Skip to content

Diagrams: a viewer opened from a modal is usable (written into the modal's popup) - #145

Merged
bmjcoding merged 1 commit into
mainfrom
claude/viewer-in-dialog
Nov 25, 2026
Merged

bmjcoding merged 1 commit into
mainfrom
claude/viewer-in-dialog

Conversation

@bmjcoding

Copy link
Copy Markdown
Owner

Fixes a bug CIMIP's lead found while adopting 1890615e: a diagram viewer opened from inside a modal Basalt Dialog was inert. Close, zoom, Fit, View as list and the app's actions were all dead, and only Escape closed it.

The cause: useModalOutside's guard (modal-outside.ts). While a modal is open, it makes every control added outside the modal's popup inert. The viewer is a native <dialog>, and it was portaled onto the body after the modal had opened, so it landed outside the popup.

The fix:

  • Where the viewer goes: layers.ts gets a ModalHost context, the nearest Basalt modal's popup. Dialog, AlertDialog, Sheet and CommandMenu provide it, and the figure passes it to the viewer, which is portaled into that popup. A showModal dialog still draws in the top layer.
  • Escape stops at the viewer, so it no longer closes the parent too.
  • Parent closing: the viewer closes when the parent starts closing (data-closed), so it never holds the parent's trigger inert.
  • Outside a modal: placement and keys are unchanged.

Review: engineering, a bug fix restoring documented behaviour, so no panel; no pixel changes. The builder checked this: all 341 elements of the viewer have the same boxes and computed styles in a form Dialog as on the page, in both themes.

Checks:

  • Passed: lint, both typechecks, the build and the size table.
  • Tests were not run (paused, DECISIONS 359). diagram-viewer-in-dialog.test.mjs is written, not run.
  • One hand run in Chromium, through scripts/chromium-launch.mjs, from a Dialog, a Sheet and an AlertDialog. Everything worked:
    • the controls;
    • Escape;
    • a press on the scrim;
    • Tab staying inside the viewer;
    • taps at 390;
    • the scroll lock;
    • the parent closing while the viewer was open.

Sizes: 14 exports grow 58 to 61 bytes (+0.1%). The package grows 197 bytes minified, 16 gzipped.

The skill's viewer: it doesn't have this bug, because it uses native modals only and nothing makes the outside inert. That was found by reading the code; it wasn't run.

🤖 Generated with Claude Code

…l's popup

CIMIP's document reader is a form DialogContent; "Expand" there opened the viewer, a native <dialog> (showModal) portalled to the end of the body,
and every control in it was dead (Close, the zoom, Fit, View as list, the app's actions; Playwright saw .basalt-diagram-viewer-end take the clicks).

The cause: the open modal's guard (modal-outside.ts, guardOutside) watches the body for anything added outside its popup and makes every control in
it inert, and the viewer arrived as a new child of the body. Inert buttons are not hit-tested, so a press landed on the row around them; only Esc
worked, because the browser's cancel goes to the <dialog> itself, which is not a control. Base UI's own marks are applied once at open and did not
reach it.

The fix: a context (layers.ts, ModalHost), set by Dialog, AlertDialog, Sheet and CommandMenu to their popup and read by the figure, which hands it
to the viewer; the viewer is written into that popup, and on the page into the body as before. Inside the popup it is inside the modal for the
guard, for Base UI's outside press and for its focus trap; a showModal dialog draws in the top layer wherever it sits. In a modal, Esc stops at the
viewer (the modal's dismissal listens on its popup and the document), so it closes the viewer alone, and the viewer closes as its modal starts to
close (data-closed), so the two leave together and the modal can return focus to its trigger. On the page nothing changes.

Engineering, a bug fix restoring documented behaviour: no panel. test/diagram-viewer-in-dialog.test.mjs is written and not run (DECISIONS 359).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bmjcoding
bmjcoding merged commit 43c486e into main Nov 25, 2026
1 of 2 checks passed
@bmjcoding
bmjcoding deleted the claude/viewer-in-dialog branch November 25, 2026 01:24
bmjcoding added a commit that referenced this pull request Nov 25, 2026
…e regenerated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant