@astryxdesign/core 0.7.2-canary.db3a2e7 → 0.7.2-canary.e2909cf
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/dist/AspectRatio/AspectRatio.d.ts +6 -8
- package/dist/AspectRatio/AspectRatio.d.ts.map +1 -1
- package/dist/AspectRatio/AspectRatio.js +44 -3
- package/dist/CheckboxInput/CheckboxInput.d.ts +1 -1
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +3 -1
- package/dist/CheckboxList/CheckboxListItem.d.ts +9 -1
- package/dist/CheckboxList/CheckboxListItem.d.ts.map +1 -1
- package/dist/CheckboxList/CheckboxListItem.js +4 -2
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +20 -8
- package/dist/Drawer/Drawer.d.ts +191 -0
- package/dist/Drawer/Drawer.d.ts.map +1 -0
- package/dist/Drawer/Drawer.js +382 -0
- package/dist/Drawer/DrawerHeader.d.ts +85 -0
- package/dist/Drawer/DrawerHeader.d.ts.map +1 -0
- package/dist/Drawer/DrawerHeader.js +134 -0
- package/dist/Drawer/index.d.ts +11 -0
- package/dist/Drawer/index.d.ts.map +1 -0
- package/dist/Drawer/index.js +11 -0
- package/dist/Drawer/useDrawerDialogPresence.d.ts +42 -0
- package/dist/Drawer/useDrawerDialogPresence.d.ts.map +1 -0
- package/dist/Drawer/useDrawerDialogPresence.js +236 -0
- package/dist/DropdownMenu/DropdownMenuDivider.d.ts +5 -3
- package/dist/DropdownMenu/DropdownMenuDivider.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuDivider.js +7 -3
- package/dist/EmptyState/EmptyState.d.ts.map +1 -1
- package/dist/EmptyState/EmptyState.js +4 -10
- package/dist/Item/Item.d.ts +6 -2
- package/dist/Item/Item.d.ts.map +1 -1
- package/dist/Item/Item.js +19 -4
- package/dist/Layer/useLayer.d.ts.map +1 -1
- package/dist/Layer/useLayer.js +7 -1
- package/dist/Layer/useLayerDismissal.d.ts +1 -1
- package/dist/Layer/useLayerDismissal.js +1 -1
- package/dist/Layout/container.stylex.d.ts +5 -5
- package/dist/Layout/container.stylex.js +4 -4
- package/dist/List/List.d.ts +46 -19
- package/dist/List/List.d.ts.map +1 -1
- package/dist/List/List.js +28 -10
- package/dist/List/ListContext.d.ts +8 -3
- package/dist/List/ListContext.d.ts.map +1 -1
- package/dist/List/ListContext.js +7 -2
- package/dist/List/ListItem.d.ts +13 -5
- package/dist/List/ListItem.d.ts.map +1 -1
- package/dist/List/ListItem.js +21 -8
- package/dist/List/index.d.ts +1 -1
- package/dist/List/index.d.ts.map +1 -1
- package/dist/Markdown/Markdown.d.ts.map +1 -1
- package/dist/Markdown/Markdown.js +8 -1
- package/dist/RadioList/RadioListItem.d.ts +9 -1
- package/dist/RadioList/RadioListItem.d.ts.map +1 -1
- package/dist/RadioList/RadioListItem.js +2 -0
- package/dist/TabList/TabMenu.d.ts +2 -2
- package/dist/TabList/TabMenu.d.ts.map +1 -1
- package/dist/TabList/TabMenu.js +6 -3
- package/dist/astryx.css +24 -2
- package/dist/hooks/useEntryAnimation.d.ts +2 -1
- package/dist/hooks/useEntryAnimation.d.ts.map +1 -1
- package/dist/hooks/useEntryAnimation.js +14 -12
- package/dist/hooks/useIsHydrating.d.ts +6 -0
- package/dist/hooks/useIsHydrating.d.ts.map +1 -0
- package/dist/hooks/useIsHydrating.js +30 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/theme/derivedVarRegistry.d.ts.map +1 -1
- package/dist/theme/derivedVarRegistry.js +0 -3
- package/dist/utils/plainDate.d.ts.map +1 -1
- package/dist/utils/plainDate.js +15 -9
- package/package.json +8 -3
- package/src/AspectRatio/AspectRatio.test.tsx +44 -43
- package/src/AspectRatio/AspectRatio.tsx +38 -18
- package/src/AspectRatio/__tests__/AspectRatioFitLayers.a11y.browser.spec.ts +157 -0
- package/src/CheckboxInput/CheckboxInput.test.tsx +34 -0
- package/src/CheckboxInput/CheckboxInput.tsx +3 -1
- package/src/CheckboxList/CheckboxList.test.tsx +22 -0
- package/src/CheckboxList/CheckboxListItem.doc.mjs +16 -0
- package/src/CheckboxList/CheckboxListItem.tsx +10 -0
- package/src/Dialog/Dialog.test.tsx +46 -0
- package/src/Dialog/Dialog.tsx +20 -7
- package/src/Dialog/__tests__/Dialog.a11y.known-failures.ts +0 -14
- package/src/Drawer/Drawer.doc.mjs +472 -0
- package/src/Drawer/Drawer.spec.md +357 -0
- package/src/Drawer/Drawer.test.tsx +1300 -0
- package/src/Drawer/Drawer.tsx +613 -0
- package/src/Drawer/DrawerDirection.test.tsx +127 -0
- package/src/Drawer/DrawerHeader.doc.mjs +293 -0
- package/src/Drawer/DrawerHeader.test.tsx +102 -0
- package/src/Drawer/DrawerHeader.tsx +235 -0
- package/src/Drawer/__tests__/DrawerAudit.a11y.chromium.spec.ts +401 -0
- package/src/Drawer/__tests__/DrawerHeaderAudit.a11y.chromium.spec.ts +297 -0
- package/src/Drawer/index.ts +13 -0
- package/src/Drawer/useDrawerDialogPresence.ts +284 -0
- package/src/DropdownMenu/DropdownMenu.test.tsx +21 -12
- package/src/DropdownMenu/DropdownMenuDivider.doc.mjs +2 -2
- package/src/DropdownMenu/DropdownMenuDivider.tsx +9 -5
- package/src/DropdownMenu/__tests__/Menu.a11y.chromium.spec.ts +145 -0
- package/src/DropdownMenu/__tests__/Menu.a11y.known-failures.ts +26 -0
- package/src/DropdownMenu/__tests__/Menu.a11y.renders.tsx +65 -0
- package/src/DropdownMenu/__tests__/Menu.a11y.states.ts +138 -0
- package/src/DropdownMenu/__tests__/Menu.a11y.test.tsx +136 -0
- package/src/EmptyState/EmptyState.doc.mjs +3 -2
- package/src/EmptyState/EmptyState.spec.md +189 -0
- package/src/EmptyState/EmptyState.test.tsx +74 -3
- package/src/EmptyState/EmptyState.tsx +4 -8
- package/src/Item/Item.doc.mjs +12 -8
- package/src/Item/Item.spec.md +226 -0
- package/src/Item/Item.test.tsx +61 -0
- package/src/Item/Item.tsx +40 -4
- package/src/Layer/layerViewportInset.test.ts +1 -0
- package/src/Layer/useLayer.tsx +10 -1
- package/src/Layer/useLayerDismissal.ts +1 -1
- package/src/Layout/container.stylex.ts +6 -6
- package/src/List/List.doc.mjs +14 -1
- package/src/List/List.spec.md +129 -77
- package/src/List/List.test.tsx +163 -94
- package/src/List/List.tsx +74 -18
- package/src/List/ListContext.tsx +9 -3
- package/src/List/ListItem.doc.mjs +16 -0
- package/src/List/ListItem.tsx +56 -27
- package/src/List/index.ts +1 -1
- package/src/Markdown/Markdown.tsx +14 -1
- package/src/RadioList/RadioList.test.tsx +22 -0
- package/src/RadioList/RadioListItem.doc.mjs +16 -0
- package/src/RadioList/RadioListItem.tsx +10 -1
- package/src/TabList/TabList.spec.md +57 -44
- package/src/TabList/TabList.test.tsx +67 -0
- package/src/TabList/TabMenu.doc.mjs +4 -3
- package/src/TabList/TabMenu.tsx +7 -4
- package/src/Tooltip/Tooltip.test.tsx +31 -0
- package/src/TreeList/TreeList.spec.md +29 -17
- package/src/hooks/useEntryAnimation.doc.mjs +4 -4
- package/src/hooks/useEntryAnimation.ssr.test.tsx +143 -0
- package/src/hooks/useEntryAnimation.ts +15 -16
- package/src/hooks/useIsHydrating.test.tsx +70 -0
- package/src/hooks/useIsHydrating.ts +31 -0
- package/src/index.ts +1 -0
- package/src/reset.css +0 -29
- package/src/theme/derivedVarRegistry.test.ts +3 -3
- package/src/theme/derivedVarRegistry.ts +0 -3
- package/src/utils/plainDate.test.ts +37 -1
- package/src/utils/plainDate.ts +15 -5
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* SYNC: When modified, update these files to stay in sync:
|
|
10
10
|
* - /packages/core/src/AspectRatio/AspectRatio.doc.mjs
|
|
11
11
|
* - /packages/core/src/AspectRatio/AspectRatio.test.tsx
|
|
12
|
-
* - /packages/core/src/reset.css (AspectRatio fit baseline rules)
|
|
13
12
|
* - /apps/storybook/stories/AspectRatio.stories.tsx
|
|
14
13
|
* - /packages/cli/assets/templates/blocks/components/AspectRatio/ (showcase blocks)
|
|
15
14
|
*/
|
|
@@ -91,13 +90,12 @@ export interface AspectRatioProps extends BaseProps<HTMLDivElement> {
|
|
|
91
90
|
* (`object-fit: contain`).
|
|
92
91
|
* - `center`: child keeps its natural size, centered in the box.
|
|
93
92
|
*
|
|
94
|
-
* `cover`/`contain` child
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* so it is not exposed on the theming surface.
|
|
93
|
+
* `cover`/`contain` size the child from the component's own styles, in
|
|
94
|
+
* the `astryx-base` cascade layer. Styles in a later layer (Tailwind
|
|
95
|
+
* utilities, `astryx-theme`), unlayered CSS, and inline styles on the
|
|
96
|
+
* child still win. When omitted, the child is left unstyled (the
|
|
97
|
+
* pre-existing contract). `fit` is structural, not visual, so it is not
|
|
98
|
+
* exposed on the theming surface.
|
|
101
99
|
*
|
|
102
100
|
* @example
|
|
103
101
|
* ```
|
|
@@ -140,15 +138,33 @@ const styles = stylex.create({
|
|
|
140
138
|
height: '100%',
|
|
141
139
|
},
|
|
142
140
|
// fit="center" centers the child at its natural size from the wrapper —
|
|
143
|
-
// no styles on the child itself.
|
|
144
|
-
// live here (StyleX has no descendant selectors); it ships as baseline
|
|
145
|
-
// rules in reset.css keyed on the `data-astryx-aspect-ratio-override`
|
|
146
|
-
// attribute the wrapper carries (see below).
|
|
141
|
+
// no styles on the child itself.
|
|
147
142
|
childCenter: {
|
|
148
143
|
display: 'flex',
|
|
149
144
|
alignItems: 'center',
|
|
150
145
|
justifyContent: 'center',
|
|
151
146
|
},
|
|
147
|
+
// `cover`/`contain` must style the child itself (`object-fit` only applies
|
|
148
|
+
// on the replaced element), and StyleX has no child selector. The
|
|
149
|
+
// `:not([stylex-hack])` pseudo-class always matches, so StyleX accepts the
|
|
150
|
+
// key and emits `.x:not([stylex-hack]) > *`, a direct-child rule in the
|
|
151
|
+
// `astryx-base` layer like every other component style.
|
|
152
|
+
childFill: {
|
|
153
|
+
':not([stylex-hack]) > *': {
|
|
154
|
+
width: '100%',
|
|
155
|
+
height: '100%',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
childCover: {
|
|
159
|
+
':not([stylex-hack]) > :is(img, video)': {
|
|
160
|
+
objectFit: 'cover',
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
childContain: {
|
|
164
|
+
':not([stylex-hack]) > :is(img, video)': {
|
|
165
|
+
objectFit: 'contain',
|
|
166
|
+
},
|
|
167
|
+
},
|
|
152
168
|
});
|
|
153
169
|
|
|
154
170
|
// The ratio compiles to a CSS variable + a class-level declaration
|
|
@@ -234,14 +250,18 @@ export function AspectRatio({
|
|
|
234
250
|
style,
|
|
235
251
|
)}
|
|
236
252
|
{...props}>
|
|
237
|
-
{/* The marker attribute carries the fit value
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
structure or on the theming surface (fit is structural, not
|
|
241
|
-
themeable). The name is namespaced to avoid collisions. */}
|
|
253
|
+
{/* The marker attribute carries the fit value. No Astryx style keys on
|
|
254
|
+
it any more, but earlier releases documented it, so product CSS may
|
|
255
|
+
still target it. */}
|
|
242
256
|
<div
|
|
243
257
|
data-astryx-aspect-ratio-override={fit}
|
|
244
|
-
{...stylex.props(
|
|
258
|
+
{...stylex.props(
|
|
259
|
+
styles.child,
|
|
260
|
+
fit === 'center' && styles.childCenter,
|
|
261
|
+
(fit === 'cover' || fit === 'contain') && styles.childFill,
|
|
262
|
+
fit === 'cover' && styles.childCover,
|
|
263
|
+
fit === 'contain' && styles.childContain,
|
|
264
|
+
)}>
|
|
245
265
|
{children}
|
|
246
266
|
</div>
|
|
247
267
|
</div>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file AspectRatioFitLayers.a11y.browser.spec.ts
|
|
5
|
+
* @input The built FitModes story (its rendered markup and compiled CSS) and
|
|
6
|
+
* Tailwind's preflight.css
|
|
7
|
+
* @output Browser evidence that `fit` fills the box on the documented setups
|
|
8
|
+
* @position AspectRatio integration proof. Which rule sizes the child is a
|
|
9
|
+
* cascade-layer question, and only a shipping engine resolves the cascade.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import * as fs from 'node:fs';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {expect, test, type Page} from '@playwright/test';
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_STORYBOOK_DIR,
|
|
17
|
+
serveStorybook,
|
|
18
|
+
type StaticServer,
|
|
19
|
+
} from '@astryxdesign/a11y-spec/storybook';
|
|
20
|
+
|
|
21
|
+
const PREFLIGHT_CSS = fs.readFileSync(
|
|
22
|
+
fileURLToPath(import.meta.resolve('tailwindcss/preflight.css')),
|
|
23
|
+
'utf8',
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
// The layer order each setup guide declares, and the layer preflight goes in.
|
|
27
|
+
const TAILWIND_SETUPS = [
|
|
28
|
+
{
|
|
29
|
+
name: 'Tailwind v4',
|
|
30
|
+
order:
|
|
31
|
+
'@layer reset, theme, base, astryx-base, astryx-theme, components, utilities;',
|
|
32
|
+
preflightLayer: 'base',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Tailwind v3',
|
|
36
|
+
order: '@layer reset, tw-preflight, astryx-base, astryx-theme;',
|
|
37
|
+
preflightLayer: 'tw-preflight',
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
// A 100×100 image in a 320px-wide 16:9 box: filling the box makes it 320×180.
|
|
42
|
+
const IMAGE =
|
|
43
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'/%3E";
|
|
44
|
+
|
|
45
|
+
type Fit = 'cover' | 'contain';
|
|
46
|
+
|
|
47
|
+
let storybook: StaticServer;
|
|
48
|
+
test.beforeAll(async () => {
|
|
49
|
+
storybook = await serveStorybook(
|
|
50
|
+
process.env.ASTRYX_STORYBOOK_DIR ?? DEFAULT_STORYBOOK_DIR,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
test.afterAll(async () => {
|
|
54
|
+
await storybook?.close();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The markup AspectRatio renders for `fit`, and every CSS rule the story
|
|
59
|
+
* page loaded, taken from the built story so the classes and rules are the
|
|
60
|
+
* component's real compiled output. The child image gets a fixed id, a
|
|
61
|
+
* local source and any extra class.
|
|
62
|
+
*/
|
|
63
|
+
async function captureStory(page: Page, fit: Fit, mediaClass: string) {
|
|
64
|
+
await page.goto(
|
|
65
|
+
`${storybook.origin}/iframe.html?id=core-aspectratio--fit-modes&viewMode=story`,
|
|
66
|
+
);
|
|
67
|
+
const wrapper = page.locator(`[data-astryx-aspect-ratio-override="${fit}"]`);
|
|
68
|
+
await expect(wrapper).toHaveCount(1);
|
|
69
|
+
return wrapper.evaluate(
|
|
70
|
+
(element, {image, extraClass}) => {
|
|
71
|
+
const root = element.parentElement?.cloneNode(true);
|
|
72
|
+
const media =
|
|
73
|
+
root instanceof HTMLElement ? root.querySelector('img') : null;
|
|
74
|
+
if (!(root instanceof HTMLElement) || media == null) {
|
|
75
|
+
throw new Error('FitModes no longer renders an img inside AspectRatio');
|
|
76
|
+
}
|
|
77
|
+
media.id = 'media';
|
|
78
|
+
media.src = image;
|
|
79
|
+
if (extraClass) {
|
|
80
|
+
media.classList.add(extraClass);
|
|
81
|
+
}
|
|
82
|
+
const css = [...document.styleSheets]
|
|
83
|
+
.flatMap(sheet => [...sheet.cssRules].map(rule => rule.cssText))
|
|
84
|
+
.join('\n');
|
|
85
|
+
return {html: root.outerHTML, css};
|
|
86
|
+
},
|
|
87
|
+
{image: IMAGE, extraClass: mediaClass},
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Re-host the captured story with `before` CSS ahead of it and `after` CSS behind it. */
|
|
92
|
+
async function measureMedia(
|
|
93
|
+
page: Page,
|
|
94
|
+
fit: Fit,
|
|
95
|
+
{
|
|
96
|
+
before = [],
|
|
97
|
+
after = [],
|
|
98
|
+
mediaClass = '',
|
|
99
|
+
}: {
|
|
100
|
+
before?: string[];
|
|
101
|
+
after?: string[];
|
|
102
|
+
mediaClass?: string;
|
|
103
|
+
},
|
|
104
|
+
) {
|
|
105
|
+
const {html, css} = await captureStory(page, fit, mediaClass);
|
|
106
|
+
await page.setContent(
|
|
107
|
+
`<!doctype html><div style="width: 320px">${html}</div>`,
|
|
108
|
+
);
|
|
109
|
+
for (const content of [...before, css, ...after]) {
|
|
110
|
+
await page.addStyleTag({content});
|
|
111
|
+
}
|
|
112
|
+
await page.waitForFunction(
|
|
113
|
+
() => (document.getElementById('media') as HTMLImageElement).complete,
|
|
114
|
+
);
|
|
115
|
+
return page.evaluate(() => {
|
|
116
|
+
const media = document.getElementById('media');
|
|
117
|
+
if (!media) {
|
|
118
|
+
throw new Error('missing media');
|
|
119
|
+
}
|
|
120
|
+
const box = media.getBoundingClientRect();
|
|
121
|
+
return {
|
|
122
|
+
width: box.width,
|
|
123
|
+
height: box.height,
|
|
124
|
+
objectFit: getComputedStyle(media).objectFit,
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const setup of TAILWIND_SETUPS) {
|
|
130
|
+
for (const fit of ['cover', 'contain'] as const) {
|
|
131
|
+
test(`fit="${fit}" fills the box on the ${setup.name} setup`, async ({
|
|
132
|
+
page,
|
|
133
|
+
}) => {
|
|
134
|
+
const media = await measureMedia(page, fit, {
|
|
135
|
+
before: [
|
|
136
|
+
setup.order,
|
|
137
|
+
`@layer ${setup.preflightLayer} { ${PREFLIGHT_CSS} }`,
|
|
138
|
+
],
|
|
139
|
+
});
|
|
140
|
+
expect(media).toEqual({width: 320, height: 180, objectFit: fit});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
test('fit fills the box with only Astryx CSS loaded', async ({page}) => {
|
|
146
|
+
const media = await measureMedia(page, 'cover', {});
|
|
147
|
+
expect(media).toEqual({width: 320, height: 180, objectFit: 'cover'});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('a utility class on the child still wins over fit', async ({page}) => {
|
|
151
|
+
const media = await measureMedia(page, 'cover', {
|
|
152
|
+
before: [TAILWIND_SETUPS[0].order, `@layer base { ${PREFLIGHT_CSS} }`],
|
|
153
|
+
after: ['@layer utilities { .h-10 { height: 40px; } }'],
|
|
154
|
+
mediaClass: 'h-10',
|
|
155
|
+
});
|
|
156
|
+
expect(media).toEqual({width: 320, height: 40, objectFit: 'cover'});
|
|
157
|
+
});
|
|
@@ -209,6 +209,40 @@ describe('CheckboxInput', () => {
|
|
|
209
209
|
);
|
|
210
210
|
});
|
|
211
211
|
|
|
212
|
+
it('preserves a caller-provided id on the input and its label', () => {
|
|
213
|
+
render(
|
|
214
|
+
<CheckboxInput
|
|
215
|
+
id="accept-terms"
|
|
216
|
+
label="Accept terms"
|
|
217
|
+
value={false}
|
|
218
|
+
onChange={() => {}}
|
|
219
|
+
/>,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const checkbox = screen.getByRole('checkbox');
|
|
223
|
+
expect(checkbox).toHaveAttribute('id', 'accept-terms');
|
|
224
|
+
expect(screen.getByText('Accept terms').closest('label')).toHaveAttribute(
|
|
225
|
+
'for',
|
|
226
|
+
'accept-terms',
|
|
227
|
+
);
|
|
228
|
+
expect(screen.getByLabelText('Accept terms')).toBe(checkbox);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('generates an id the label resolves when the caller passes an empty id', () => {
|
|
232
|
+
render(
|
|
233
|
+
<CheckboxInput
|
|
234
|
+
id=""
|
|
235
|
+
label="Accept terms"
|
|
236
|
+
value={false}
|
|
237
|
+
onChange={() => {}}
|
|
238
|
+
/>,
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const checkbox = screen.getByRole('checkbox');
|
|
242
|
+
expect(checkbox.id).not.toBe('');
|
|
243
|
+
expect(screen.getByLabelText('Accept terms')).toBe(checkbox);
|
|
244
|
+
});
|
|
245
|
+
|
|
212
246
|
it('forwards arbitrary data-* attributes to the input', () => {
|
|
213
247
|
render(
|
|
214
248
|
<CheckboxInput
|
|
@@ -311,6 +311,7 @@ const dynamicWidthStyles = stylex.create({
|
|
|
311
311
|
* ```
|
|
312
312
|
*/
|
|
313
313
|
export function CheckboxInput({
|
|
314
|
+
id: idProp,
|
|
314
315
|
label,
|
|
315
316
|
isLabelHidden = false,
|
|
316
317
|
description,
|
|
@@ -340,7 +341,8 @@ export function CheckboxInput({
|
|
|
340
341
|
// The row is the pressable: the overlay's pressed arm reads the row's
|
|
341
342
|
// scope marker, the way the indicator's hover tint does.
|
|
342
343
|
const pressable = usePressFeedback();
|
|
343
|
-
const
|
|
344
|
+
const generatedId = useId();
|
|
345
|
+
const id = idProp || generatedId;
|
|
344
346
|
const descriptionID = useId();
|
|
345
347
|
const statusMessageID = useId();
|
|
346
348
|
// Announce the effective required state (form default included) while the
|
|
@@ -59,6 +59,28 @@ beforeEach(() => {
|
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
describe('CheckboxList', () => {
|
|
62
|
+
it('forwards CheckboxListItem align to its Item row unchanged', () => {
|
|
63
|
+
render(
|
|
64
|
+
<CheckboxList label="Toppings" value={[]} onChange={() => {}}>
|
|
65
|
+
<CheckboxListItem label="Cheese" value="cheese" data-testid="cheese" />
|
|
66
|
+
<CheckboxListItem
|
|
67
|
+
label="Olives"
|
|
68
|
+
value="olives"
|
|
69
|
+
align="first-line"
|
|
70
|
+
data-testid="olives"
|
|
71
|
+
/>
|
|
72
|
+
</CheckboxList>,
|
|
73
|
+
);
|
|
74
|
+
expect(screen.getByTestId('cheese')).toHaveAttribute(
|
|
75
|
+
'data-align',
|
|
76
|
+
'center',
|
|
77
|
+
);
|
|
78
|
+
expect(screen.getByTestId('olives')).toHaveAttribute(
|
|
79
|
+
'data-align',
|
|
80
|
+
'first-line',
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
62
84
|
it('renders with label', () => {
|
|
63
85
|
render(
|
|
64
86
|
<CheckboxList label="Preferences" value={[]} onChange={() => {}}>
|
|
@@ -55,6 +55,13 @@ export const docs = {
|
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
|
+
{
|
|
59
|
+
name: 'align',
|
|
60
|
+
type: "'center' | 'start' | 'first-line'",
|
|
61
|
+
description:
|
|
62
|
+
'Vertical alignment of the start and end content against the label, passed through to Item unchanged. `first-line` keeps a small mark (a checkbox) level with the first line of a wrapped label. See Item.align.',
|
|
63
|
+
default: "'center'",
|
|
64
|
+
},
|
|
58
65
|
{
|
|
59
66
|
name: 'isDisabled',
|
|
60
67
|
type: 'boolean',
|
|
@@ -130,6 +137,13 @@ export const docsZh = {
|
|
|
130
137
|
type: 'ReactNode',
|
|
131
138
|
description: '在标签区域后渲染的内容。',
|
|
132
139
|
},
|
|
140
|
+
{
|
|
141
|
+
name: 'align',
|
|
142
|
+
type: "'center' | 'start' | 'first-line'",
|
|
143
|
+
description:
|
|
144
|
+
'起始和结束内容相对于标签的垂直对齐方式,原样传递给 Item。`first-line` 让小标记(复选框)与换行标签的第一行保持水平。参见 Item.align。',
|
|
145
|
+
default: "'center'",
|
|
146
|
+
},
|
|
133
147
|
{
|
|
134
148
|
name: 'isDisabled',
|
|
135
149
|
type: 'boolean',
|
|
@@ -165,6 +179,8 @@ export const docsDense = {
|
|
|
165
179
|
description:
|
|
166
180
|
'Individual checkbox item w/ label, description, end content slot. Collection mode inside CheckboxList with value; standalone inside List or CheckboxList without value.',
|
|
167
181
|
propDescriptions: {
|
|
182
|
+
align:
|
|
183
|
+
"Start/end content alignment, passed to Item: 'center' (default), 'start', or 'first-line' (centered on the label's first line).",
|
|
168
184
|
label:
|
|
169
185
|
'Primary label. String or ReactNode; nested controls keep their behavior. A ReactNode names the checkbox from its visible text.',
|
|
170
186
|
'aria-label':
|
|
@@ -29,6 +29,7 @@ import {ListContext} from '../List/ListContext';
|
|
|
29
29
|
import {CheckboxListContext} from './CheckboxListContext';
|
|
30
30
|
import {useTranslator} from '../i18n';
|
|
31
31
|
import {ItemDescriptionContext} from '../Item/ItemDescriptionContext';
|
|
32
|
+
import type {ItemAlign} from '../Item';
|
|
32
33
|
|
|
33
34
|
// =============================================================================
|
|
34
35
|
// Styles
|
|
@@ -45,6 +46,13 @@ const styles = stylex.create({
|
|
|
45
46
|
// =============================================================================
|
|
46
47
|
|
|
47
48
|
export interface CheckboxListItemProps extends BaseProps<HTMLLIElement> {
|
|
49
|
+
/**
|
|
50
|
+
* Vertical alignment of the start and end content against the label,
|
|
51
|
+
* forwarded to Item. Use `first-line` to keep the checkbox level with the
|
|
52
|
+
* first line of a wrapped label.
|
|
53
|
+
* @default 'center'
|
|
54
|
+
*/
|
|
55
|
+
align?: ItemAlign;
|
|
48
56
|
/**
|
|
49
57
|
* Primary text label for the item.
|
|
50
58
|
*
|
|
@@ -192,6 +200,7 @@ export function CheckboxListItem({
|
|
|
192
200
|
className,
|
|
193
201
|
style,
|
|
194
202
|
onClick: onClickProp,
|
|
203
|
+
align,
|
|
195
204
|
...restProps
|
|
196
205
|
}: CheckboxListItemProps) {
|
|
197
206
|
const t = useTranslator();
|
|
@@ -297,6 +306,7 @@ export function CheckboxListItem({
|
|
|
297
306
|
label={namesFromVisibleLabel ? <span id={labelID}>{label}</span> : label}
|
|
298
307
|
description={description}
|
|
299
308
|
endContent={endContent}
|
|
309
|
+
align={align}
|
|
300
310
|
isDisabled={effectiveDisabled}
|
|
301
311
|
// Delegate row clicks to the checkbox instead of wiring onClick (which
|
|
302
312
|
// would add an invisible row button = a second tab stop). The checkbox
|
|
@@ -110,6 +110,52 @@ beforeEach(() => {
|
|
|
110
110
|
});
|
|
111
111
|
|
|
112
112
|
describe('Dialog', () => {
|
|
113
|
+
it('restores focus to the opener when content mounts in the open commit', () => {
|
|
114
|
+
function Harness({
|
|
115
|
+
open,
|
|
116
|
+
onOpenChange,
|
|
117
|
+
}: {
|
|
118
|
+
open: boolean;
|
|
119
|
+
onOpenChange: (v: boolean) => void;
|
|
120
|
+
}) {
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<button type="button" onClick={() => onOpenChange(true)}>
|
|
124
|
+
Open
|
|
125
|
+
</button>
|
|
126
|
+
<Dialog isOpen={open} onOpenChange={onOpenChange}>
|
|
127
|
+
{open ? (
|
|
128
|
+
<div>
|
|
129
|
+
<DialogHeader title="Review" />
|
|
130
|
+
<p>Body</p>
|
|
131
|
+
</div>
|
|
132
|
+
) : null}
|
|
133
|
+
</Dialog>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let open = false;
|
|
139
|
+
const setOpen = (v: boolean) => {
|
|
140
|
+
open = v;
|
|
141
|
+
};
|
|
142
|
+
const harness = render(<Harness open={open} onOpenChange={setOpen} />);
|
|
143
|
+
const opener = screen.getByRole('button', {name: 'Open'});
|
|
144
|
+
opener.focus();
|
|
145
|
+
|
|
146
|
+
fireEvent.click(opener);
|
|
147
|
+
harness.rerender(<Harness open={open} onOpenChange={setOpen} />);
|
|
148
|
+
|
|
149
|
+
// The freshly mounted header title is the focused screen reader anchor
|
|
150
|
+
// while the dialog is open...
|
|
151
|
+
expect(document.activeElement).toBe(screen.getByText('Review'));
|
|
152
|
+
|
|
153
|
+
// ...but closing restores the element that opened the dialog, not the
|
|
154
|
+
// (now unmounted) title.
|
|
155
|
+
harness.rerender(<Harness open={false} onOpenChange={setOpen} />);
|
|
156
|
+
expect(document.activeElement).toBe(opener);
|
|
157
|
+
});
|
|
158
|
+
|
|
113
159
|
it('renders when isOpen is true', () => {
|
|
114
160
|
render(
|
|
115
161
|
<Dialog isOpen={true} onOpenChange={() => {}}>
|
package/src/Dialog/Dialog.tsx
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
useCallback,
|
|
33
33
|
useEffect,
|
|
34
34
|
useId,
|
|
35
|
+
useLayoutEffect,
|
|
35
36
|
useMemo,
|
|
36
37
|
useRef,
|
|
37
38
|
type ReactNode,
|
|
@@ -505,12 +506,26 @@ export function Dialog({
|
|
|
505
506
|
|
|
506
507
|
const mergedDialogRef = useMergedRefs(ref, attachDialog);
|
|
507
508
|
|
|
508
|
-
// Capture the element that was focused when the dialog opened,
|
|
509
|
-
//
|
|
509
|
+
// Capture the element that was focused when the dialog opened, for
|
|
510
|
+
// directional animation origin and focus restoration on close.
|
|
510
511
|
const triggerElementRef = useRef<HTMLElement | null>(null);
|
|
511
512
|
|
|
512
513
|
useInteractionModalityTracking();
|
|
513
514
|
|
|
515
|
+
// This runs in a layout effect so the capture lands before any descendant's
|
|
516
|
+
// passive mount effect: all layout effects run before any passive effect,
|
|
517
|
+
// while a child's passive effect runs before this parent's passive effect.
|
|
518
|
+
// Content that mounts in the open commit — e.g. a DialogHeader focusing its
|
|
519
|
+
// own title on mount — would otherwise move document.activeElement inside
|
|
520
|
+
// the dialog before the capture ran, and closing would then restore focus
|
|
521
|
+
// to a detached node, stranding the user's focus on <body>.
|
|
522
|
+
useLayoutEffect(() => {
|
|
523
|
+
if (isInline || !isOpen) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
triggerElementRef.current = document.activeElement as HTMLElement | null;
|
|
527
|
+
}, [isOpen, isInline]);
|
|
528
|
+
|
|
514
529
|
// Derive dismissal behavior from purpose
|
|
515
530
|
const allowEscape = purpose !== 'required';
|
|
516
531
|
const allowBackdropClick = purpose === 'info';
|
|
@@ -526,11 +541,9 @@ export function Dialog({
|
|
|
526
541
|
}
|
|
527
542
|
|
|
528
543
|
if (isOpen) {
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
// Set directional CSS custom properties before opening
|
|
544
|
+
// Set directional CSS custom properties before opening. The trigger was
|
|
545
|
+
// captured by the layout effect above, before any descendant effect
|
|
546
|
+
// could move focus.
|
|
534
547
|
const trigger = triggerElementRef.current;
|
|
535
548
|
if (trigger && trigger !== document.body) {
|
|
536
549
|
const dir = getDialogDirection(trigger);
|
|
@@ -25,18 +25,4 @@ export const DIALOG_MODAL_KNOWN_FAILURES: ReadonlyArray<KnownFailure> = [
|
|
|
25
25
|
reason:
|
|
26
26
|
'This migration records the existing focus-order violation without changing the overlapping Dialog implementation path.',
|
|
27
27
|
},
|
|
28
|
-
{
|
|
29
|
-
expectation: 'modal-dialog.focus.restored',
|
|
30
|
-
binding: 'Dialog',
|
|
31
|
-
state: 'conditional-content-focus-restoration',
|
|
32
|
-
evidenceLayer: 'real-browser',
|
|
33
|
-
failureEquals:
|
|
34
|
-
'closing the modal dialog did not return focus to its still-available invoker',
|
|
35
|
-
standardsReference:
|
|
36
|
-
'Astryx component:Dialog FR4 — closing a native Dialog must return focus to its still-connected invoker when it can receive focus.',
|
|
37
|
-
userImpact:
|
|
38
|
-
'When focus-moving content mounts only while the dialog is open, closing can leave the user at the document body instead of the control that opened the task.',
|
|
39
|
-
reason:
|
|
40
|
-
'This migration records the existing restoration violation without changing the overlapping Dialog implementation path.',
|
|
41
|
-
},
|
|
42
28
|
];
|