From de0aa1099d7fb80d1397ab15db105a20e11cc73b Mon Sep 17 00:00:00 2001 From: bailey <74082460+bmjcoding@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:07:56 -0600 Subject: [PATCH] A diagram viewer opened from a modal is usable: written into the modal's popup CIMIP's document reader is a form DialogContent; "Expand" there opened the viewer, a native (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 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 --- packages/react/src/command.tsx | 4 +- packages/react/src/diagram-figure.tsx | 6 +- packages/react/src/diagram-viewer.tsx | 25 +- packages/react/src/dialog.tsx | 4 +- packages/react/src/layers.ts | 6 + packages/react/src/overlays.tsx | 6 +- .../test/diagram-viewer-in-dialog.test.mjs | 252 ++++++++++++++++++ packages/react/test/export-sizes.json | 32 +-- 8 files changed, 309 insertions(+), 26 deletions(-) create mode 100644 packages/react/test/diagram-viewer-in-dialog.test.mjs diff --git a/packages/react/src/command.tsx b/packages/react/src/command.tsx index bf75c696..e78cb2a4 100644 --- a/packages/react/src/command.tsx +++ b/packages/react/src/command.tsx @@ -5,7 +5,7 @@ import { SearchGlyph } from "./glyphs/search"; import { Button } from "./button"; import { CommandHints, CommandRowContent, commandRowShape, commandValue } from "./command-row"; import { Icon } from "./icon"; -import { BAND_LEVEL, inLevel, MODAL_LEVEL, ModalDepth, useModalLayer, usePanelLevel } from "./layers"; +import { BAND_LEVEL, inLevel, MODAL_LEVEL, ModalDepth, ModalHost, useModalLayer, usePanelLevel } from "./layers"; import { useModalOutside } from "./modal-outside"; import { isModKey } from "./platform"; import { Spinner } from "./spinner"; @@ -155,6 +155,7 @@ export function CommandMenuShell({ open, onOpenChange, groups, placeholder = "Se const Panel = state.status === "ready" ? state.Panel : null; return ( + @@ -203,6 +204,7 @@ export function CommandMenuShell({ open, onOpenChange, groups, placeholder = "Se + ); } diff --git a/packages/react/src/diagram-figure.tsx b/packages/react/src/diagram-figure.tsx index dcfc28cb..134b8bab 100644 --- a/packages/react/src/diagram-figure.tsx +++ b/packages/react/src/diagram-figure.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import { Kbd } from "./kbd"; import { useShortcutsVisible } from "./keyboard"; -import { inLevel, usePanelLevel } from "./layers"; +import { inLevel, ModalHost, usePanelLevel } from "./layers"; import { applyTrace, buildModel, placeLabels, tapTrace, transcript, entranceDrawn, figureKey, figureList, figureTree, hasStops, hintEntries, keyTarget, measureFigure, settleEntrance, syncAttributes, toHtml, } from "./diagram-core"; @@ -507,6 +507,8 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, onLayout, void fetchViewer().then((mod) => { setOpening(false); if (mod) setViewerOpen(true); }); }; const closeViewer = React.useCallback(() => setViewerOpen(false), []); + // The nearest Basalt modal's popup, when the figure is in one: the viewer is written into it (layers.ts, ModalHost). + const modalHost = React.useContext(ModalHost); // An app's own actions: their module loads once script runs, only for a figure that has some; until it arrives, and if it cannot, none is drawn. const hasActions = !viewer && Boolean(actions?.length); const [actionsModule, setActionsModule] = React.useState(null); @@ -639,7 +641,7 @@ export function DiagramFigure({ spec, component, viewer, zoom = true, onLayout, {opening ? : null} {viewerOpen && viewerModule ? ( - + ) : null} ) : null; diff --git a/packages/react/src/diagram-viewer.tsx b/packages/react/src/diagram-viewer.tsx index 3e7c8bb3..0ab7f018 100644 --- a/packages/react/src/diagram-viewer.tsx +++ b/packages/react/src/diagram-viewer.tsx @@ -50,6 +50,11 @@ export interface DiagramViewerProps { summary: React.ReactNode; /** "Expand": focus returns to it when the viewer closes. */ opener: React.RefObject; + /** + * The popup of the Basalt modal the figure sits in (layers.ts, ModalHost), or none on the page. Opened from a modal, the viewer is written into its popup: + * at the end of the body it would be outside the modal, where everything is inert, and every control in it dead. + */ + host?: React.RefObject | null; onClose: () => void; } @@ -58,7 +63,7 @@ const EMPTY: ZoomState = { zoom: 1, level: 100, fit: 1, min: 1, max: 4, atMin: f /** A length token's value in CSS pixels, read from a probe the stage holds. */ const probeWidth = (stage: HTMLElement | null, which: string) => stage?.querySelector(`.${P}-probe[data-probe="${which}"]`)?.offsetWidth ?? 0; -export function DiagramViewer({ kit, actions, Actions, spec, component, source, summary, opener, onClose }: DiagramViewerProps) { +export function DiagramViewer({ kit, actions, Actions, spec, component, source, summary, opener, host, onClose }: DiagramViewerProps) { const { Figure: DiagramFigure, Kbd, buildModel, figureKey, figureList, hintEntries, toHtml, inLevel, measureFigure } = kit; // The viewer's figure is still (9.7): no entrance, flow, mover or run, so no motion code is loaded for it. const still = React.useMemo(() => ({ ...spec, motion: "still" }), [spec]); @@ -157,6 +162,8 @@ export function DiagramViewer({ kit, actions, Actions, spec, component, source, const closing = React.useRef(false); const onCloseRef = React.useRef(onClose); onCloseRef.current = onClose; + // Where the dialog is written: the modal's popup, read once as the viewer opens (the modal is open, so it is there), else the body. + const [into] = React.useState(() => host?.current ?? null); const close = React.useCallback(() => { const d = dialogRef.current; if (!d || closing.current) return; @@ -200,11 +207,17 @@ export function DiagramViewer({ kit, actions, Actions, spec, component, source, d.addEventListener("click", onClick); d.addEventListener("click", onLink); d.addEventListener("keydown", onKey); - return () => { clearTimeout(timer); d.removeEventListener("transitionend", onEntered); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("click", onLink); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; - }, [opener, close]); + // In a modal, the viewer closes as the modal starts to close (Base UI marks its popup `data-closed`), so the two leave together, and the native modal + // is gone before the modal returns focus to its trigger (which the viewer would hold inert). Unmounted with it, the cleanup below closes it too. + const parent = into ? new MutationObserver(() => { if (into.hasAttribute("data-closed")) close(); }) : null; + if (into) parent?.observe(into, { attributes: true, attributeFilter: ["data-closed"] }); + return () => { parent?.disconnect(); clearTimeout(timer); d.removeEventListener("transitionend", onEntered); d.removeEventListener("close", onClose); d.removeEventListener("pointerdown", onDown); d.removeEventListener("click", onClick); d.removeEventListener("click", onLink); d.removeEventListener("keydown", onKey); if (d.open) d.close(); }; + }, [opener, close, into]); return createPortal( - + // In a modal, Esc closes the viewer alone (the browser's cancel): the key goes no further, so the modal's own dismissal, a React handler on its popup and + // a listener on the document, never sees it. On the page it travels as it always has. + {inLevel(1, <>
@@ -266,7 +279,9 @@ export function DiagramViewer({ kit, actions, Actions, spec, component, source, )}
, - document.body, + into ?? document.body, ); } +const stopEscape = (event: React.KeyboardEvent) => { if (event.key === "Escape") event.stopPropagation(); }; + diff --git a/packages/react/src/dialog.tsx b/packages/react/src/dialog.tsx index 4e60c597..208afe65 100644 --- a/packages/react/src/dialog.tsx +++ b/packages/react/src/dialog.tsx @@ -1,7 +1,7 @@ import { Dialog as BaseDialog } from "@base-ui/react/dialog"; import * as React from "react"; -import { inLevel, MODAL_LEVEL, ModalDepth, useModalLayer } from "./layers"; +import { inLevel, MODAL_LEVEL, ModalDepth, ModalHost, useModalLayer } from "./layers"; import { useModalOutside } from "./modal-outside"; import type { FocusTarget, OpenChangeDetails, PartProps, PopupActions } from "./types"; import { withClass, withStyle } from "./utils"; @@ -182,10 +182,12 @@ export function DialogContent({ className, style, children, ref, size = "default const first: FocusTarget | undefined = initialFocus ?? (form ? (type: string) => ((state?.opened ?? type) === "touch" ? title() : popup.current?.querySelector(FIRST_FIELD) ?? true) : size === "wide" ? title : undefined); return ( + {inLevel(MODAL_LEVEL, children)} + ); } diff --git a/packages/react/src/layers.ts b/packages/react/src/layers.ts index f82d7aaf..12a6c98f 100644 --- a/packages/react/src/layers.ts +++ b/packages/react/src/layers.ts @@ -6,6 +6,12 @@ import { useScreenKeyboardLayout } from "./screen-keyboard"; // floating children; a nested modal then covers the entire preceding level. export const ModalDepth = /* @__PURE__ */ React.createContext(0); +// The popup of the nearest Basalt modal (Dialog, AlertDialog, Sheet, CommandMenu), or null on the page. While a modal is open, what is outside its popup is +// inert (Base UI's marks, and useModalOutside's guard over anything added to the page later), so a native modal opened from inside one (the diagram viewer) +// is written into this popup rather than at the end of the body: inside, it stays operable, a press in it is not a press outside, and the focus trap holds it. +// A `showModal` dialog draws in the top layer wherever it sits. Context crosses portals, as the depth does. +export const ModalHost = /* @__PURE__ */ React.createContext | null>(null); + export function useModalLayer() { const parent = React.useContext(ModalDepth); // A modal is fixed to the window: while an on-screen keyboard is up it is laid out on what is still seen. diff --git a/packages/react/src/overlays.tsx b/packages/react/src/overlays.tsx index 3217bbb2..d2b6e7b0 100644 --- a/packages/react/src/overlays.tsx +++ b/packages/react/src/overlays.tsx @@ -6,7 +6,7 @@ import { IconButton } from "./button"; import { CloseGlyph } from "./glyphs/close"; import { Dialog, DialogActions, DialogClose, DialogContent, DialogDescription, DialogModal, DialogTitle, DialogTrigger } from "./dialog"; import type { DialogCloseProps, DialogContentProps, DialogProps, DialogTriggerProps } from "./dialog"; -import { inLevel, MODAL_LEVEL, ModalDepth, useModalLayer } from "./layers"; +import { inLevel, MODAL_LEVEL, ModalDepth, ModalHost, useModalLayer } from "./layers"; import { useModalOutside } from "./modal-outside"; import { useScrollStop } from "./scroll-stop"; import type { PartProps } from "./types"; @@ -44,10 +44,12 @@ export function AlertDialogContent({ className, initialFocus, ref, style, childr const mergedRef = useModalOutside(keepRef); return ( + popup.current?.querySelector("[data-basalt-cancel]") ?? true)} className={withClass("basalt-dialog", className)}>{inLevel(MODAL_LEVEL, children)} + ); } @@ -91,10 +93,12 @@ export function SheetContent({ side = "right", className, style, children, ref, }, [step]); return ( + {inLevel(MODAL_LEVEL, children)} + ); } diff --git a/packages/react/test/diagram-viewer-in-dialog.test.mjs b/packages/react/test/diagram-viewer-in-dialog.test.mjs new file mode 100644 index 00000000..3c2be17d --- /dev/null +++ b/packages/react/test/diagram-viewer-in-dialog.test.mjs @@ -0,0 +1,252 @@ +// The diagram viewer opened from inside a modal (CIMIP's document reader, found adopting main 1890615e): written at the end of the body, the viewer sat outside +// the open Dialog, whose guard (modal-outside.ts) made every control added to the page later inert, so Close, the zoom, Fit, View as list and the app's +// actions were dead and only Esc closed it. Now it is written into the modal's popup (layers.ts, ModalHost). Here: every control works from a Dialog, a Sheet and +// an AlertDialog; Esc and a press on the viewer's scrim close the viewer alone; focus stays in it and goes back to Expand; the parent closing with the viewer +// open takes it away cleanly; on the page it is where it was, and in a modal it is drawn the same. In Chromium against the built package. Written while tests +// are paused (DECISIONS 359): not yet run. +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { after, before, describe, test } from "node:test"; + +import { fixturePage, launch, pkg } from "./support.mjs"; + +const P = "basalt-diagram"; +const font = (file) => fs.readFileSync(path.join(pkg, "dist", "fonts", file)).toString("base64"); +const FONTS = `@font-face{font-family:"Geist";src:url(data:font/woff2;base64,${font("Geist-Variable.woff2")}) format("woff2");font-weight:100 900}@font-face{font-family:"Geist Mono";src:url(data:font/woff2;base64,${font("GeistMono-Variable.woff2")}) format("woff2");font-weight:100 900}`; +const PAGE = `${FONTS} body{background:var(--basalt-surface-page);margin:0;padding:16px;box-sizing:border-box} #root{max-width:1104px;margin:0 auto}`; + +let browser; +before(async () => { browser = await launch(); }); +after(async () => { await browser?.close(); }); + +// The host: `window.__show(where)` draws the architecture figure, with one action, on the page or in a closed Dialog, Sheet or AlertDialog opened by `#trigger`; +// `window.__close()` closes the modal from the app. Every press of the action is logged in `window.__log`. +const HOST = ` +import data from "./test/fixtures/cimip-diagrams.json"; +const { type, ...FIG } = data.architecture; +window.__log = []; +const actions = [{ label: "Copy link", onSelect: (ctx) => { window.__log.push({ viewer: ctx.viewer }); } }]; +function Host() { + const [where, setWhere] = React.useState(null); + const [open, setOpen] = React.useState(false); + window.__show = (w) => flushSync(() => { setWhere(w); setOpen(false); }); + window.__close = () => flushSync(() => setOpen(false)); + const fig = ; + if (where === "page") return fig; + if (where === "dialog") return ( + + Open + Document{fig} + + ); + if (where === "sheet") return ( + + Open + Document{fig} + + ); + if (where === "alert") return ( + + Open + Document{fig}Cancel + + ); + return null; +} +createRoot(document.getElementById("root")).render();`; + +const frames = (page, n = 3) => page.evaluate((n) => new Promise((resolve) => { let k = 0; const step = () => (++k >= n ? resolve() : requestAnimationFrame(step)); requestAnimationFrame(step); }), n); +const settled = (page) => page.evaluate(() => Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {})))); + +async function hostPage(where, { theme = "dark", width = 1440, height = 900, touch = false } = {}) { + const { page, errors } = await fixturePage(browser, HOST, { theme, standards: true, viewport: { width, height }, hasTouch: touch, isMobile: touch }); + if (touch) await page.evaluate(() => { const meta = document.createElement("meta"); meta.name = "viewport"; meta.content = "width=device-width, initial-scale=1"; document.head.append(meta); }); + await page.addStyleTag({ content: PAGE }); + await page.evaluate(() => document.fonts.ready); + await page.evaluate((w) => window.__show(w), where); + if (where !== "page") { + if (touch) await page.locator("#trigger").tap(); else await page.locator("#trigger").click(); + await page.waitForSelector("#parent[data-open]"); + await settled(page); + } + await page.waitForSelector(`#fig .${P}-foot .${P}-action`); + await frames(page, 4); + return { page, errors }; +} + +/** Opens the viewer from the figure's Expand and waits until its figure is laid out and its entrance has ended. */ +async function openViewer(page, { tap = false } = {}) { + const expand = page.locator(`#fig .${P}-expand`); + await expand.scrollIntoViewIfNeeded(); + if (tap) await expand.tap(); else await expand.click(); + await page.waitForSelector(`dialog.${P}-viewer[open] .${P}[data-layout]`); + await settled(page); + await frames(page, 3); +} +const viewer = (page) => page.locator(`dialog.${P}-viewer`); +const level = async (page) => (await viewer(page).locator(`.${P}-level > span`).textContent()).trim(); +const parentOpen = (page) => page.evaluate(() => Boolean(document.querySelector("#parent[data-open]"))); +const focusIn = (page, selector) => page.evaluate((s) => Boolean(document.activeElement?.closest(s)), selector); + +for (const where of ["dialog", "sheet", "alert"]) { + describe(`from ${where === "alert" ? "an AlertDialog" : `a ${where === "dialog" ? "Dialog" : "Sheet"}`}`, () => { + test("the viewer is written into the modal's popup, nothing in it is inert, and Zoom in, Fit, View as list, the action and Close all work", async () => { + const { page, errors } = await hostPage(where); + await openViewer(page); + const placed = await page.evaluate((P) => { + const d = document.querySelector(`dialog.${P}-viewer`); + return { inParent: Boolean(d.closest("#parent")), inert: d.querySelectorAll("[inert]").length + (d.closest("[inert]") ? 1 : 0) }; + }, P); + assert.deepEqual(placed, { inParent: true, inert: 0 }); + assert.equal(await focusIn(page, `dialog.${P}-viewer`), true, "focus opens in the viewer"); + + const before = await level(page); + await viewer(page).getByRole("button", { name: "Zoom in" }).click(); + assert.notEqual(await level(page), before, "a zoom step lands"); + await viewer(page).getByRole("button", { name: "Fit" }).click(); + assert.equal(await viewer(page).getByRole("button", { name: "Fit" }).getAttribute("aria-disabled"), "true", "Fit lands at Fit"); + await viewer(page).getByRole("button", { name: "View as list" }).click(); + await viewer(page).getByRole("button", { name: "Hide the list" }).click(); + await viewer(page).getByRole("button", { name: "Copy link" }).click(); + assert.deepEqual(await page.evaluate(() => window.__log), [{ viewer: true }]); + assert.equal(await parentOpen(page), true, "no press in the viewer closes the modal"); + + await viewer(page).getByRole("button", { name: "Close", exact: true }).click(); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.equal(await parentOpen(page), true, "Close leaves the modal open"); + assert.equal(await page.evaluate((P) => document.activeElement?.matches(`#fig .${P}-expand`), P), true, "focus is back on Expand"); + assert.deepEqual(errors, []); + await page.close(); + }); + }); +} + +describe("dismissal and focus, from a Dialog", () => { + test("Esc closes the viewer alone and returns focus to Expand; a second Esc closes the Dialog", async () => { + const { page, errors } = await hostPage("dialog"); + await openViewer(page); + await page.keyboard.press("Escape"); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.equal(await parentOpen(page), true, "the Dialog is still open"); + assert.equal(await page.evaluate((P) => document.activeElement?.matches(`#fig .${P}-expand`), P), true); + // The Dialog works after the viewer: its own Esc still closes it. + await page.keyboard.press("Escape"); + await page.waitForSelector("#parent", { state: "detached" }); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("a press on the viewer's scrim closes the viewer and leaves the Dialog open", async () => { + const { page, errors } = await hostPage("dialog", { width: 1440, height: 900 }); + await openViewer(page); + // From 720 the viewer is the window less space-4 on every side: the top-left corner, 4px in, is its scrim. + await page.mouse.click(4, 4); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.equal(await parentOpen(page), true); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("Tab and Shift+Tab cycle inside the viewer and never reach the Dialog behind it", async () => { + const { page, errors } = await hostPage("dialog"); + await openViewer(page); + const count = await viewer(page).evaluate((d) => d.querySelectorAll('a[href],button:not([disabled]),[tabindex]:not([tabindex="-1"])').length); + for (let i = 0; i < count + 2; i += 1) { + await page.keyboard.press("Tab"); + assert.equal(await focusIn(page, `dialog.${P}-viewer`), true, `Tab ${i + 1} stays in the viewer`); + } + for (let i = 0; i < count + 2; i += 1) { + await page.keyboard.press("Shift+Tab"); + assert.equal(await focusIn(page, `dialog.${P}-viewer`), true, `Shift+Tab ${i + 1} stays in the viewer`); + } + assert.equal(await parentOpen(page), true); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("at 390 on touch a tap on Zoom in and on Close works", async () => { + const { page, errors } = await hostPage("dialog", { width: 390, height: 844, touch: true }); + await openViewer(page, { tap: true }); + const before = await level(page); + await viewer(page).getByRole("button", { name: "Zoom in" }).tap(); + assert.notEqual(await level(page), before); + await viewer(page).getByRole("button", { name: "Close", exact: true }).tap(); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.equal(await parentOpen(page), true); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("the scroll lock: while the viewer is open the page does not scroll; after it closes the Dialog's lock holds; after the Dialog closes the page scrolls", async () => { + const { page, errors } = await hostPage("dialog"); + const overflow = () => page.evaluate(() => getComputedStyle(document.documentElement).overflow); + const lockedWithDialog = await overflow(); + await openViewer(page); + assert.equal(await overflow(), "hidden"); + await viewer(page).getByRole("button", { name: "Close", exact: true }).click(); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.equal(await overflow(), lockedWithDialog, "the Dialog's own lock is as it was"); + await page.keyboard.press("Escape"); + await page.waitForSelector("#parent", { state: "detached" }); + await frames(page, 2); + assert.notEqual(await overflow(), "hidden"); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("the Dialog closing with the viewer open takes the viewer with it: no open dialog is left, the page is not inert, and focus is back on the trigger", async () => { + const { page, errors } = await hostPage("dialog"); + await openViewer(page); + await page.evaluate(() => window.__close()); + await page.waitForSelector("#parent", { state: "detached" }); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + await frames(page, 2); + const after = await page.evaluate(() => ({ + open: document.querySelectorAll("dialog[open]").length, + inert: document.querySelectorAll("[inert]").length, + focus: document.activeElement?.id ?? null, + })); + assert.deepEqual(after, { open: 0, inert: 0, focus: "trigger" }); + await page.locator("#trigger").click(); + await page.waitForSelector("#parent[data-open]"); + assert.deepEqual(errors, []); + await page.close(); + }); +}); + +describe("on the page and in a modal", () => { + test("on the page the viewer is the body's own child, as before", async () => { + const { page, errors } = await hostPage("page"); + await openViewer(page); + assert.equal(await viewer(page).evaluate((d) => d.parentElement === document.body), true); + await page.keyboard.press("Escape"); + await page.waitForSelector(`dialog.${P}-viewer`, { state: "detached" }); + assert.deepEqual(errors, []); + await page.close(); + }); + + test("the viewer is drawn the same in a Dialog as on the page: every element's box and computed style, in both themes", async () => { + const read = (page) => viewer(page).evaluate((d) => { + const PROPS = ["color", "background-color", "font-family", "font-size", "font-weight", "line-height", "letter-spacing", "text-align", "white-space", "border-top-color", "border-top-width", "border-radius", "box-shadow", "opacity", "padding-left", "padding-top", "gap", "visibility", "pointer-events", "cursor"]; + return [d, ...d.querySelectorAll("*")].map((el) => { + const cs = getComputedStyle(el), r = el.getBoundingClientRect(); + return [el.tagName, el.className?.baseVal ?? el.className, Math.round(r.x), Math.round(r.y), Math.round(r.width), Math.round(r.height), ...PROPS.map((p) => cs.getPropertyValue(p))].join("|"); + }); + }); + for (const theme of ["dark", "light"]) { + const onPage = await hostPage("page", { theme }); + await openViewer(onPage.page); + const a = await read(onPage.page); + await onPage.page.close(); + const inDialog = await hostPage("dialog", { theme }); + await openViewer(inDialog.page); + const b = await read(inDialog.page); + await inDialog.page.close(); + assert.equal(b.length, a.length); + const differ = a.flatMap((line, i) => (line === b[i] ? [] : [`${line}\n${b[i]}`])); + assert.deepEqual(differ, [], `${theme}: the viewer in a Dialog differs from the viewer on the page`); + assert.deepEqual([...onPage.errors, ...inDialog.errors], []); + } + }); +}); diff --git a/packages/react/test/export-sizes.json b/packages/react/test/export-sizes.json index 53fe32f1..7c9a47da 100644 --- a/packages/react/test/export-sizes.json +++ b/packages/react/test/export-sizes.json @@ -10,7 +10,7 @@ "AlertDialogAction": 69695, "AlertDialogActions": 208, "AlertDialogCancel": 69719, - "AlertDialogContent": 75000, + "AlertDialogContent": 75061, "AlertDialogDescription": 69849, "AlertDialogTitle": 69862, "AlertDialogTrigger": 69874, @@ -18,7 +18,7 @@ "AppHeader": 1285, "AppShell": 104323, "AppTile": 1112, - "ArchitectureDiagram": 104733, + "ArchitectureDiagram": 104791, "ArrowDownGlyph": 2868, "ArrowLeftGlyph": 2869, "ArrowRightGlyph": 2859, @@ -64,13 +64,13 @@ "Combobox": 164926, "CommandBlock": 4923, "CommandList": 34036, - "CommandMenu": 88496, + "CommandMenu": 88557, "Composer": 53074, "CopyButton": 19373, "CopyGlyph": 2884, "Countdown": 3016, "CoverageStrip": 1570, - "DataFlowDiagram": 104680, + "DataFlowDiagram": 104738, "DateAge": 2527, "DescriptionColumns": 216, "DescriptionItem": 593, @@ -78,7 +78,7 @@ "Dialog": 70793, "DialogActions": 208, "DialogClose": 69662, - "DialogContent": 77247, + "DialogContent": 77308, "DialogDescription": 69849, "DialogTitle": 69862, "DialogTrigger": 69841, @@ -105,7 +105,7 @@ "Fieldset": 6390, "FilterResult": 698, "FilterToolbar": 774, - "FlowchartDiagram": 104701, + "FlowchartDiagram": 104759, "Form": 8730, "FormGrid": 438, "FormGridItem": 628, @@ -232,8 +232,8 @@ "STAGE_WORDS": 149, "STATUS_MESSAGE_MS": 26, "SandboxesGlyph": 2963, - "SchemaDiagram": 104649, - "SearchDialog": 89508, + "SchemaDiagram": 104707, + "SearchDialog": 89569, "SearchField": 18500, "SearchGlyph": 3183, "SearchMatch": 248, @@ -251,14 +251,14 @@ "SelectableList": 821, "SelectionBar": 25913, "Separator": 4531, - "SequenceDiagram": 104677, + "SequenceDiagram": 104735, "SettingsGlyph": 3100, "ShareBar": 1411, "Sheet": 70793, "SheetActions": 208, "SheetBody": 1841, "SheetClose": 69662, - "SheetContent": 75289, + "SheetContent": 75350, "SheetDescription": 69849, "SheetFooter": 234, "SheetHeader": 79528, @@ -268,9 +268,9 @@ "SingleKeysSwitch": 17082, "SiteBrand": 1302, "SiteFooter": 15010, - "SiteHeader": 181139, + "SiteHeader": 181200, "SiteLockupDefs": 694, - "SiteMenu": 173461, + "SiteMenu": 173522, "SiteNav": 5102, "SiteNavLink": 411, "SiteNavList": 5112, @@ -316,7 +316,7 @@ "Tab": 40001, "TabBar": 3501, "TabBarItem": 1859, - "TabBarMore": 92391, + "TabBarMore": 92452, "Table": 8279, "TableBody": 143, "TableCall": 391, @@ -353,7 +353,7 @@ "TooltipProvider": 97618, "TrashGlyph": 2906, "TravelSpinner": 2100, - "Tray": 91515, + "Tray": 91576, "TrayRow": 502, "TrendsGlyph": 2924, "VersionLink": 1973, @@ -433,8 +433,8 @@ } }, "package": { - "bytes": 953467, - "gzip": 318283 + "bytes": 953664, + "gzip": 318299 }, "styles": { "bytes": 470812,