Skip to content

Full screen view for Mermaid diagrams#4275

Merged
gregberge merged 5 commits into
mainfrom
greg/rnd-11082-enlargefullscreen-view-for-mermaid-diagrams
May 28, 2026
Merged

Full screen view for Mermaid diagrams#4275
gregberge merged 5 commits into
mainfrom
greg/rnd-11082-enlargefullscreen-view-for-mermaid-diagrams

Conversation

@gregberge
Copy link
Copy Markdown
Contributor

@gregberge gregberge commented May 27, 2026

Overview

Mermaid diagrams can be hard to read inline when they're large. This adds a fullscreen view: a control in the diagram's bottom-right toolbar opens the diagram in a centered dialog where it can be panned and zoomed comfortably.

CleanShot.2026-05-27.at.18.54.21.mp4

What's new

  • Fullscreen toggle in the Mermaid controls toolbar (expand / compress).
  • Opens the diagram in a centered dialog (not edge-to-edge), so the dimmed/blurred page stays visible around it.
  • Closes on: clicking outside, pressing Escape, or the reduce control — with enter/exit animations.
  • The toolbar itself was reorganized into a single harmonious cluster (fullscreen · pan · zoom) and made a bit more compact.

How it works

  • The live diagram is reparented, not re-rendered. When entering fullscreen, the existing diagram DOM node is moved into the dialog and moved back on close. This preserves the rendered SVG and the panzoom instance (no re-render, no flicker, no second Mermaid pass).
  • No layout jump. While the diagram is detached, the inline slot reserves its measured height, so content below doesn't shift.
  • Dialog is portaled to document.body so it escapes any transformed/clipping ancestor and reliably covers the viewport.
  • react-aria provides FocusScope (focus containment + restore) and usePreventScroll (robust scroll lock, incl. scrollbar width / iOS).

Tooltip primitive change (separate commit)

The control tooltips exposed a pre-existing issue: Radix renders tooltip content in a portaled [data-radix-popper-content-wrapper] outside the diagram, and—being pointer-interactive—it stole the hover that reveals the controls, causing a flicker loop.

Tooltip now makes its content non-interactive whenever disableHoverableContent is set (marks it with data-non-interactive + a scoped global rule sets pointer-events: none on that wrapper). This is a generic primitive improvement, reusable by any tooltip, not a Mermaid-specific hack.

Testing

  • Open a page with a Mermaid diagram, enter/exit fullscreen via the control, Escape, and click-outside.
  • Pan/zoom works in both inline and fullscreen views.
  • No page jump when toggling; scroll is locked behind the dialog.
  • Control tooltips show correctly and no longer flicker the toolbar on hover.
  • Light/dark themes.

gregberge and others added 2 commits May 27, 2026 11:09
The portaled popper wrapper would otherwise sit over the trigger and steal
pointer events (e.g. hover-revealed controls). A scoped global rule makes
that wrapper pointer-transparent for these tooltips only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Enlarge a Mermaid diagram into a centered dialog from a control in the
bottom-right toolbar. Closes on click outside, Escape, or the reduce control,
with enter/exit animations. The live diagram is reparented (not re-rendered)
so panzoom and the SVG are preserved, and the inline slot reserves its height
to avoid a layout jump. Uses react-aria FocusScope and usePreventScroll.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 27, 2026 09:10
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 27, 2026

RND-11082

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

🦋 Changeset detected

Latest commit: 19f2b55

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a fullscreen dialog experience for Mermaid diagrams (with pan/zoom controls) and updates the Tooltip primitive to support truly non-interactive tooltip content so tooltips don’t steal pointer events from hover-revealed controls.

Changes:

  • Add a fullscreen toggle to Mermaid diagram controls and render the fullscreen UI in a centered, scroll-locking dialog portaled to document.body.
  • Preserve the Mermaid SVG and panzoom instance when entering/exiting fullscreen (intended to avoid re-render/flicker).
  • Make Tooltip content non-interactive when disableHoverableContent is set, including a global CSS rule to prevent Radix’s portaled wrapper from intercepting pointer events.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/gitbook/src/components/RootLayout/globals.css Adds a global selector to disable pointer events on Radix tooltip wrappers that contain non-interactive tooltip content.
packages/gitbook/src/components/primitives/Tooltip.tsx Adds a data-non-interactive marker + inline styles when disableHoverableContent is set.
packages/gitbook/src/components/primitives/Button.tsx Passes tooltip contentProps through without cloning/spreading.
packages/gitbook/src/components/DocumentView/CodeBlock/MermaidPanZoomControls.tsx Reworks the controls into a compact toolbar and adds fullscreen toggle support.
packages/gitbook/src/components/DocumentView/CodeBlock/MermaidCodeBlock.tsx Implements fullscreen dialog rendering, scroll lock, Escape/click-outside close, and diagram “reparenting” behavior.
packages/gitbook/package.json Adds react-aria for FocusScope and usePreventScroll.
bun.lock Updates lockfile entries (incl. turbo bump and react-aria).
.changeset/tooltip-non-interactive.md Adds changeset for the Tooltip non-interactive behavior change.
.changeset/mermaid-fullscreen.md Adds changeset for the Mermaid fullscreen feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/gitbook/src/components/primitives/Tooltip.tsx Outdated
Comment thread packages/gitbook/src/components/DocumentView/CodeBlock/MermaidCodeBlock.tsx Outdated
@argos-ci
Copy link
Copy Markdown

argos-ci Bot commented May 27, 2026

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2-cloudflare (Inspect) 👍 Changes approved 15 changed May 27, 2026, 5:04 PM
customers-v2-vercel (Inspect) ⚠️ Changes detected (Review) 13 changed May 27, 2026, 7:16 PM
v2-cloudflare (Inspect) 👍 Changes approved 4 changed May 27, 2026, 5:09 PM
v2-vercel (Inspect) 👍 Changes approved 4 changed May 27, 2026, 5:06 PM

gregberge and others added 2 commits May 27, 2026 18:45
Addresses review: spreading caller `style` after `pointerEvents: none` let a
caller set it back to `auto`. Spread caller style first, force the
non-interactive properties last.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses review: instead of manually appendChild-ing a React-managed node
between the inline slot and the dialog, the diagram subtree is now portaled
into a stable, React-uncontrolled host node. Only that plain node is moved
between hosts, so React keeps full control of the subtree and the portal
target never changes (panzoom and the SVG are preserved, no remount).

Also softens the controls toolbar (drop border/shadow, lighter translucent
background) so it reads as part of the diagram rather than a floating card.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@taranvohra taranvohra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we add it for GBX ?

@gregberge
Copy link
Copy Markdown
Contributor Author

Did we add it for GBX ?

No we don't care in GBX.

@gregberge gregberge merged commit b9bb535 into main May 28, 2026
33 of 35 checks passed
@gregberge gregberge deleted the greg/rnd-11082-enlargefullscreen-view-for-mermaid-diagrams branch May 28, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants