Repository navigation
Modals: corner close button and full-screen EEG viewer - #206
Conversation
Adds DialogCloseButton.astro, a small reusable component rendering an
X in the top-right corner with aria-label="Close", keyboard focus, and
a visible focus ring. Used by ActionBar's three dialogs and the
ProvenanceToggle popover, alongside the existing bottom Close button
(kept) and Esc (unchanged, native <dialog> behavior).
Restructures ActionBar's dialogs so the close button stays pinned
while content scrolls: the outer dialog no longer scrolls itself, an
inner .compute-dialog__scroll/.cite-dialog__scroll wrapper does.
Fixes a bug caught in manual testing where `display: flex` on the
bare dialog class selector outranked the browser's default
`dialog { display: none }` and left closed dialogs visible; gated
behind [open] instead.
ConfirmDialog intentionally does not get the X: its Cancel button is
already the same dismiss action a corner X would be (both just close
without confirming), so adding one would be redundant on a small,
single-purpose confirm box rather than fixing a real gap.
Moves the Zarr signal viewer from an inline slot cramped into a BIDS tree row into EegViewerDialog.astro, a page-level dialog sized to ~70% of the viewport (clamped for small/huge screens) using the same close-button treatment as the other dialogs, minus a redundant bottom Close button since the viewer already fills the available height. mountEegViewer() now returns a teardown handle instead of Promise<void>, and tears down any previous instance in the slot at the very start of the function (previously only on the happy path, which could strand a prior instance's ResizeObserver/MutationObserver/WebGL context if a re-open failed early). The page script tracks the handle plus a monotonic sequence number so a superseded mount (reopen with a different file, or a close mid-fetch) tears itself down instead of writing stale content into the shared slot; closing the dialog clears the slot and invalidates any mount still in flight. The code-split dynamic import is unchanged — the viewer + zarrita bundle still loads only when a signal file is first opened. Every existing failure path (zarrAvailable=false with its recorded reason, the mount-failure catch, the aria-busy/data-loaded state markers) is preserved, just relocated from the per-row click handler into openEegViewerModal(). render-dir-listing.ts: the eeg preview button no longer renders a per-row preview slot (it mounts into the modal's shared slot instead) and uses aria-haspopup="dialog" rather than aria-expanded, since it opens a dialog rather than toggling adjacent content.
Deploying nemar-website with
|
| Latest commit: |
16991f0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://cda14a8c.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-issue-199-modal-clos.nemar-website.pages.dev |
|
Both must-fix findings addressed, plus the Esc gap. Pushed as 1. Stale mount clobbering a live viewerConfirmed the root cause reading the code: Implemented the suggested predicate. Updated the misleading comment to say what is actually guaranteed now. 2. WebGL context leak
3. ProvenanceToggle EscapeAgreed it's pre-existing rather than a regression, and agreed it should be fixed here rather than deferred: the PR gives that popover a close button that makes it read as a dialog, so it should behave like one. Added a Not changed
Worth flagging: fix 1 is a genuine race, and I have not re-run your delayed-fetch reproduction against it. The logic is straightforward and the guard sits before every slot write, but if you still have that harness set up, re-running it would be the real confirmation. |
Closes #199.
What changed
Part 1 — shared corner close button
Added
src/components/DialogCloseButton.astro, a small reusable component (X icon +aria-label="Close"+ a delegated document-level click handler that callsdialog.close()on the nearest ancestor<dialog>, or sets.open = falseon the nearest ancestor<details>). Used it in:ActionBar.astro's three dialogs ([data-download-dialog],[data-compute-dialog],[data-citations-dialog])ProvenanceToggle.astro'srole="dialog"popoverThe X is an addition next to the existing bottom Close button (kept — it still reads as the natural end-of-content action) and Esc (unchanged, native
<dialog>behavior; the shared component's script only listens for clicks). Keyboard reachable, visible:focus-visiblering usingvar(--color-focus)/var(--shadow-focus), theme-aware via tokens only.Restructured the three ActionBar dialogs so the corner X stays pinned while long content scrolls underneath it: the outer
<dialog>no longer scrolls itself (padding: 0; overflow: hidden), a new inner.compute-dialog__scroll/.cite-dialog__scrollwrapper does. Without this, the X would have the same "goes out of view on a long dialog" problem the issue opened with, just moved from the bottom to the top.Part 2 — EEG viewer in a full-screen modal
Added
src/components/EegViewerDialog.astro, a page-level dialog sized tomin(70vw, 1400px)wide bymin(70vh, 900px)tall (clamped for small/huge screens,block-size: fit-contentso short states like the "unavailable" fallback don't leave a mostly-empty box). Same close-button/scroll-wrapper treatment as part 1, minus the bottom Close button — the viewer's own toolbar already fills the available height, so a redundant button below it would sit below the fold, the exact problem the corner X exists to fix.src/pages/dataset/[id].astro's click handler now branches "eeg" preview buttons into a newopenEegViewerModal()instead of the old inline per-row-slot toggle. The dynamic import (await import("../../lib/eeg-viewer/viewer")) still only fires on first open of a signal file — code-split behavior unchanged. Every existing failure path is preserved:zarrAvailable === "false"with its recordedzarrFailureReason+ download fallback, the mount-failure catch + download fallback, and thearia-busy/data-loaded(undefined/"loading"/"true") state markers.src/lib/eeg-viewer/viewer.ts:mountEegViewer()now returnsPromise<(() => void) | undefined>(a teardown handle) instead ofPromise<void>, and tears down any previous instance mounted into the slot at the very top of the function rather than only on the happy path — previously a re-open that failed early (store won't open, no channel groups, no 2D context) could strand the prior instance'sResizeObserver/MutationObserver/WebGL context under the DOM being overwritten.render-dir-listing.ts: the eeg preview button no longer renders a per-rowdata-preview-slot(it mounts into the modal's one shared slot instead) and usesaria-haspopup="dialog"rather thanaria-expanded, since it opens a dialog rather than toggling adjacent content.Design decisions
Shared component vs. per-file duplication. AGENTS.md's scoped-style rule says siblings that each render their own row markup should duplicate layout CSS rather than reach for a shared stylesheet (
BidsTree.astro/BidsDirChildren.astro). That rule is about siblings independently rendering similar-looking markup; it isn't a blanket ban on small reusable leaf components.DialogCloseButton.astrois exactly the normal Astro pattern for that case — one component owns both its markup and its own scoped style/script, and gets imported wherever needed. Using it three times on one page only registers one delegated click listener (Astro dedupes identical inline scripts by content), so there's no per-instance wiring cost either.ConfirmDialog: no X. Judged this deliberately rather than applying the X uniformly.
ConfirmDialog.astroalready has a Cancel button that is behaviorally identical to what a corner X would do here — both just calldialog.close()without confirming (ConfirmDialog'sclosehandler only proceeds whenreturnValue === "confirm", so neither X nor Cancel could be confused for the destructive action). Since there's no actual ambiguity hazard, but the dialog is small, single-purpose, and already has an explicit dismiss control front and center, adding a second one that does the same thing is clutter, not a fix. Left it out.EEG viewer sizing.
~70% of the viewportis a cap (max-inline-size/max-block-size), not a fixed size, so short states (the "unavailable" fallback) shrink to content instead of leaving a big empty box — caught this exact issue while testing and fixed it withblock-size: fit-content.Concurrency guard changed shape, not intent. The old per-row
data-loadedgate only had to protect against re-clicking the same row mid-fetch (each file had its own isolated slot). The shared modal slot can now have a different file opened before the first one's mount settles, sodataset/[id].astrotracks a monotoniceegModalSeqplus the current teardown handle: a superseded mount attempt (rapid reopen with a different file, or a close while a fetch is in flight) calls its owndestroy()and — if the reason it was superseded was a close rather than a newer open — re-clears the slot, sincedestroy()only unwinds side effects (observers/listeners/GL context), not the DOM the mount already wrote. Verified this specific race by hand (see below).What I verified in the browser
Used the
puppeteerMCP tools against the dev server (Playwright's own Chromium wasn't installed locally and the download was too slow to block on; puppeteer gave full coverage instead) on a real dataset with real EEG recordings (nm000103, HBN-EEG NC) and a real mirrored dataset (on007753) for the ProvenanceToggle popover, in both light and dark theme (data-themeattribute):display: none(this caught the[open]-gating bug described above — a screenshot showed "Compute on this dataset" bleeding through behind the download dialog before the fix).details.openflips tofalse).zarrAvailable === "false"fallback path (forced via a synthetic dataset attribute): renders the recorded failure reason + download link inside the modal.bun run typecheck(0 errors),bun run test(907/907 passing, including two new/updated tests inrender-dir-listing.test.tsfor the eeg row's slot-less markup andaria-haspopup),bun run lint(clean).Not verified: real keyboard-driven Esc-to-close (native
<dialog>behavior — untouched by this change, and syntheticKeyboardEvents can't trigger the browser's trusted-event-only handling for it; didn't want to block on the slow Playwright Chromium download to confirm something I didn't modify). Real:focus-visiblestyling on Tab-driven keyboard focus, for the same synthetic-event limitation — confirmed the CSS declaration is present and matches the existing:focus-visiblepattern used elsewhere in the codebase (SiteNotices.astro's dismiss button,ConfirmDialog.astro's verify input).Left out
Nothing deliberately scoped out beyond the ConfirmDialog judgment call above.