Skip to content

Commit 252b45b

Browse files
authored
feat(Layer): one input hold, first used by Dialog, Drawer and MobileNav (spec:AST-094 FR35) (#8342)
* feat(Layer): one input hold, first used by Dialog, Drawer and MobileNav (spec:AST-094 FR35) Layer/inputHold holds a layer's pointer input while its presentation enters or leaves. holdInput(layer, {until, scope}) raises a shield: 'viewport' over the whole viewport while a modal layer enters; 'surface' over the layer's own box while a non-modal one enters, the page around it live; 'layer' over the viewport, its content inert, while a layer leaves. It decides by each event's pointer (a finger's or a pen's press is held to its end; a mouse passes once it moves with no button down, or from the start when the page last heard a mouse, DEC-16), never cancels a touch's start, and cancels a one-finger move so a pinch still zooms (FR10). It hears input through Core's shared input stream before every other subscriber, and ends the dispatch for a held event, so press feedback and the gesture host never hear it; the stream gains first subscribers and records the type of the latest pointer event it delivers (getLastPointerType). The gesture host asks the hold for each touch (holdsTouch), so the hold imports nothing from gestures/ and a component in the root entry may use it statically (architecture:react-component-runtime INV13). Its first users hold only under a coarse primary pointer, a touch presentation (FR13): Dialog, Drawer and MobileNav hold a finger's tap or drag while they enter (holdEntranceInput, which reads the entrance's own animations; MobileNav's slide-in is capped at 550 ms), a non-modal Drawer only on its panel. Under a fine primary pointer nothing is held and nothing listens (FR24). Where the primary pointer is fine and the screen also takes touch, a finger is not held yet; AST-094's current-state impact and Drawer's record name that gap. AST-094's current-state impact also names the first press of a still mouse after a finger, which lands on an entering presentation's shield. AlertDialog renders Dialog, so its entrance is held too: its record says FR7 ships in part, the leaving alert's inert content waiting for FR6's dismissal. Every browser proof lands its input at an exact point (an entrance held where it is, the page's clock, or an exact step of a drag) and plays once. The WebKit interaction lane's scope includes Layer/inputHold.ts: the gesture host imports it, so the gesture specs' fixture bundles it. MobileNav's record states what the rest of the slide-out after the close does: it is inert, taking no input and hidden from assistive technology (FR5). A browser case proves both against the open drawer. From #8342 and its per-event offer, #8630 (Dialog and Drawer) and #8374 (MobileNav). Co-authored-by: Cindy Zhang <cindyxz@meta.com> * Merge branch 'main' into uikit/c18-presentation-hold
1 parent c1a2cae commit 252b45b

37 files changed

Lines changed: 4798 additions & 59 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+
[fix] On a phone or tablet (a coarse primary pointer), a tap or a drag that lands while a `Dialog` or a `Drawer` is still entering no longer closes it, runs one of its actions, moves focus or scrolls the page: it reaches nothing until the entrance has played, and the dialog or drawer finishes entering and stays open. Around a `Drawer` without a scrim only a tap or a drag on the panel is held, and the page stays live. Keys and assistive technology stay live during the entrance, the content stays in the accessibility tree, a pinch still zooms the page, and a mouse or a trackpad still clicks: at once when it was the last pointer used, otherwise once it moves.
6+
7+
@vjeux

‎.changeset/layer-input-hold.md‎

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+
[chore] Internal: one input hold for every layer (`Layer/inputHold`). While a layer presents, a finger's or a pen's touch, press or click reaches nothing: anywhere around a modal layer, and only on the layer itself around a non-modal one, whose page stays live. A mouse passes once it moves, at once when the page last heard a mouse (keys and assistive technology still act, and a pinch still zooms the page). While it dismisses, every press and click reaches nothing, and the layer's content is inert. The gesture host asks the hold about each touch (`holdsTouch`), and `isInputShield` lets a hit test see past a hold's shield. Not exported from the package entry point; Dialog's and Drawer's entrance holds and MobileNav's drawer use it.
6+
7+
@vjeux
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] On a phone or tablet (a coarse primary pointer), a tap or a drag during MobileNav's slide-in reaches nothing; keys and assistive technology stay live, and a mouse or a trackpad still clicks: at once when it was the last pointer used, otherwise once it moves.
6+
7+
@vjeux

‎docs/specs/AST-094-touch-presentations/spec.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ affects_consumer_docs: []
2828
```json
2929
{
3030
"paths": [
31+
"packages/core/src/Layer/holdEntranceInput.ts",
32+
"packages/core/src/Layer/inputHold.ts",
3133
"packages/core/src/motion/uikit/segmented.ts",
3234
"packages/core/src/motion/uikit/slider.ts"
3335
]
@@ -827,7 +829,13 @@ under a finger, and a mouse follows `module:DropdownMenu/useMenuPress` FR3 and
827829
let a scrim or overlay tap close at any time (`spec:AST-003` FR10 and
828830
`architecture:layer-runtime` INV14 leave dismissal to the component). Toast and a non-modal sheet (`component:BottomSheetSwitcher` FR5 and its
829831
Non-modal state) do not hold the page: the page behind them stays live, and
830-
only the sheet itself holds a tap or a drag while it enters.
832+
only the sheet itself holds a tap or a drag while it enters. Dialog, Drawer
833+
and MobileNav hold an entrance only under a coarse primary pointer: where
834+
the primary pointer is fine and the screen also takes touch (a touchscreen
835+
laptop), a finger's tap or drag during the entrance is not held. After a
836+
finger, the first press of a mouse that has not moved since lands on the
837+
entering presentation's shield and does nothing, where FR35 keeps today's
838+
behavior for a mouse (DEC-16); a move of the mouse lowers the shield first.
831839
- BottomSheet, Toast, Lightbox, NavigationStack and keyboard dismissal: a
832840
drag that commits follows FR36–FR40.
833841
- `spec:AST-100` owns release velocity, which FR17 reads.

‎docs/specs/components/AlertDialog/AlertDialog.spec.md‎

Lines changed: 7 additions & 5 deletions
Large diffs are not rendered by default.

‎docs/specs/components/Dialog/Dialog.spec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ architecture:
3131
architecture:react-component-runtime,
3232
]
3333
contributing: []
34-
system_specs: [spec:AST-013, spec:AST-020, spec:AST-021]
34+
system_specs: [spec:AST-013, spec:AST-020, spec:AST-021, spec:AST-094/FR35]
3535
---
3636

3737
# Dialog component contract

‎docs/specs/components/Drawer/Drawer.spec.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ Consumer migration instructions belong in consumer docs and release notes.
9595
motion the slide and the scrim transition still run for 0.01 s. For a fine
9696
pointer, `design:reduced-motion` DR1 forbids the travel and DR3 allows no
9797
animated property; a touch user gets no opacity fade, which DR2 calls for.
98-
- **A tap during the entrance is not held.** Under a finger, a scrim tap that
99-
lands while the drawer is still entering closes an `info` drawer, and a tap
100-
or drag reaches the panel. `spec:AST-094` FR35 holds pointer input until the
101-
entrance finishes.
98+
- **A finger is held during the entrance only under a coarse primary
99+
pointer.** There, a tap or a drag that lands while the drawer is still
100+
entering reaches nothing, and around a non-modal drawer only one on the
101+
panel is held. Where the primary pointer is fine and the screen also takes
102+
touch (a touchscreen laptop), a finger's scrim tap during the entrance
103+
closes an `info` drawer, and a tap or drag reaches the panel.
104+
`spec:AST-094` FR35 holds pointer input until the entrance finishes.
102105
- **A consumer `onCancel` never runs.** Drawer sets its own `onCancel` after
103106
the caller's props, so a caller's `onCancel` is dropped.
104107
`architecture:public-component-api` INV5 has accepted event inputs reach the

‎docs/specs/components/MobileNav/MobileNav.spec.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ verified_by:
2424
packages/core/src/MobileNav/MobileNavPinchZoom.a11y.chromium.spec.ts,
2525
packages/core/src/Layer/layerDismissalFamilies.test.tsx,
2626
packages/core/src/MobileNav/__tests__/MobileNavWidth.a11y.chromium.spec.ts,
27+
packages/core/src/MobileNav/__tests__/MobileNavTouchPresentation.a11y.chromium.spec.ts,
2728
packages/core/src/theme/themingTargets.test.ts,
2829
scripts/check-knowledge.mjs,
2930
apps/storybook/rtl-audit/targets.json,
@@ -40,7 +41,7 @@ architecture:
4041
architecture:public-component-api,
4142
]
4243
contributing: []
43-
system_specs: []
44+
system_specs: [spec:AST-094/FR13, spec:AST-094/FR35]
4445
---
4546

4647
# MobileNav component contract
@@ -142,7 +143,7 @@ Consumer migration instructions belong in consumer docs and release notes.
142143
| FR2 | `isOpen` and `onOpenChange` win when given; otherwise the drawer reads and changes the enclosing AppShell's drawer state. The dialog uses AppShell's drawer id when there is one, else its own; a caller `id` replaces either (Current-state impact). | Current source and tests |
143144
| FR3 | Opening calls `showModal()`, and records the focused element as the opener; where focus lands inside the open drawer is uncontracted here. While open, the page's scroller clips its overflow and keeps its scrollbar gutter: the root, or `<body>` when `<body>` sets its own overflow and the root's stays `visible`. Pull-to-refresh and the page's bounce stop, because a scroll lock under a modal holds the page (`spec:AST-094` FR19). Closing releases all three. | Current source and tests |
144145
| FR4 | The native cancel request (Escape) is routed through the shared dismissal stack and requests close only when this drawer is topmost. A click on the overlay outside the Drawer requests close; a click inside does not. The Close button, named by `@astryx.mobileNav.closeNavigation`, requests close. A caller `onClick` on the dialog runs before the backdrop check; one that calls `preventDefault()` cancels that backdrop close. | Current source and tests |
145-
| FR5 | After a close request the drawer slides out while the dialog stays open, and the dialog closes within its slide-out transition and no later than 250 ms after the request (on the next task, never in the commit that requests it, under reduced motion or a zero-length transition). Reopening before then cancels the close. Unmounting closes the dialog. | Current source and tests |
146+
| FR5 | After a close request the drawer slides out while the dialog stays open, and the dialog closes within its slide-out transition and no later than 250 ms after the request (on the next task, never in the commit that requests it, under reduced motion or a zero-length transition). Reopening before then cancels the close. Unmounting closes the dialog. After the dialog closes, the rest of the slide-out is inert. | Current source and tests |
146147
| FR6 | When the dialog closes, focus returns to the recorded opener if it is still connected and was not the document body; otherwise focus is left alone. A reopen that interrupted a close keeps the original opener. | Current source and tests |
147148
| FR7 | The Drawer enters from its resolved inline edge, from off-screen to on-screen, and the backdrop fades in from transparent, without a reduced-motion preference. Under reduced motion, motion follows `design:reduced-motion` DR1–DR3 (Current-state impact records today's shortfall). The overlay clips the off-screen drawer without becoming a scroll container and allows pinch zoom. | Current source and tests |
148149
| FR8 | `side="start"` or `"end"` sets the edge. `side="auto"` MUST keep the drawer's start and end relationship to the element that opened it (`design:bidirectionality` DR7). Implementation gap: it resolves on each open from the focused element's physical half of the viewport (left half picks `start`, otherwise `end`); when nothing is focused at open it keeps its last value, and before any open it is `end`. | Current source |
@@ -270,6 +271,7 @@ ownership.
270271
| FR2, FR3, FR4 | `MobileNav.test.tsx`; `MobileNavCloseEdgeCases.test.tsx`; `MobileNavScrollbarGutter.test.tsx`; `MobileNavRootScrollClaim.test.tsx` | Escape, backdrop, content click, Close | A wrong close source or a lingering scroll lock fails. | `audit:MobileNav/behavior` |
271272
| FR4 | `layerDismissalFamilies.test.tsx` MobileNav cases | Escape over a required Dialog; cancel while topmost and while not | Closing when not topmost, or not closing when topmost, fails. | `audit:MobileNav/behavior` |
272273
| FR5, ORD3 | `MobileNavCloseVisibility.test.tsx`; `MobileNavCloseEdgeCases.test.tsx`; `MobileNavCloseTiming.test.ts` | Close, reduced motion, reopen, unmount, the 250 ms bound | Closing before the slide-out or a stuck dialog fails. | `audit:MobileNav/behavior` |
274+
| FR5 | `MobileNavTouchPresentation.a11y.chromium.spec.ts` (the slide-out after the close) | Closed dialog, drawer still sliding out; open drawer | A tap on the leaving drawer reaching it, or the browser's accessibility tree exposing the dialog or its links after the close, fails. | `audit:MobileNav/behavior` |
273275
| FR6, AR2 | `MobileNavFocus.test.tsx` | Standalone, AppShell, Escape, removed opener | Focus not returned, or returned too early, fails. | `audit:MobileNav/accessibility` |
274276
| FR7 | `MobileNavEntryAnimation.test.tsx` | Start and end edges | Missing starting style or a scroll-container overlay fails. | `audit:MobileNav/behavior` |
275277
| FR11, AR3 | `MobileNavToggle.test.tsx`; `MobileNavReopen.test.tsx` | Closed, open, reopen | Broken expanded state or id link fails. | `audit:MobileNav/accessibility` |

‎packages/core/src/Dialog/Dialog.doc.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export const docs = {
6969
],
7070
},
7171
description:
72-
'Modal dialog using the native <dialog> element. Modal and inline content starts with theme body text defaults. Ancestor surface/group membership ends as a whole, including group-owned state. Explicit props and unrelated contexts remain unchanged. Place intentional groups and complete required providers inside the dialog. With reduced motion the dialog never slides or scales in: on a touch screen it fades in, in 200 ms or less, and with a mouse it appears at once.',
72+
'Modal dialog using the native <dialog> element. Modal and inline content starts with theme body text defaults. Ancestor surface/group membership ends as a whole, including group-owned state. Explicit props and unrelated contexts remain unchanged. Place intentional groups and complete required providers inside the dialog. With reduced motion the dialog never slides or scales in: on a touch screen it fades in, in 200 ms or less, and with a mouse it appears at once. On a phone or tablet (a coarse primary pointer), a tap or a drag that lands while the dialog is still entering reaches nothing, and the dialog finishes entering; keys and assistive technology stay live, and a mouse or a trackpad still clicks: at once when it was the last pointer used, otherwise once it moves.',
7373
props: [
7474
{
7575
name: 'isOpen',

‎packages/core/src/Dialog/Dialog.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* @file Dialog.tsx
77
* @input Uses React, DialogHTMLAttributes, ReactNode, container (Layout), DialogContext, layerTextReset,
8-
* layerStructureReset, modalOutlet, interactionModality, chainEventHandlers
8+
* layerStructureReset, modalOutlet, interactionModality, chainEventHandlers, holdEntranceInput
99
* @output Exports Dialog component, DialogProps, DialogVariant, DialogPurpose types
1010
* @position Core implementation; consumed by index.ts, tested by Dialog.test.tsx
1111
*
@@ -27,6 +27,7 @@
2727
* SYNC: When modified, update these files to stay in sync:
2828
* - /packages/core/src/Dialog/Dialog.doc.mjs (props table, features, implementation notes)
2929
* - /packages/core/src/Dialog/Dialog.test.tsx (tests for new/changed behavior)
30+
* - /packages/core/src/Dialog/__tests__/DialogTouchEntrance.interaction.browser.spec.ts (the touch entrance hold)
3031
* - /packages/core/src/Dialog/index.ts (exports if types change)
3132
* - /apps/storybook/stories/Dialog.stories.tsx (storybook stories)
3233
* - /packages/cli/assets/templates/blocks/components/Dialog/ (showcase blocks)
@@ -51,6 +52,7 @@ import {layerStructureReset} from '../Layer/layerStructureReset.stylex';
5152
import {LayerContentBoundary} from '../Layer/layerScopedContext';
5253
import {layerClickBoundary} from '../Layer/layerClickBoundary';
5354
import {LayerDepthProvider} from '../Layer/LayerDepthContext';
55+
import {holdEntranceInput} from '../Layer/holdEntranceInput';
5456
import {useLayerDismissal} from '../Layer/useLayerDismissal';
5557
import {useBackdropPress} from '../Layer/useBackdropPress';
5658
import {useModalOutlet} from '../Layer/modalOutlet';
@@ -642,6 +644,11 @@ export function Dialog({
642644
focusForLastInput(autofocusTarget);
643645
}
644646
}
647+
// Under a coarse primary pointer, a tap or a drag during the entrance
648+
// reaches nothing. Keys and assistive technology stay live. The hold
649+
// ends with the entrance, or with this effect's cleanup on a close or
650+
// unmount.
651+
return holdEntranceInput(dialog) ?? undefined;
645652
} else {
646653
if (dialog.open) {
647654
dialog.close();

0 commit comments

Comments
 (0)