I put a modal dialog inside a 40-pixel toolbar and never opened it in a browser
I recently shipped a “New sprint” dialog for our app’s top-level Sprints page. A user pressed the button and got a thin strip on the screen with a single dropdown in it. The dialog’s title and its Create button were there, but they sat above and below the visible area, and the only way to reach them was to scroll inside that strip. I wrote this bug. Here is what I did, why my tests didn’t catch it, and what I’m changing.
What I built
The design asked for a dialog with a Project select, a short line explaining what Create does, a disabled state with a reason when a project already has a draft, and Cancel and Create buttons. It didn’t say where in the page the dialog should be mounted. That was fine, because the app already has one shared modal component and every dialog uses it.
The dialog itself was correct: right fields, right labels, right behaviour. The mistake was where I put it.
The New sprint button lives in the page’s breadcrumb row, a short strip across the top of the frame. The frame provides a portal slot so screens can drop controls at the end of that row. I put the button in that slot, and because the dialog’s open/closed state sat in the same component as the button, I rendered the dialog right next to it, inside the slot.
So the whole modal, scrim and panel, ended up inside a toolbar about 2.5rem tall.
Why that broke it
Our dialog CSS uses position: fixed; inset: 0 and sizes the panel with percentages: a max width, and a max-height of nearly 100% with overflow-y: auto. That only works if the dialog’s containing block is the viewport. I assumed it was and never checked.
The breadcrumb row declares container-type: inline-size so it can use container queries. Under the older containment spec, and in every browser engine released before a fairly recent change to it, container-type also applies layout containment. A layout-contained element becomes the containing block for its position: fixed descendants. In those engines my “full-screen” dialog was laid out against the breadcrumb row:
- The overlay was the size of the row, roughly 1200×42 pixels.
- The panel’s
max-height: ~100%became about 50 pixels. - The shared dialog component focuses the first field when it opens, so the panel scrolled to the Project select. That left the dropdown visible with the title hidden above it and Create hidden below.
That is exactly what was reported. In current engines, where container-type no longer applies layout containment, the panel happens to lay out against the viewport and looks fine. Our desktop app embeds the platform’s system web engine, and the web version runs in whatever browser the user has, so “fine in the newest engines” doesn’t cover our users.
The wrong placement caused a second bug that shows up in every engine. The breadcrumb row also has position: relative; z-index: 10, which creates a stacking context. The dialog’s own z-index: 40 only applied within that context, not the whole page. The navigation rail is a sibling at z-index: 40, so it painted above the dialog and its scrim. On a phone-sized screen the rail covered the start of the dialog’s text. On desktop the rail’s button stayed bright and clickable over the scrim. A modal that lets you click past it isn’t really a modal.
Why my tests didn’t catch it
I wrote unit tests for the dialog’s role, its options, and what Create does, and I ran them at both desktop and phone widths. They passed. But they ran in jsdom, which doesn’t do layout at all. Those tests would pass whatever size the panel was, even zero pixels. Running them “at both widths” only proved which branch of the layout code rendered, not what the user would see. Describing that as layout coverage overstated what I had verified.
Worse, I knew. My notes on the task ended with a line saying the dialog hadn’t been tried in a browser. I wrote that sentence and closed the task anyway. For a task whose whole deliverable was a new piece of UI, that line was the bug report, and I filed it myself.
We already have a real-browser test suite that runs across several engines and viewport sizes, plus a screenshot tool that captures any page in the full app frame. One run with the dialog open would have shown either the collapsed strip or the rail painted over the panel.
It spread
A few commits later, another screen’s two dialogs were built by copying my pattern, with each dialog rendered in the breadcrumb slot next to the button that opens it. They have the same defect. Code that looks finished gets copied, and nobody re-checks a pattern that seems to already work.
What I should have done
Our codebase already had two correct patterns, in files I was reading at the time.
-
Render the dialog beside the page, not inside the toolbar. Keep the button in the breadcrumb slot and lift the open state up one level, then render the dialog as a sibling of the page content:
<ToolbarSlot> <Button onClick={() => setOpen(true)}>New sprint</Button> </ToolbarSlot> {open ? <NewSprintDialog onDismiss={() => setOpen(false)} /> : null} <PageContent />Another screen already did exactly this with its confirm dialogs.
-
Portal the dialog to
document.body. Some of our dialogs and our drawer component already do this, so they escape whatever box opened them. Better still, the shared dialog component can portal itself for every caller, so this mistake can’t happen again. That’s the fix I’m pushing for.
I rendered the dialog inside the toolbar because its state lived there, which was the easy choice in React. I treated that convenience as if it were a placement decision. A modal isn’t one of the toolbar’s controls. It covers the whole page and should be mounted at that level.
What I’m changing
These are the checks I’ll apply to my own work and in code review:
- The box that opens a dialog is never the box it lives in. Any dialog, drawer, or other
position: fixedsurface inside a frame slot (toolbar, page bar, stats strip) gets moved beside the page or portaled to the body. - Check the ancestors, not just the surface’s own CSS. Between a fixed-position element and
<body>, look forcontainer-type,contain,transform,filter,will-change, orpositioncombined withz-index. Any of these can take over the element’s size, its layer, or both, in some engines or in all of them. - jsdom alone isn’t enough for UI. A new or changed modal needs at least one real-browser run or a screenshot of it open, at both desktop and phone widths, and the notes should say which engine it was seen in.
- “Not checked in a browser” means not done. If I find myself writing that about user-facing UI, the task stays open.
- Verify before you copy. Before reusing a pattern from another screen, confirm the original was actually checked.
The fix for both screens is small. The real lesson is that the bug could only be found by opening the dialog in a browser, and I wrote down that I hadn’t done that. I’m sorry to the user who ran into it and to the teammate who copied my pattern.