@astryxdesign/core 0.6.1 → 0.6.2-canary.2b2113d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/dist/BottomSheet/BottomSheet.d.ts +1 -1
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheet.js +3 -1
- package/dist/BottomSheet/BottomSheetPanel.d.ts +7 -5
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
- package/dist/BottomSheet/BottomSheetPanel.js +56 -19
- package/dist/DateRangeInput/DateRangeInput.d.ts +3 -0
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +16 -9
- package/dist/Dialog/DialogHeader.d.ts +1 -1
- package/dist/Dialog/DialogHeader.d.ts.map +1 -1
- package/dist/Dialog/DialogHeader.js +10 -7
- package/dist/FileInput/FileInput.d.ts.map +1 -1
- package/dist/FileInput/FileInput.js +9 -3
- package/dist/Markdown/Markdown.d.ts +10 -2
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.js +58 -14
- package/dist/Markdown/index.d.ts +1 -1
- package/dist/Markdown/index.d.ts.map +1 -1
- package/dist/Markdown/parser.d.ts +126 -12
- package/dist/Markdown/parser.d.ts.map +1 -1
- package/dist/Markdown/parser.js +369 -34
- package/dist/Markdown/utils.d.ts +1 -1
- package/dist/Markdown/utils.d.ts.map +1 -1
- package/dist/Slider/Slider.d.ts.map +1 -1
- package/dist/Slider/Slider.js +5 -2
- package/dist/Spinner/Spinner.d.ts +1 -1
- package/dist/Spinner/Spinner.d.ts.map +1 -1
- package/dist/Spinner/Spinner.js +23 -15
- package/dist/astryx.css +5 -2
- package/dist/hooks/scrollKeyboardDelegation.d.ts +3 -0
- package/dist/hooks/scrollKeyboardDelegation.d.ts.map +1 -0
- package/dist/hooks/scrollKeyboardDelegation.js +146 -0
- package/dist/hooks/useScrollableArea.d.ts +6 -2
- package/dist/hooks/useScrollableArea.d.ts.map +1 -1
- package/dist/hooks/useScrollableArea.js +17 -5
- package/locales/en.json +16 -0
- package/locales/pseudo.json +12 -0
- package/package.json +7 -5
- package/scripts/agent-doc-state.mjs +1 -1
- package/src/BottomSheet/BottomSheet.doc.mjs +8 -1
- package/src/BottomSheet/BottomSheet.spec.md +46 -20
- package/src/BottomSheet/BottomSheet.test.tsx +6 -3
- package/src/BottomSheet/BottomSheet.tsx +3 -1
- package/src/BottomSheet/BottomSheetKeyboard.test.tsx +195 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +11 -1
- package/src/BottomSheet/BottomSheetPanel.tsx +49 -16
- package/src/BottomSheet/__tests__/BottomSheetKeyboard.a11y.browser.spec.ts +344 -0
- package/src/DateRangeInput/DateRangeInput.doc.mjs +35 -7
- package/src/DateRangeInput/DateRangeInput.spec.md +203 -0
- package/src/DateRangeInput/DateRangeInput.test.tsx +100 -4
- package/src/DateRangeInput/DateRangeInput.tsx +29 -20
- package/src/Dialog/Dialog.doc.mjs +3 -0
- package/src/Dialog/Dialog.spec.md +1 -1
- package/src/Dialog/DialogHeader.doc.mjs +38 -0
- package/src/Dialog/DialogHeader.test.tsx +49 -0
- package/src/Dialog/DialogHeader.tsx +23 -4
- package/src/Dialog/modules/DialogHeader.spec.md +152 -0
- package/src/FileInput/FileInput.doc.mjs +2 -0
- package/src/FileInput/FileInput.spec.md +199 -0
- package/src/FileInput/FileInput.test.tsx +14 -0
- package/src/FileInput/FileInput.tsx +13 -3
- package/src/Markdown/Markdown.doc.mjs +167 -42
- package/src/Markdown/Markdown.public.test.ts +157 -0
- package/src/Markdown/Markdown.spec.md +149 -70
- package/src/Markdown/Markdown.test.tsx +107 -3
- package/src/Markdown/Markdown.tsx +116 -35
- package/src/Markdown/incremental.test.ts +175 -7
- package/src/Markdown/index.ts +6 -0
- package/src/Markdown/parser.perf.test.ts +3 -1
- package/src/Markdown/parser.test.ts +122 -0
- package/src/Markdown/parser.ts +609 -81
- package/src/Markdown/utils.ts +6 -0
- package/src/ScrollableArea/modules/useScrollableArea.spec.md +50 -22
- package/src/Slider/Slider.doc.mjs +16 -0
- package/src/Slider/Slider.spec.md +61 -47
- package/src/Slider/Slider.test.tsx +18 -0
- package/src/Slider/Slider.tsx +12 -6
- package/src/Spinner/Spinner.doc.mjs +6 -3
- package/src/Spinner/Spinner.test.tsx +37 -0
- package/src/Spinner/Spinner.tsx +31 -14
- package/src/hooks/scrollKeyboardDelegation.test.ts +155 -0
- package/src/hooks/scrollKeyboardDelegation.ts +233 -0
- package/src/hooks/useScrollableArea.doc.mjs +15 -3
- package/src/hooks/useScrollableArea.test.tsx +59 -1
- package/src/hooks/useScrollableArea.ts +34 -10
- package/src/theme/derivedVarRegistry.test.ts +6 -4
|
@@ -14,6 +14,9 @@ verified_by:
|
|
|
14
14
|
[
|
|
15
15
|
packages/core/src/BottomSheet/BottomSheet.test.tsx,
|
|
16
16
|
packages/core/src/BottomSheet/BottomSheetPanel.test.tsx,
|
|
17
|
+
packages/core/src/BottomSheet/BottomSheetKeyboard.test.tsx,
|
|
18
|
+
packages/core/src/BottomSheet/__tests__/BottomSheetKeyboard.a11y.browser.spec.ts,
|
|
19
|
+
apps/storybook/stories/BottomSheet.stories.tsx,
|
|
17
20
|
scripts/check-knowledge.mjs,
|
|
18
21
|
]
|
|
19
22
|
modules: []
|
|
@@ -22,7 +25,7 @@ design_specs: []
|
|
|
22
25
|
architecture:
|
|
23
26
|
[architecture:component-theming-surface, architecture:layer-runtime]
|
|
24
27
|
contributing: []
|
|
25
|
-
system_specs: []
|
|
28
|
+
system_specs: [spec:AST-025]
|
|
26
29
|
---
|
|
27
30
|
|
|
28
31
|
# BottomSheet component contract
|
|
@@ -30,14 +33,15 @@ system_specs: []
|
|
|
30
33
|
## Intent
|
|
31
34
|
|
|
32
35
|
BottomSheet presents caller-provided content in a panel that rises from the
|
|
33
|
-
bottom edge. This draft records current consumer anatomy
|
|
34
|
-
|
|
36
|
+
bottom edge. This draft records current consumer anatomy, keyboard-reachable
|
|
37
|
+
scrolling, and theming reachability without changing public API.
|
|
35
38
|
|
|
36
39
|
## Compatibility and migration
|
|
37
40
|
|
|
38
41
|
- Released default preserved: `yes`
|
|
39
|
-
- Compatibility class: additive
|
|
40
|
-
targets, and
|
|
42
|
+
- Compatibility class: additive internal content box and shared scroll behavior;
|
|
43
|
+
public props, defaults, targets, and caller child ordering inside the content box
|
|
44
|
+
remain unchanged
|
|
41
45
|
- Controlled/uncontrolled behavior: unchanged
|
|
42
46
|
- Migration decision: none
|
|
43
47
|
|
|
@@ -48,7 +52,8 @@ Consumer migration instructions belong in consumer docs and release notes.
|
|
|
48
52
|
**Owns**
|
|
49
53
|
|
|
50
54
|
- The visual Sheet panel and its current `bottom-sheet` target.
|
|
51
|
-
- The scrolling Content area
|
|
55
|
+
- The scrolling Content area, its shared viewport/content-box integration, and
|
|
56
|
+
automatic keyboard-path selection.
|
|
52
57
|
- Standalone sheet presentation, including its optional native-dialog Scrim.
|
|
53
58
|
|
|
54
59
|
**Does not own / non-goals**
|
|
@@ -67,10 +72,11 @@ in `BottomSheet.doc.mjs`.
|
|
|
67
72
|
|
|
68
73
|
## Behavioral and layout contract
|
|
69
74
|
|
|
70
|
-
| ID | Candidate invariant
|
|
71
|
-
| --- |
|
|
72
|
-
| FR1 | The current presented sheet contains one Sheet panel, one scrolling Content area, and one decorative Handle; a Scrim is present only in scrim-backed presentation.
|
|
73
|
-
| FR2 | The Sheet panel carries `bottom-sheet`; Content area, Handle, and Scrim carry no BottomSheet public target.
|
|
75
|
+
| ID | Candidate invariant | Basis | Draft review state |
|
|
76
|
+
| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | -------------------------------------------------- |
|
|
77
|
+
| FR1 | The current presented sheet contains one Sheet panel, one scrolling Content area, and one decorative Handle; a Scrim is present only in scrim-backed presentation. | Current source, docs, and tests | Verified current behavior; no new behavior decided |
|
|
78
|
+
| FR2 | The Sheet panel carries `bottom-sheet`; Content area, Handle, and Scrim carry no BottomSheet public target. | Current source, docs, and tests | Verified current behavior; no target change |
|
|
79
|
+
| FR3 | Content renders in one real observed content box. Effective overflow, containment, and keyboard access come from `useScrollableArea`; the named overflowing body delegates forward Tab entry to a safe first sequential native link/button. | `spec:AST-025`; issue #5207; tests | Focus-time prototype for owner review |
|
|
74
80
|
|
|
75
81
|
### Allowed variation
|
|
76
82
|
|
|
@@ -96,8 +102,14 @@ in `BottomSheet.doc.mjs`.
|
|
|
96
102
|
|
|
97
103
|
## Accessibility contract
|
|
98
104
|
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
- **AR1 — Keyboard scroll path.** The named body is a tab stop while effectively
|
|
106
|
+
overflowing. On forward Tab entry, the shared hook may delegate to the first
|
|
107
|
+
sequential native link/button outside navigation-key-owning surfaces. It keeps
|
|
108
|
+
the body stop for excluded content and skips the body on reverse traversal
|
|
109
|
+
from the delegated first child.
|
|
110
|
+
- **AR2 — Focus continuity.** Content, overflow, or eligibility changes MUST NOT
|
|
111
|
+
move focus. Pointer/programmatic body focus never delegates. A focused body
|
|
112
|
+
losing overflow remains programmatically focusable.
|
|
101
113
|
|
|
102
114
|
## Design relationships
|
|
103
115
|
|
|
@@ -143,18 +155,20 @@ a decision that they must remain unthemeable.
|
|
|
143
155
|
mapping, and factual `none` dispositions.
|
|
144
156
|
- `architecture:layer-runtime` owns the current native-dialog host distinction
|
|
145
157
|
and records that sheets retain local scrim and swipe behavior.
|
|
158
|
+
- `spec:AST-025` owns effective scroll measurement, overflow and containment,
|
|
159
|
+
automatic keyboard-owner selection, and focus continuity.
|
|
146
160
|
- `family:overlay-dismissal` owns shared Escape and platform-close ordering and
|
|
147
161
|
records BottomSheet's current local-only adoption gap. This anatomy backfill
|
|
148
162
|
does not migrate that runtime behavior.
|
|
149
163
|
|
|
150
164
|
## Verification map
|
|
151
165
|
|
|
152
|
-
| Contract | Verification
|
|
153
|
-
| ------------------- |
|
|
154
|
-
| FR1 | `BottomSheet.test.tsx` render, content, Handle, and scrim behavior suites
|
|
155
|
-
| FR2 | Panel target assertion, source inspection, and theming target inventories
|
|
156
|
-
| Layout evidence
|
|
157
|
-
| Theming anatomy map | `scripts/check-knowledge.mjs`
|
|
166
|
+
| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
|
|
167
|
+
| ------------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------- | --------------------------------- |
|
|
168
|
+
| FR1 | `BottomSheet.test.tsx` render, content, Handle, and scrim behavior suites | Modal, non-modal, and switcher presentations | Removing a documented part fails existing content, structure, or dismissal assertions. | `audit:BottomSheet/anatomy` |
|
|
169
|
+
| FR2 | Panel target assertion, source inspection, and theming target inventories | Sheet panel, Content area, Handle, and Scrim | Removing the panel target or documenting an unshipped child target fails evidence or inventory. | `audit:BottomSheet/theming` |
|
|
170
|
+
| FR3, AR1–AR2 | `BottomSheetKeyboard.test.tsx`; `BottomSheetKeyboard.a11y.browser.spec.ts`; open Storybook stories | fitting/overflow, plain text, usable/unusable/dynamic descendants, focus | Missing/duplicate keyboard access, stale ownership, focus movement, or broken content-box layout fails. | `audit:BottomSheet/accessibility` | | Layout evidence | `BottomSheetPanel.test.tsx` | Floating Handle and scrolling Content area | Reordering or merging the stable parts fails existing panel structure and style assertions. | `audit:BottomSheet/anatomy` |
|
|
171
|
+
| Theming anatomy map | `scripts/check-knowledge.mjs` | Canonical anatomy and current target inventory | Missing, extra, prefixed, stale, or multiply assigned mappings fail repository validation. | `audit:BottomSheet/theming` |
|
|
158
172
|
|
|
159
173
|
Existing tests directly assert the Sheet panel target, Content area placement,
|
|
160
174
|
Handle structure, and scrim behavior. Source and public target metadata confirm
|
|
@@ -162,8 +176,20 @@ that the other three parts have no public target.
|
|
|
162
176
|
|
|
163
177
|
## Decision log
|
|
164
178
|
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
### DEC-1 — BottomSheet adopts automatic shared keyboard ownership
|
|
180
|
+
|
|
181
|
+
**Reference:** `component:BottomSheet/DEC-1`
|
|
182
|
+
**Decider:** cixzhang, 2026-09-13
|
|
183
|
+
|
|
184
|
+
BottomSheet supplies its existing label to
|
|
185
|
+
`keyboardAccess.owner="contentOrViewport"`. The shared hook keeps the overflowing
|
|
186
|
+
body named and tabbable, delegating forward keyboard entry to a safe first native
|
|
187
|
+
link/button. Pointer/programmatic focus and excluded content keep the body path. BottomSheet retains `stickyContainment="always"` because the
|
|
188
|
+
body deliberately remains the sheet-local Sticky boundary.
|
|
189
|
+
|
|
190
|
+
A real flow-root content box supplies the hook's observation seam while preserving
|
|
191
|
+
representative margin, float, percentage-height, flex/grid-child, and hug-height
|
|
192
|
+
behavior.
|
|
167
193
|
|
|
168
194
|
## Open questions
|
|
169
195
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file BottomSheet.test.tsx
|
|
5
5
|
* @input Uses vitest, @testing-library/react, BottomSheet component
|
|
6
|
-
* @output Unit tests for BottomSheet
|
|
6
|
+
* @output Unit tests for BottomSheet behavior and observed content anatomy
|
|
7
7
|
* @position Core testing; validates BottomSheet.tsx implementation
|
|
8
8
|
*
|
|
9
9
|
* SYNC: When BottomSheet.tsx changes, update tests to match new behavior
|
|
@@ -290,7 +290,7 @@ describe('BottomSheet', () => {
|
|
|
290
290
|
expect(onClick).toHaveBeenCalledTimes(1);
|
|
291
291
|
});
|
|
292
292
|
|
|
293
|
-
it('keeps consumer content
|
|
293
|
+
it('keeps consumer content first and last inside the observed content box', () => {
|
|
294
294
|
render(
|
|
295
295
|
<BottomSheet isOpen onOpenChange={() => {}} label="Filters">
|
|
296
296
|
<div data-testid="consumer-content">Sheet content</div>
|
|
@@ -300,7 +300,10 @@ describe('BottomSheet', () => {
|
|
|
300
300
|
const consumer = screen.getByTestId('consumer-content');
|
|
301
301
|
|
|
302
302
|
expect(body.children).toHaveLength(1);
|
|
303
|
-
|
|
303
|
+
const content = body.lastElementChild;
|
|
304
|
+
expect(content).toHaveAttribute('data-scroll-content');
|
|
305
|
+
expect(content?.lastElementChild).toBe(consumer);
|
|
306
|
+
expect(consumer.matches(':first-child')).toBe(true);
|
|
304
307
|
expect(consumer.matches(':last-child')).toBe(true);
|
|
305
308
|
});
|
|
306
309
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file BottomSheet.tsx
|
|
7
|
-
* @input Uses React, StyleX, core hooks/utils, BottomSheetPanel, BottomSheetSwitcherContext
|
|
7
|
+
* @input Uses React, StyleX, core hooks/utils, named BottomSheetPanel, BottomSheetSwitcherContext
|
|
8
8
|
* @output Exports BottomSheet component and BottomSheetProps
|
|
9
9
|
* @position Public BottomSheet router plus private standalone/switcher hosts
|
|
10
10
|
*
|
|
@@ -379,6 +379,7 @@ function StandaloneBottomSheet({
|
|
|
379
379
|
ref={ref}
|
|
380
380
|
state={panelState}
|
|
381
381
|
height={height}
|
|
382
|
+
label={label}
|
|
382
383
|
snapPoints={snapPoints}
|
|
383
384
|
isSwipeDismissAllowed={purpose === 'info'}
|
|
384
385
|
isPageScrollLocked={shouldPresent && hasScrim}
|
|
@@ -537,6 +538,7 @@ function SwitcherBottomSheetItem({
|
|
|
537
538
|
ref={ref}
|
|
538
539
|
state={panelState}
|
|
539
540
|
height={height}
|
|
541
|
+
label={label}
|
|
540
542
|
snapPoints={snapPoints}
|
|
541
543
|
isSwipeDismissAllowed={purpose === 'info'}
|
|
542
544
|
isPageScrollLocked={hasScrim}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file BottomSheetKeyboard.test.tsx
|
|
5
|
+
* @input BottomSheetPanel, real shared scroll behavior, and explicit DOM geometry
|
|
6
|
+
* @output Regression coverage for viewport access, entry-time eligibility, and focus continuity
|
|
7
|
+
* @position BottomSheet integration tests; browser stories verify native key scrolling
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import {act, fireEvent, render, screen, waitFor} from '@testing-library/react';
|
|
11
|
+
import {useState, type ReactNode} from 'react';
|
|
12
|
+
import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
|
|
13
|
+
import {BottomSheetPanel} from './BottomSheetPanel';
|
|
14
|
+
|
|
15
|
+
function Fixture({children}: {children: ReactNode}) {
|
|
16
|
+
return (
|
|
17
|
+
<BottomSheetPanel
|
|
18
|
+
label="Reading details"
|
|
19
|
+
state={{kind: 'open', entering: false}}
|
|
20
|
+
height="capped"
|
|
21
|
+
onDismiss={() => {}}
|
|
22
|
+
onScrimOpacity={() => {}}>
|
|
23
|
+
{children}
|
|
24
|
+
</BottomSheetPanel>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function body() {
|
|
29
|
+
return screen.getByRole('group', {name: 'Reading details'});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function measure(scrollHeight: number, scrollWidth = 300) {
|
|
33
|
+
const viewport = body();
|
|
34
|
+
// jsdom does not resolve the shared hook's dynamic StyleX CSS variable.
|
|
35
|
+
viewport.style.overflowY = 'auto';
|
|
36
|
+
viewport.style.overflowX = 'auto';
|
|
37
|
+
for (const [key, value] of Object.entries({
|
|
38
|
+
clientHeight: 100,
|
|
39
|
+
clientWidth: 300,
|
|
40
|
+
scrollHeight,
|
|
41
|
+
scrollWidth,
|
|
42
|
+
})) {
|
|
43
|
+
Object.defineProperty(viewport, key, {configurable: true, value});
|
|
44
|
+
}
|
|
45
|
+
fireEvent(window, new Event('resize'));
|
|
46
|
+
await waitFor(() => {
|
|
47
|
+
expect(viewport.dataset.scrollableBlock === 'true').toBe(
|
|
48
|
+
scrollHeight > 101,
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
beforeEach(() => {
|
|
54
|
+
// jsdom has no layout. Visibility-specific cases still use real computed
|
|
55
|
+
// style/hidden/inert checks; native layout is covered in Storybook.
|
|
56
|
+
vi.spyOn(HTMLElement.prototype, 'getClientRects').mockReturnValue([
|
|
57
|
+
new DOMRect(0, 0, 20, 20),
|
|
58
|
+
] as unknown as DOMRectList);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
afterEach(() => {
|
|
62
|
+
vi.restoreAllMocks();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('BottomSheet keyboard scrolling', () => {
|
|
66
|
+
it('adds a named body tab stop only while text-only content overflows', async () => {
|
|
67
|
+
render(<Fixture>Reading details body</Fixture>);
|
|
68
|
+
await measure(100);
|
|
69
|
+
expect(body()).not.toHaveAttribute('tabindex');
|
|
70
|
+
await measure(300);
|
|
71
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
72
|
+
expect(body()).toHaveStyle({overscrollBehaviorY: 'contain'});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('preserves current body focus when overflow disappears', async () => {
|
|
76
|
+
render(<Fixture>Reading details body</Fixture>);
|
|
77
|
+
await measure(300);
|
|
78
|
+
act(() => body().focus());
|
|
79
|
+
await measure(100);
|
|
80
|
+
expect(body()).toHaveFocus();
|
|
81
|
+
expect(body()).toHaveAttribute('tabindex', '-1');
|
|
82
|
+
expect(body()).toHaveStyle({overscrollBehaviorY: 'auto'});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('retains keyboard access to content that overflows only horizontally', async () => {
|
|
86
|
+
render(<Fixture>Wide reading content</Fixture>);
|
|
87
|
+
await measure(100, 600);
|
|
88
|
+
await waitFor(() =>
|
|
89
|
+
expect(body()).toHaveAttribute('data-scrollable-inline', 'true'),
|
|
90
|
+
);
|
|
91
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('keeps the named viewport available alongside focusable content', async () => {
|
|
95
|
+
render(
|
|
96
|
+
<Fixture>
|
|
97
|
+
<button type="button">Continue reading</button>
|
|
98
|
+
</Fixture>,
|
|
99
|
+
);
|
|
100
|
+
await measure(300);
|
|
101
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
102
|
+
act(() => screen.getByRole('button').focus());
|
|
103
|
+
expect(screen.getByRole('button')).toHaveFocus();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it.each([
|
|
107
|
+
<button type="button" key="disabled" disabled>
|
|
108
|
+
Unavailable
|
|
109
|
+
</button>,
|
|
110
|
+
<button type="button" key="hidden" hidden>
|
|
111
|
+
Hidden
|
|
112
|
+
</button>,
|
|
113
|
+
<button type="button" key="negative" tabIndex={-2}>
|
|
114
|
+
Programmatic only
|
|
115
|
+
</button>,
|
|
116
|
+
<button type="button" key="visibility" style={{visibility: 'hidden'}}>
|
|
117
|
+
Hidden by CSS
|
|
118
|
+
</button>,
|
|
119
|
+
<div key="inert" inert>
|
|
120
|
+
<button type="button">Inert</button>
|
|
121
|
+
</div>,
|
|
122
|
+
<fieldset key="fieldset" disabled>
|
|
123
|
+
<button type="button">Disabled by fieldset</button>
|
|
124
|
+
</fieldset>,
|
|
125
|
+
])(
|
|
126
|
+
'ignores a descendant that cannot supply sequential keyboard access (%#)',
|
|
127
|
+
async child => {
|
|
128
|
+
render(<Fixture>{child}</Fixture>);
|
|
129
|
+
await measure(300);
|
|
130
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
131
|
+
},
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
it('does not move focus when a nested child changes', async () => {
|
|
135
|
+
let setHasControl: (value: boolean) => void = () => {};
|
|
136
|
+
function AsyncContent() {
|
|
137
|
+
const [hasControl, update] = useState(false);
|
|
138
|
+
setHasControl = update;
|
|
139
|
+
return hasControl ? (
|
|
140
|
+
<button type="button">Loaded action</button>
|
|
141
|
+
) : (
|
|
142
|
+
<p>Loading text</p>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
render(
|
|
146
|
+
<Fixture>
|
|
147
|
+
<AsyncContent />
|
|
148
|
+
</Fixture>,
|
|
149
|
+
);
|
|
150
|
+
await measure(300);
|
|
151
|
+
act(() => body().focus());
|
|
152
|
+
act(() => setHasControl(true));
|
|
153
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
154
|
+
expect(body()).toHaveFocus();
|
|
155
|
+
act(() => setHasControl(false));
|
|
156
|
+
await waitFor(() => expect(body()).toHaveAttribute('tabindex', '0'));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('retains the viewport when an existing descendant becomes disabled', async () => {
|
|
160
|
+
render(
|
|
161
|
+
<Fixture>
|
|
162
|
+
<button type="button">Continue reading</button>
|
|
163
|
+
</Fixture>,
|
|
164
|
+
);
|
|
165
|
+
await measure(300);
|
|
166
|
+
screen.getByRole('button').setAttribute('disabled', '');
|
|
167
|
+
await waitFor(() => expect(body()).toHaveAttribute('tabindex', '0'));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it.each(['content', 'ancestor'])(
|
|
171
|
+
'retains the viewport when %s data attributes change child visibility',
|
|
172
|
+
async target => {
|
|
173
|
+
const {container} = render(
|
|
174
|
+
<Fixture>
|
|
175
|
+
<style>
|
|
176
|
+
{'[data-actions="hidden"] button { visibility: hidden; }'}
|
|
177
|
+
</style>
|
|
178
|
+
<div data-testid="conditional-content">
|
|
179
|
+
<button type="button">Conditional action</button>
|
|
180
|
+
</div>
|
|
181
|
+
</Fixture>,
|
|
182
|
+
);
|
|
183
|
+
await measure(300);
|
|
184
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
185
|
+
const owner =
|
|
186
|
+
target === 'content'
|
|
187
|
+
? screen.getByTestId('conditional-content')
|
|
188
|
+
: container;
|
|
189
|
+
owner.setAttribute('data-actions', 'hidden');
|
|
190
|
+
await waitFor(() => expect(body()).toHaveAttribute('tabindex', '0'));
|
|
191
|
+
owner.removeAttribute('data-actions');
|
|
192
|
+
expect(body()).toHaveAttribute('tabindex', '0');
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
});
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* @file BottomSheetPanel.test.tsx
|
|
5
5
|
* @input Uses vitest, Testing Library, BottomSheetPanel
|
|
6
|
-
* @output Tests the shared sheet surface motion
|
|
6
|
+
* @output Tests the shared sheet surface motion and keyboard scroll contracts
|
|
7
7
|
* @position Internal presentation tests shared by standalone and switcher modes
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -50,6 +50,7 @@ function renderPanel(
|
|
|
50
50
|
) {
|
|
51
51
|
return render(
|
|
52
52
|
<BottomSheetPanel
|
|
53
|
+
label="Sheet details"
|
|
53
54
|
state={state}
|
|
54
55
|
height="hug"
|
|
55
56
|
style={panelTransitionStyle}
|
|
@@ -92,6 +93,7 @@ describe('BottomSheetPanel', () => {
|
|
|
92
93
|
const onMotionComplete = vi.fn();
|
|
93
94
|
const {rerender} = render(
|
|
94
95
|
<BottomSheetPanel
|
|
96
|
+
label="Sheet details"
|
|
95
97
|
state={{kind: 'retained', motion: 'covered', alignmentOffset: 0}}
|
|
96
98
|
height="hug"
|
|
97
99
|
style={panelTransitionStyle}
|
|
@@ -104,6 +106,7 @@ describe('BottomSheetPanel', () => {
|
|
|
104
106
|
|
|
105
107
|
rerender(
|
|
106
108
|
<BottomSheetPanel
|
|
109
|
+
label="Sheet details"
|
|
107
110
|
state={{kind: 'open', entering: true}}
|
|
108
111
|
height="hug"
|
|
109
112
|
style={panelTransitionStyle}
|
|
@@ -139,6 +142,7 @@ describe('BottomSheetPanel', () => {
|
|
|
139
142
|
|
|
140
143
|
rerender(
|
|
141
144
|
<BottomSheetPanel
|
|
145
|
+
label="Sheet details"
|
|
142
146
|
state={{kind: 'exiting'}}
|
|
143
147
|
height="hug"
|
|
144
148
|
style={panelTransitionStyle}
|
|
@@ -166,6 +170,7 @@ describe('BottomSheetPanel', () => {
|
|
|
166
170
|
const onMotionComplete = vi.fn();
|
|
167
171
|
render(
|
|
168
172
|
<BottomSheetPanel
|
|
173
|
+
label="Sheet details"
|
|
169
174
|
state={{kind: 'open', entering: true}}
|
|
170
175
|
height="hug"
|
|
171
176
|
onDismiss={() => {}}
|
|
@@ -184,6 +189,7 @@ describe('BottomSheetPanel', () => {
|
|
|
184
189
|
const onMotionComplete = vi.fn();
|
|
185
190
|
render(
|
|
186
191
|
<BottomSheetPanel
|
|
192
|
+
label="Sheet details"
|
|
187
193
|
state={{kind: 'open', entering: true}}
|
|
188
194
|
height="hug"
|
|
189
195
|
style={{
|
|
@@ -211,6 +217,7 @@ describe('BottomSheetPanel', () => {
|
|
|
211
217
|
const panelRef = vi.fn();
|
|
212
218
|
const {rerender, unmount} = render(
|
|
213
219
|
<BottomSheetPanel
|
|
220
|
+
label="Sheet details"
|
|
214
221
|
ref={panelRef}
|
|
215
222
|
state={{kind: 'open', entering: false}}
|
|
216
223
|
height="hug"
|
|
@@ -223,6 +230,7 @@ describe('BottomSheetPanel', () => {
|
|
|
223
230
|
expect(panelRef).toHaveBeenCalledTimes(1);
|
|
224
231
|
rerender(
|
|
225
232
|
<BottomSheetPanel
|
|
233
|
+
label="Sheet details"
|
|
226
234
|
ref={panelRef}
|
|
227
235
|
state={{kind: 'open', entering: false}}
|
|
228
236
|
height="hug"
|
|
@@ -361,6 +369,7 @@ describe('BottomSheetPanel', () => {
|
|
|
361
369
|
|
|
362
370
|
const {container: closing} = render(
|
|
363
371
|
<BottomSheetPanel
|
|
372
|
+
label="Sheet details"
|
|
364
373
|
state={{kind: 'exiting'}}
|
|
365
374
|
height="hug"
|
|
366
375
|
onDismiss={() => {}}
|
|
@@ -379,6 +388,7 @@ describe('BottomSheetPanel', () => {
|
|
|
379
388
|
|
|
380
389
|
const {container: resting} = render(
|
|
381
390
|
<BottomSheetPanel
|
|
391
|
+
label="Sheet details"
|
|
382
392
|
state={{kind: 'open', entering: false}}
|
|
383
393
|
height="hug"
|
|
384
394
|
onDismiss={() => {}}
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file BottomSheetPanel.tsx
|
|
7
|
-
* @input Uses React, StyleX, theme tokens,
|
|
8
|
-
* @output Internal BottomSheetPanel
|
|
7
|
+
* @input Uses React, StyleX, theme tokens, sheet gestures, shared scroll behavior, and the host label
|
|
8
|
+
* @output Internal BottomSheetPanel with a keyboard-reachable scrolling body and motion-state types
|
|
9
9
|
* @position Shared presentation layer for standalone and switcher BottomSheets
|
|
10
10
|
*
|
|
11
11
|
* This component owns everything intrinsic to a sheet surface: height budgets,
|
|
12
12
|
* drag and snap gestures, the handle and scrolling body, motion styles, and
|
|
13
|
-
* transition completion. It
|
|
14
|
-
* state,
|
|
13
|
+
* transition completion. It owns the body's keyboard access; dialog focus
|
|
14
|
+
* entry/return, inert state, and switcher registration belong to the host.
|
|
15
15
|
*
|
|
16
16
|
* SYNC: When modified, update these files to stay in sync:
|
|
17
17
|
* - /packages/core/src/BottomSheet/BottomSheet.tsx
|
|
@@ -33,17 +33,20 @@ import {
|
|
|
33
33
|
import * as stylex from '@stylexjs/stylex';
|
|
34
34
|
import type {BaseProps} from '../BaseProps';
|
|
35
35
|
import {useDevWarning} from '../hooks';
|
|
36
|
+
import {useScrollableArea} from '../hooks/useScrollableArea';
|
|
36
37
|
import {
|
|
37
38
|
borderVars,
|
|
38
39
|
colorVars,
|
|
39
40
|
durationVars,
|
|
40
41
|
easeVars,
|
|
42
|
+
focusVars,
|
|
41
43
|
radiusVars,
|
|
42
44
|
shadowVars,
|
|
43
45
|
sizeVars,
|
|
44
46
|
spacingVars,
|
|
45
47
|
} from '../theme/tokens.stylex';
|
|
46
48
|
import {mergeProps, themeProps} from '../utils';
|
|
49
|
+
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
|
|
47
50
|
import {overlayPaddingReset} from '../Layout/padding.stylex';
|
|
48
51
|
import {
|
|
49
52
|
isValidSnapPoint,
|
|
@@ -211,9 +214,11 @@ const styles = stylex.create({
|
|
|
211
214
|
flexGrow: 1,
|
|
212
215
|
minHeight: 0,
|
|
213
216
|
boxSizing: 'border-box',
|
|
214
|
-
overflowY: 'auto',
|
|
215
|
-
overscrollBehavior: 'none',
|
|
216
217
|
touchAction: 'pan-y',
|
|
218
|
+
outlineOffset: {
|
|
219
|
+
default: 0,
|
|
220
|
+
':focus-visible': `calc(-1 * ${focusVars['--focus-outline-width']})`,
|
|
221
|
+
},
|
|
217
222
|
// The scrolling area paints the surface itself, covering the sheet's whole
|
|
218
223
|
// inner box. Without it the sheet's edge is not uniform: a theme that packs
|
|
219
224
|
// an inset ring into --shadow-high (the bundled themes all add one in dark
|
|
@@ -229,6 +234,15 @@ const styles = stylex.create({
|
|
|
229
234
|
// space a content wrapper's own top padding already provides.
|
|
230
235
|
paddingBlockEnd: 0,
|
|
231
236
|
},
|
|
237
|
+
content: {
|
|
238
|
+
// Preserve the body's block formatting (including margin/float isolation)
|
|
239
|
+
// and its definite percentage-height basis. min-content lets this real
|
|
240
|
+
// observed box grow with async content beyond a fixed-height viewport.
|
|
241
|
+
display: 'flow-root',
|
|
242
|
+
boxSizing: 'border-box',
|
|
243
|
+
height: '100%',
|
|
244
|
+
minHeight: 'min-content',
|
|
245
|
+
},
|
|
232
246
|
tallKeyboardBody: {
|
|
233
247
|
scrollPaddingBlockEnd: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
|
|
234
248
|
'::after': {
|
|
@@ -265,6 +279,8 @@ interface BottomSheetPanelProps extends BaseProps<HTMLDivElement> {
|
|
|
265
279
|
ref?: React.Ref<HTMLDivElement>;
|
|
266
280
|
state: BottomSheetPanelState;
|
|
267
281
|
height: BottomSheetHeight | number | string;
|
|
282
|
+
/** Existing host name, reused for the keyboard scrolling group. */
|
|
283
|
+
label: string;
|
|
268
284
|
children: ReactNode;
|
|
269
285
|
snapPoints?: ReadonlyArray<BottomSheetSnapPoint>;
|
|
270
286
|
isSwipeDismissAllowed?: boolean;
|
|
@@ -391,6 +407,7 @@ export function BottomSheetPanel({
|
|
|
391
407
|
ref,
|
|
392
408
|
state,
|
|
393
409
|
height,
|
|
410
|
+
label,
|
|
394
411
|
children,
|
|
395
412
|
snapPoints,
|
|
396
413
|
className,
|
|
@@ -490,6 +507,17 @@ export function BottomSheetPanel({
|
|
|
490
507
|
onScrimOpacity,
|
|
491
508
|
});
|
|
492
509
|
|
|
510
|
+
const {getViewportProps, getContentProps} = useScrollableArea({
|
|
511
|
+
// The previous overflow-y:auto also computed overflow-x:auto. Keep wide
|
|
512
|
+
// content reachable instead of clipping that existing inline scroll path.
|
|
513
|
+
axis: 'both',
|
|
514
|
+
keyboardAccess: {owner: 'contentOrViewport', label},
|
|
515
|
+
overscroll: 'contain',
|
|
516
|
+
// The sheet body deliberately remains the boundary for sheet-local sticky
|
|
517
|
+
// content while fitting, as it was before shared scroll adoption.
|
|
518
|
+
stickyContainment: 'always',
|
|
519
|
+
});
|
|
520
|
+
|
|
493
521
|
const setElement = useCallback(
|
|
494
522
|
(element: HTMLDivElement | null) => {
|
|
495
523
|
sheetRef(element);
|
|
@@ -656,17 +684,22 @@ export function BottomSheetPanel({
|
|
|
656
684
|
<div {...stylex.props(styles.handlePill)} />
|
|
657
685
|
</div>
|
|
658
686
|
<div
|
|
659
|
-
{...
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
687
|
+
{...getViewportProps<HTMLDivElement>({
|
|
688
|
+
...bodyProps,
|
|
689
|
+
...mergeProps(
|
|
690
|
+
stylex.props(
|
|
691
|
+
focusOutlineStyles.focusVisible,
|
|
692
|
+
styles.body,
|
|
693
|
+
height === 'tall' && styles.tallKeyboardBody,
|
|
694
|
+
),
|
|
695
|
+
scrollPreservationInset > 0
|
|
696
|
+
? {style: {paddingBlockEnd: `${scrollPreservationInset}px`}}
|
|
697
|
+
: {},
|
|
663
698
|
),
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
{...bodyProps}>
|
|
669
|
-
{children}
|
|
699
|
+
})}>
|
|
700
|
+
<div {...getContentProps<HTMLDivElement>(stylex.props(styles.content))}>
|
|
701
|
+
{children}
|
|
702
|
+
</div>
|
|
670
703
|
</div>
|
|
671
704
|
</div>
|
|
672
705
|
);
|