Repository navigation
feat(Drawer): independent scope, modality, and scrim paint - #5550
freddymeta wants to merge 9 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsCarousel (@astryxdesign/core) · View in Storybook
Drawer (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
05cff5f to
0019e5c
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Thanks—pane-scoped Drawer is the right owner. Please keep scope and modality orthogonal: containerRef chooses the host only; expose explicit modality ('modal' | 'nonModal') rather than silently changing hasScrim and focus behavior.
Three runtime paths still block:
- In a scrollable pane, wheel input over the reveal moved the absolute portal host:
scrollTop 0→180moved the 292px drawer from y=44 to −136, leaving 116px visible (Drawer.tsx:290-301). - Two reverse Tabs focused the dimmed opener, and Enter activated it while pointer input stayed blocked (
Drawer.tsx:864-880). - Replacing the target behind the same ref removed the dialog while
isOpenstayed true; even closed, target resolution doubled Profiler commits at N=1/3/10 and added one style read per Drawer (Drawer.tsx:598-612).
Please preserve the host through scroll/replacement, make blocking consistent across input modes, and avoid the extra mount pass/read.
[Reviewed by Robohands]
|
All four in
|
|
Correction on my last comment: I've dropped
Three conventions cover it. 1. Escape Hatches — "Don't add flexibility without a demonstrated use case." Its own worked example is this exact shape:
Modality is focus trap + scroll lock + top layer. The prop's only new capability was two combinations neither of us has a use case for: a scrim that doesn't block (looks blocked, isn't) and a modal with no scrim (blocks with no sign it's blocked). Both are things the docs would warn against. 2. 3. The name is wrong even if the axis were right. What I think you actually caughtNot a conflation — a scope change wearing the costume of a semantic one.
The reason it read as a silent behaviour change is that the bounded scrim wasn't actually blocking — your own second finding. It dimmed, and the keyboard walked straight through it. So The one thing that genuinely doesn't survive containment is the top layer —
Happy to be argued back into it if you have a caller who needs one of those two combinations — that's exactly the "demonstrated use case" the convention asks for, and I couldn't produce one. |
|
Reversing my last comment — I talked myself out of it on a durability argument ("new permanent API to express two anti-patterns"). That argument doesn't apply here: What changed from the first attemptThe first version defaulted modality?: 'modal' | 'nonModal' // default 'modal' — what is ENFORCED
hasScrim?: boolean // default modality === 'modal' — what is SEENThe scrim follows modality, so ordinary cases still set one prop, and both separations are expressible: a non-modal inspector that dims its context, and a modal over content that should stay legible. And I had bounded mode wrongLast version warned on "The area behind is out of play" is true whether that area is the page or the container. Only the mechanism differs, because the top layer is viewport-sized:
So there's nothing to refuse and nothing to warn about. The warning is gone; the two things a bounded modal genuinely isn't ( Migration20 Sorry for the round trip — you asked for this in the first place and I second-guessed it against the wrong rulebook. |
|
One more turn on this, and it lands somewhere simpler than either previous version: one prop, Freddy's question was the right one — are these two props actually pointing at the same thing? Near enough, yes. They came apart only in combinations neither of us could name a use for, and both are things we'd warn against:
So it's one decision, and it should be one prop. The rename is the part that was actually worth doing. Honest cost: it diverges from
|
cixzhang
left a comment
There was a problem hiding this comment.
Thanks—the scroll and closed-cost fixes now pass, but our prior API ask is still open. The ratified Drawer ruling keeps containerRef as scope, modality as enforcement, and hasScrim as paint; isModal recombines the last two, so please restore those independent axes (Drawer.tsx:478-519).
The inert pass also snapshots only current children. In Chromium, a control inserted into the pane after open had no inert, accepted focus, and stayed keyboard-active while the scrim blocked its pointer path (Drawer.tsx:719-746). Please keep later pane content unavailable for the full modal lifetime.
This also needs a rebase: #5549 landed useDrawerDialogPresence, and current head conflicts in Drawer.tsx and Drawer.test.tsx.
[Reviewed by Robohands]
…iewport Rebuilt on today's main as one commit. The branch carried eight, including #5549's two (landed, and dropped here) and four that walked the modality API out and back again — noise in a review, so they are squashed into the shape they arrived at. Rebased onto `useDrawerDialogPresence`, which #5549 extracted. The hook gains one optional field, `mountHost`: a ref is stable, so nothing in it can observe the dialog ELEMENT arriving, and a bounded Drawer renders no dialog until its container resolves one commit later. Without naming the host as a dependency an already-open bounded Drawer never opens at all — which is exactly how the rebase first failed its own test. Bounded mode, unchanged from the reviewed head: - the panel is portalled into the container and pinned to its SCROLLPORT, so scrolling the pane 180px no longer carries the drawer 180px with it; - `isModal` blocks the container with `inert` rather than the top layer, so the keyboard is blocked exactly as far as the pointer is; - target resolution is deferred until the panel paints and survives the host being swapped or detached. New in this round, from review: the inert pass is held for the whole open lifetime instead of stamped once. A pane is live content — a row streams in, a menu opens, a lazy panel resolves — and a one-shot pass left every later arrival focusable behind a scrim that already blocked the pointer. A `childList` MutationObserver re-runs it; the drawer still hands back only what it inerted, so a container someone else marked is returned untouched. Two tests, both verified failing against a one-shot pass.
4fecc8f to
c892388
Compare
|
it looks a little strange to me to separate separately @rubyycheung and I are planning to promote this component to core after this. no rush |
cixzhang
left a comment
There was a problem hiding this comment.
The independent scope/modality/scrim API is acceptable as reversible lab work, but two bounded modal Drawers sharing one host inert each other's clip wrappers. The front Drawer can therefore become inoperable by keyboard and pointer.
Please fix that bounded-modal stacking boundary; the other API experimentation does not block.
[Reviewed by Robohands]
# Conflicts: # apps/sandbox/src/app/(sandbox)/pages/motion-lab/__generated__/motionAudit.ts
Two bounded modal Drawers sharing a container each inerted every child of the host except their own clip wrapper, so each inerted the other and the front panel — the one the user is looking at — went dead to pointer and keyboard. Enforcement is now single-owner per container. A second registry tracks RENDERED bounded drawers, deliberately not the existing LIFO stack of OPEN ones: inert is held for the whole exit transition, so a drawer that has started closing must still enforce, and it leaves that stack the moment it closes. Only the front-most blocking drawer in a host applies inert, and its pass spares any drawer opened after it — a modal puts what is BEHIND it out of play, and a drawer in front of it is not that. Four tests: front interactive with the one behind it blocked, handback when the front one closes, a non-modal drawer opened on top left alone, and the container never released when the drawer behind closes first. Each verified to fail on the previous head.
|
(Replaces my previous comment, which was too long.) Fixed in The bounded-modal stacking boundary. You were right, and the cause was the escape hatch in the pass: each bounded modal inerted every child of its host except its own clip wrapper. Two of them in one container therefore inerted each other, and the front panel — the one the user is looking at — went dead to pointer and keyboard. Enforcement is now single-owner per container:
Why a second registry, rather than duplication. The existing LIFO stack tracks open drawers, so Escape closes the innermost, and a drawer leaves it the moment it starts closing. Bounded enforcement has to outlive that — Four tests, each verified to fail on the previous head: front interactive with the one behind blocked (the reported bug); handback when the front closes; non-modal on top left alone; container never released when the drawer behind closes first — watched with a Negative control on each half: remove the front-most gate and its stack subscription → three of four fail; remove the spared-clips skip → the non-modal one fails. Gates: |
xinzi-bot
left a comment
There was a problem hiding this comment.
Thanks — the bounded stacking path looks fixed. One API behavior still leaks: hasScrim={false} removes paint, but viewport modals still close on an invisible backdrop click while bounded modals with no scrim do not. Please gate backdrop dismissal on the visible scrim path so outside-click semantics stay consistent.
[Automated review]
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — the pane-scoped inspector is the right capability, and the scroll, late-content and closed-cost fixes hold at this head.
We asked for the bounded-modal stacking boundary last round, and the case we reported is fixed. It returns one step over: change one bounded drawer's modality while another is open in the same pane, and the drawer behind takes over the inert pass and applies it to the front panel. In Chromium that panel keeps painting on top and stops responding — whoever is working in that inspector loses every control in it, to keyboard and pointer, with nothing explaining why (Drawer.tsx:821-830).
A bounded pane now carries two orderings of its drawers — which paints in front, and which applies inert — and here they disagree. Could one ordering decide both? A test flipping modality on an open pair would pin it; the 64 we have pass without seeing this.
[Reviewed by Robohands]
Dismissed because the review used non-authoritative auto-ratified wiki guidance. Current in-repo specs do not settle the Drawer API; owner judgement is required before contributor review. The measured implementation evidence is retained for reassessment after that decision.
cixzhang
left a comment
There was a problem hiding this comment.
Thanks — the main merge does not change Drawer, so the bounded stacking block from our prior review is still open: someone using two bounded inspectors can lose every control in the visible front Drawer.
If a buried Drawer changes from modality="nonModal" to "modal" while another modal Drawer is open above it, the buried entry becomes the inert owner. At this exact head, Chromium refused focus and pointer hit-testing on the visible front panel (Drawer.tsx:821-900). Please keep rendered order stable across live modality changes and cover this path in the pair matrix.
[Reviewed by Robohands]
|
Closing because we are no longer using the bounded Drawer variant. |
The gap
A
Draweris always the viewport's. There is no way to say this inspector belongs to this pane — a split view, a dashboard card, a canvas, a chart panel.position: fixedandshowModal()both address the screen, so today you either take over the whole page or hand-roll the panel.People do hand-roll it. A design system downstream of ours carries its own sheet for exactly this, with a "contained" mode whose own source comments call it an approximation of what Astryx does not have. That is the demand signal.
The API
One prop for scope.
containerRef?: React.RefObject<HTMLElement | null>— matching theanchorRefshape Popover/Tooltip/Typeahead already use. The panel is portalled into the element and pinned withposition: absolute, at the container's height, with the 56px mobile reveal measured against the container (100%) rather than the viewport (100dvw).Absent, nothing changes:
containerRefis optional and every existing path is byte-identical.Screenshots
Lab/Drawer→Bounded. Closed:Open — the panel is inside the pane, the scrim dims only the pane, and the button below it is still live:
(Assets live on the
assets/pr-5550branch of this repo — asset-only, deletable with the PR. I have no fork.)API: three independent axes
The review was right: scope, enforcement, and paint are separate decisions.
The defaults preserve the ordinary case: a modal Drawer has a scrim, and a non-modal Drawer does not. Callers can deliberately separate them for future products:
modality="nonModal" hasScrimdims context without taking it out of play. Its scrim is paint-only and pointer-transparent.modality="modal" hasScrim={false}blocks context without dimming it.containerRefchanges only the scope. Viewport modality uses the browser top layer; bounded modality appliesinertto current and late-inserted siblings for the full rendered lifetime, including exit.isModalis removed rather than retained as an alias:labis private/canary and all branch-owned call sites, docs, tests, and stories now use the independent API.The native dialog also follows a live
modalitychange. Because an open<dialog>cannot switch betweenshow()andshowModal()in place, Drawer closes and immediately reopens it in the requested mode while preserving the original focus-return target.The one honest trade
A bounded modal cannot use the top layer. A top-layer element is always viewport-sized, so containment and the top layer are mutually exclusive — no amount of CSS makes
showModal()respect a box. That costs exactly two things,aria-modaland the body scroll lock, because neither is true of a bounded panel. The blocking itself is not lost:modality="modal"makes the container backgroundinert.showModal()/show()show()modality="modal"enforced byinert::backdroparia-modal"true"when modalThe area the drawer belongs to is the area modality blocks. Paint remains independent:
hasScrimcontrols dimming, while keyboard, pointer, and accessibility blocking followmodality. The rest of the page stays live for a bounded Drawer.A
useDevWarningfires when the container computes toposition: static, because the panel would silently escape to the nearest positioned ancestor.Behaviour in a scrolling pane
An absolutely positioned child of a scroll container resolves against the scrolled padding box, so a naive
inset: 0rides the content out of view. The clip box offsets by the container's scroll position and sizes to its client box, so the panel stays in the scrollport:scrollTop: 0scrollTop: 180Written straight to the node from a passive scroll listener rather than through React state — a re-render per scroll frame is not affordable, and a transform stays on the compositor. A container that does not scroll reports offset 0 and its padding box, so it is one code path.
Cost when closed
Resolving the portal target is a state write, so doing it on mount cost every closed bounded Drawer on the page a second commit. It now resolves only once the panel actually paints; a
Profilertest asserts a closed bounded Drawer commits exactly['mount']. ThegetComputedStylebehind the static-container warning likewise moved out of render into a dev-only effect.Resolution also survives the host being swapped or detached — the ref object never changes identity, so a dependency array cannot see it; a
MutationObservercan.Screenshots
Lab/Drawer→Bounded. Closed:Open — the panel is inside the pane, the scrim dims only the pane, and the button below it is still live:
(Assets live on the
assets/pr-5550branch of this repo — asset-only, deletable with the PR. I have no fork.)Measured
Lab/Drawer→Bounded, in Chromium against a real Storybook build:positionabsolute:modalfalsearia-modalbodyoverflowvisible(not scroll-locked)elementFromPointover that controldisplayreturns tononeTests
59 Drawer tests pass after the current-main merge. New guards cover all four modality/scrim combinations in both viewport and bounded scopes, live modality changes, late-inserted pane content, and inert cleanup after exit. Coupling scrim paint back to modality makes three focused axis tests fail. Full build, lab/docs/Storybook typechecks, repository checks, and strict lint pass.
No changeset:
@astryxdesign/labis private and not released.