Skip to content

Commit b8eef54

Browse files
committed
feat(core): BottomSheet stacks by open order, replaces on a same-update switch, and BottomSheetSwitcher is deprecated
Modal bottom sheets form one stack per document, ordered by open order (ties within one commit by tree order), with one visible scrim, covered sheets receded and blocked, the native top layer reconciled before paint, and dismissal reaching only the top sheet. A sheet rendered in a closing sheet's content leaves with it and comes back with it while its own isOpen is still true; its state is never written for it. A whole BottomSheetSwitcher flow is one level of the stack. When the top sheet closes and exactly one other sheet opens in the same update, from a control inside the closing sheet, the opening sheet replaces it with the switcher's handoff: it enters above the retained sheet, a taller retained sheet aligns down to meet it, the retained sheet fades after both motions and keeps the scrim until the replacing sheet takes it over with no transition, and focus moves into the entering sheet. Unrelated owners acting in one update keep their own push and pop motion and their own focus return. Non-modal sheets (hasScrim={false}) are hosted in the top layer as manual popovers (show() below the Popover API floor), with no scrim, scroll lock or focus trap as before; they never stack, but they replace each other the same way, return focus to their opener on close while focus is still inside, and the toast viewport re-enters the top layer above them. The private registry keeps one state per page (shared by every copy of the package, guarded by shape) and one stack per document; closes driven by the registry never move focus; a change of scrim owner lands with a 0s inline pin for two frames; closing every sheet of a stack in one update returns focus once, to the bottom sheet's target, after the last dialog has closed. A BottomSheetSwitcher flow, whose steps each own a native dialog, is one level of the stack: the active step's dialog is the level, a tree anchor keeps same-commit ties stable across handoffs, the registry is told when a handoff changes the dialog so the sheets above the flow stay above it, the flow's scrim is multiplied by the stack's, and covered step dialogs carry the stack state. BottomSheetSwitcher and BottomSheet's sheetId are deprecated in favour of one standalone sheet per step driven by one state value; a flow used on its own behaves as released, and a flow stacked with other sheets is one level of the stack, until a future minor removes them. The CLI block templates, the Lab MobileTokenizer and the stories teach the replacement. A modal standalone sheet is a toast outlet only while it is the open sheet on top; a covered sheet hands the outlet to the sheet above it and takes it back when that sheet closes. Implements component:BottomSheet DEC-2 / FR5–FR12 / AR3–AR4, component:BottomSheetSwitcher FR10 and DEP-0015, and the architecture:layer-runtime toast re-entry; deletes their implementation gap notes and adds the stacking and replace suites to verified_by.
1 parent 4444d70 commit b8eef54

40 files changed

Lines changed: 11261 additions & 659 deletions
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] `BottomSheet` stacks by open order. A modal sheet opened while another modal sheet is open now stacks on top of it instead of presenting as a second, unrelated dialog: the covered sheet stays mounted with its state, recedes behind the top sheet (0.96 / −8px at depth 1, 0.92 / −16px from depth 2), and is blocked from pointer, keyboard, and assistive technology; only the bottom sheet's backdrop dims the page, so a stack no longer darkens per level; and Escape, a scrim tap, a swipe, and a platform close request pop only the top sheet, through that sheet's own `onOpenChange` and honouring its `purpose`. The top sheet is the most recently opened one still open, wherever the sheets are written — siblings, separate components, inside another sheet's content, or inside a `BottomSheetSwitcher` step; a whole switcher is one level, and switching its step keeps its place. When several sheets open in one update (a deep link), tree order decides and the first painted frame is already right: a sheet nested in another sheet's content no longer opens beneath its parent. Closing the top sheet returns focus into the sheet it reveals; closing every sheet of a stack in one update returns focus once, to the bottom sheet's `finalFocusRef` or opener, after the last dialog has closed (each sheet's own return used to be refused while the others were still modal). A sheet rendered inside a closing sheet's content now leaves with it instead of staying open invisibly, and comes back with the host if its own `isOpen` is still true (its state is never written for it); sheets above it that are not in its content stay open. Sheets with `hasScrim={false}` never stack and are never stacked on. No prop, type, or export changes; a modal sheet on its own behaves exactly as before (apart from the reduced-motion fix released alongside).
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] BottomSheet follows the reduced-motion design rule. With `prefers-reduced-motion: reduce`, a sheet's entrance, exit, recede and replace handoff — a `BottomSheetSwitcher` step's too — no longer travel or scale: on a touch screen (`pointer: coarse`) the entering sheet fades in at its resting place and the leaving or retained sheet fades out where it is, opacity only, within 200 ms; with a mouse, trackpad or keyboard the change is immediate, except that a swipe dismissal — a transition a touch drag's release started — fades out in place on every pointer. Before, the motions ran shortened transforms on every pointer and nothing cross-faded.
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] `BottomSheet` replaces a sheet that closes in the same update another opens. When the top sheet of a stack closes and exactly one other sheet opens in the same update (one state value naming the open step does this), the new sheet replaces it instead of stacking on it: it rises above the replaced sheet, a taller replaced sheet moves down to meet its top edge at the same time, the replaced sheet fades only after both motions finish and is inert and hidden from assistive technology from the start, the scrim holds steady with no dip, focus moves into the new sheet, and closing the flow later returns focus to the element that opened its first sheet. This is the handoff `BottomSheetSwitcher` runs between its steps, now available to standalone sheets; a multi-step flow can be written as one `BottomSheet` per step with no switcher. A covered sheet closing while a sheet opens, several sheets changing at once, or a close and an open in different updates keep the ordinary push and pop motion, and existing stacking behaviour is unchanged. A replace is recognised only when the move was made from inside the closing sheet: the control last pressed (or, with no recent press, the focused element) was in it, as a step's own Continue or Back button is; a close and an open driven from a control outside it, by two unrelated owners, stay a pop and a push with their own focus return. Non-modal sheets (`hasScrim={false}`) replace each other the same way: they are now hosted in the browser top layer as manual popovers, with no scrim, focus trap or scroll lock as before, so a non-modal step orders above the one it replaces, and the toast viewport re-enters the top layer above a non-modal sheet as it does above a modal. The non-modal sheet's page-level `z-index` is gone with the move (AST-027); below the Popover API support floor the sheet falls back to `show()` in page stacking order, usable but with no promise over later page content (the reduced fallback AST-003 describes). They still never stack. A non-modal sheet now also returns focus to its opener when it closes while the person is still in it (a modal sheet always did); focus the person took elsewhere on the live page stays there. The private stack registry now keeps one state per page (shared by every copy of the package on it, guarded by shape) and one stack per document. No prop, type, or export changes; a modal sheet on its own behaves exactly as before (apart from the reduced-motion fix released alongside). A non-modal sheet on its own changes in three ways with its new host: it is in the top layer (a manual popover) instead of page stacking order, its page-level `z-index` is gone, and it returns focus to its opener on close while focus is still inside it; its scrim-less, scroll-free, page-interactive contract is unchanged.
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] `BottomSheetSwitcher` and the `sheetId` prop of `BottomSheet` are deprecated. The replacement is already in this release: write each step of a multi-step flow as its own standalone `BottomSheet` with `isOpen`, driven by one state value that names the open step; closing the top sheet and opening the next in the same update runs the same replace handoff the switcher ran (entering step above, a taller retained step aligns down and fades after both motions, one steady scrim, focus into the new step and back to the flow's opener on close). Migration, per flow: (1) replace the `activeSheet` / `onActiveSheetChange` pair with one `step` state value; (2) give each step `isOpen={step === 'id'}` and `onOpenChange={isOpen => !isOpen && setStep(current => (current === 'id' ? null : current))}` in place of `sheetId="id"` (the guard keeps a step that is being replaced from clearing the step the person just chose); (3) remove the `BottomSheetSwitcher` wrapper, moving its `hasScrim` onto every step; (4) keep the step buttons as they were (`setStep('next')`). The handoff runs when the move is made from inside the open step (a step's own Continue or Back, or code while focus is in it); a step changed from a control outside the flow's sheets — a page control beside a `hasScrim={false}` flow, or code after focus has left the step — closes and opens with the sheets' own push and pop motion, where the switcher handed off on any `activeSheet` change. The switcher's other props map as follows: `onCancel` becomes a guarded `onOpenChange` on each step (one that ignores `false` while the flow must stay open), which keeps the step's dialog role — a standalone sheet reports Escape, the platform close, the scrim tap and the swipe all as `onOpenChange(false)` with no reason, so the guard holds the step open against all of them while it applies, where `onCancel` vetoed only the cancel request; a veto of Escape alone has no equivalent, and the only per-path lever is `purpose` (`form` keeps Escape and blocks the scrim tap and the swipe; `required` blocks all three and exposes the step as an `alertdialog`). A consumer `aria-label` / `aria-labelledby` becomes each step's `label`, which names its dialog. `ref`, `id`, `data-testid`, `className`, `style`, `xstyle` and the other dialog props have no dialog-level equivalent — a standalone sheet's `ref` and base props reach its panel `<div>` and its dialog is implementation — so a test or an anchor that needs the dialog queries the panel's `closest('dialog')`, and dialog-level styling is dropped. Flows that keep using the switcher keep working: a switcher flow used on its own behaves as released — with two fixes released alongside: a toast raised from a step now renders above the flow and can be pressed, and under reduced motion its steps' entrance, exit and handoff follow the reduced-motion rule (no travel; a cross-fade on touch, immediate otherwise) — and when it is stacked with other sheets the stacking behaviour of this release applies to it as one level (it recedes and is blocked when covered, shares the one scrim, stands down from dismissal while covered, and returns focus by the stacking rules). Its declarations and docs are marked `@deprecated` and its docs, templates and stories show only the replacement, until a future minor release removes it. Non-modal flows (`hasScrim={false}`) migrate the same way: non-modal sheets replace each other too.
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[fix] Toasts raised from a `BottomSheetSwitcher` step stay visible and clickable above the flow. A modal switcher flow now supplies its active step's dialog as the toast viewport's host, as a standalone scrim `BottomSheet` and a `Dialog` do; the host follows each handoff to the entering step, and the flow hands the viewport back when it closes. Before, the viewport stayed behind the flow's dialogs, so a toast raised from a step was covered by the step and a press on it landed on the step. A `hasScrim={false}` flow is not modal and leaves the viewport in place.
6+
7+
@imdreamrunner
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[feat] The two Bottom Sheet flow block templates (`BottomSheetSwitcherShowcase`, `BottomSheetSwitcherReviewFlow`) now teach the replacement for the deprecated `BottomSheetSwitcher`: each step is a standalone `BottomSheet` driven by one state value, and moving on replaces the open step in place. Both stay examples of `BottomSheetSwitcher` (the showcase remains that page's hero) and are now also listed under `BottomSheet`. Template ids, files and their published registry identities keep their names, so `template <name>`, the released JSON ids and the ShadCN routes are unchanged.
6+
7+
@imdreamrunner

‎apps/storybook/stories/BottomSheet.stories.tsx‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,3 +787,72 @@ export const NestedPopover: Story = {
787787
);
788788
},
789789
};
790+
791+
/**
792+
* A no-scrim sheet with a `data-autofocus` field: focus on open follows the
793+
* native host, which lands on the panel; the field is not focused.
794+
*/
795+
export const NoScrimAutofocus: Story = {
796+
name: 'No scrim with a data-autofocus field',
797+
render: () => {
798+
const [isOpen, setIsOpen] = useState(false);
799+
const [value, setValue] = useState('');
800+
return (
801+
<>
802+
<Button label="Open sheet" onClick={() => setIsOpen(true)} />
803+
<BottomSheet
804+
isOpen={isOpen}
805+
onOpenChange={setIsOpen}
806+
label="Filter places"
807+
hasScrim={false}
808+
height="hug">
809+
<Section padding={4}>
810+
<VStack gap={3}>
811+
<TextInput
812+
label="Search"
813+
value={value}
814+
onChange={setValue}
815+
hasAutoFocus
816+
/>
817+
<Button label="Done" onClick={() => setIsOpen(false)} />
818+
</VStack>
819+
</Section>
820+
</BottomSheet>
821+
</>
822+
);
823+
},
824+
};
825+
826+
/**
827+
* A modal sheet with a `data-autofocus` field (a TextInput with hasAutoFocus):
828+
* what focus lands on when the sheet opens.
829+
*/
830+
export const ModalAutofocus: Story = {
831+
name: 'Modal with a data-autofocus field',
832+
render: () => {
833+
const [isOpen, setIsOpen] = useState(false);
834+
const [value, setValue] = useState('');
835+
return (
836+
<>
837+
<Button label="Open sheet" onClick={() => setIsOpen(true)} />
838+
<BottomSheet
839+
isOpen={isOpen}
840+
onOpenChange={setIsOpen}
841+
label="Edit note"
842+
height="hug">
843+
<Section padding={4}>
844+
<VStack gap={3}>
845+
<TextInput
846+
label="Note"
847+
value={value}
848+
onChange={setValue}
849+
hasAutoFocus
850+
/>
851+
<Button label="Done" onClick={() => setIsOpen(false)} />
852+
</VStack>
853+
</Section>
854+
</BottomSheet>
855+
</>
856+
);
857+
},
858+
};

0 commit comments

Comments
 (0)