@astryxdesign/core 0.4.3 → 0.4.4-canary.0e8af82
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 +60 -0
- package/README.md +79 -45
- package/dist/Banner/Banner.d.ts +3 -0
- package/dist/Banner/Banner.d.ts.map +1 -1
- package/dist/Banner/Banner.js +13 -3
- package/dist/BottomSheet/BottomSheet.d.ts +75 -0
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheet.js +396 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts +63 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetPanel.js +441 -0
- package/dist/BottomSheet/BottomSheetSwitcher.d.ts +61 -0
- package/dist/BottomSheet/BottomSheetSwitcher.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetSwitcher.js +410 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts +21 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetSwitcherContext.js +13 -0
- package/dist/BottomSheet/index.d.ts +11 -0
- package/dist/BottomSheet/index.d.ts.map +1 -0
- package/dist/BottomSheet/index.js +12 -0
- package/dist/BottomSheet/snapOffsets.d.ts +109 -0
- package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
- package/dist/BottomSheet/snapOffsets.js +206 -0
- package/dist/BottomSheet/useMobileKeyboard.d.ts +35 -0
- package/dist/BottomSheet/useMobileKeyboard.d.ts.map +1 -0
- package/dist/BottomSheet/useMobileKeyboard.js +373 -0
- package/dist/BottomSheet/useSheetGestures.d.ts +185 -0
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -0
- package/dist/BottomSheet/useSheetGestures.js +1038 -0
- package/dist/Calendar/Calendar.d.ts +17 -0
- package/dist/Calendar/Calendar.d.ts.map +1 -1
- package/dist/Calendar/Calendar.js +25 -1
- package/dist/Calendar/hooks/useCalendarConstraints.d.ts +22 -1
- package/dist/Calendar/hooks/useCalendarConstraints.d.ts.map +1 -1
- package/dist/Calendar/hooks/useCalendarConstraints.js +26 -4
- package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
- package/dist/Chat/ChatComposerInput.js +3 -4
- package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
- package/dist/CheckboxInput/CheckboxInput.js +9 -0
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +18 -7
- package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/ContextMenu/ContextMenu.js +4 -2
- package/dist/DateInput/DateInput.d.ts.map +1 -1
- package/dist/DateInput/DateInput.js +15 -2
- package/dist/DateRangeInput/DateRangeInput.d.ts +23 -1
- package/dist/DateRangeInput/DateRangeInput.d.ts.map +1 -1
- package/dist/DateRangeInput/DateRangeInput.js +38 -3
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +38 -3
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +2 -1
- package/dist/Field/FieldLabel.d.ts +2 -1
- package/dist/Field/FieldLabel.d.ts.map +1 -1
- package/dist/Field/FieldLabel.js +21 -3
- package/dist/Field/InputClearButton.d.ts +2 -1
- package/dist/Field/InputClearButton.d.ts.map +1 -1
- package/dist/Field/InputClearButton.js +6 -1
- package/dist/FormLayout/FormLayout.d.ts +24 -2
- package/dist/FormLayout/FormLayout.d.ts.map +1 -1
- package/dist/FormLayout/FormLayout.js +7 -2
- package/dist/FormLayout/FormLayoutContext.d.ts +15 -2
- package/dist/FormLayout/FormLayoutContext.d.ts.map +1 -1
- package/dist/FormLayout/FormLayoutContext.js +19 -4
- package/dist/FormLayout/index.d.ts +1 -1
- package/dist/FormLayout/index.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.d.ts.map +1 -1
- package/dist/Lightbox/Lightbox.js +9 -3
- package/dist/MobileNav/MobileNav.d.ts +12 -0
- package/dist/MobileNav/MobileNav.d.ts.map +1 -1
- package/dist/MobileNav/MobileNav.js +102 -30
- package/dist/MultiSelector/MultiSelector.d.ts.map +1 -1
- package/dist/MultiSelector/MultiSelector.js +27 -8
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +15 -2
- package/dist/PowerSearch/PowerSearchEditPopover.js +1 -1
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +12 -1
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +20 -4
- package/dist/StatusDot/StatusDot.d.ts +43 -3
- package/dist/StatusDot/StatusDot.d.ts.map +1 -1
- package/dist/StatusDot/StatusDot.js +42 -5
- package/dist/Switch/Switch.d.ts.map +1 -1
- package/dist/Switch/Switch.js +14 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
- package/dist/TextArea/TextArea.d.ts.map +1 -1
- package/dist/TextArea/TextArea.js +6 -1
- package/dist/TextInput/TextInput.d.ts.map +1 -1
- package/dist/TextInput/TextInput.js +6 -1
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +14 -2
- package/dist/Tokenizer/Tokenizer.js +11 -5
- package/dist/Tooltip/useTooltip.d.ts.map +1 -1
- package/dist/Tooltip/useTooltip.js +4 -1
- package/dist/Typeahead/BaseTypeahead.d.ts.map +1 -1
- package/dist/Typeahead/BaseTypeahead.js +5 -3
- package/dist/Typeahead/Typeahead.d.ts.map +1 -1
- package/dist/Typeahead/Typeahead.js +10 -1
- package/dist/astryx.css +21 -0
- package/dist/hooks/index.d.ts +8 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +8 -1
- package/dist/hooks/useFocusTrap.d.ts +0 -11
- package/dist/hooks/useFocusTrap.d.ts.map +1 -1
- package/dist/hooks/useFocusTrap.js +1 -11
- package/dist/hooks/useInputStatusIcon.d.ts.map +1 -1
- package/dist/hooks/useInputStatusIcon.js +1 -0
- package/dist/hooks/useResolvedRequired.d.ts +19 -0
- package/dist/hooks/useResolvedRequired.d.ts.map +1 -0
- package/dist/hooks/useResolvedRequired.js +40 -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/defineTheme.d.ts +22 -4
- package/dist/theme/defineTheme.d.ts.map +1 -1
- package/dist/theme/expandColorScale.d.ts +17 -2
- package/dist/theme/expandColorScale.d.ts.map +1 -1
- package/dist/theme/expandColorScale.js +63 -33
- package/dist/utils/ime.d.ts +5 -0
- package/dist/utils/ime.d.ts.map +1 -0
- package/dist/utils/ime.js +63 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/plainDate.d.ts +6 -0
- package/dist/utils/plainDate.d.ts.map +1 -1
- package/dist/utils/plainDate.js +12 -0
- package/locales/af-ZA.json +958 -0
- package/locales/ar-SA.json +998 -0
- package/locales/ca-ES.json +974 -0
- package/locales/cs-CZ.json +990 -0
- package/locales/da-DK.json +966 -0
- package/locales/de-DE.json +966 -0
- package/locales/el-GR.json +990 -0
- package/locales/en.json +52 -0
- package/locales/es-ES.json +978 -0
- package/locales/fi-FI.json +990 -0
- package/locales/fr-FR.json +928 -0
- package/locales/he-IL.json +990 -0
- package/locales/hu-HU.json +990 -0
- package/locales/it-IT.json +978 -0
- package/locales/ja-JP.json +998 -0
- package/locales/ko-KR.json +990 -0
- package/locales/nl-NL.json +954 -0
- package/locales/no-NO.json +978 -0
- package/locales/pl-PL.json +982 -0
- package/locales/pseudo.json +39 -0
- package/locales/pt-BR.json +982 -0
- package/locales/pt-PT.json +982 -0
- package/locales/ro-RO.json +982 -0
- package/locales/ru-RU.json +990 -0
- package/locales/sr-SP.json +990 -0
- package/locales/sv-SE.json +986 -0
- package/locales/tr-TR.json +990 -0
- package/locales/uk-UA.json +990 -0
- package/locales/vi-VN.json +986 -0
- package/locales/zh-CN.json +998 -0
- package/locales/zh-TW.json +998 -0
- package/package.json +9 -8
- package/src/Banner/Banner.doc.mjs +3 -3
- package/src/Banner/Banner.test.tsx +40 -0
- package/src/Banner/Banner.tsx +27 -2
- package/src/BottomSheet/BottomSheet.doc.mjs +299 -0
- package/src/BottomSheet/BottomSheet.test.tsx +2265 -0
- package/src/BottomSheet/BottomSheet.tsx +559 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +240 -0
- package/src/BottomSheet/BottomSheetPanel.tsx +601 -0
- package/src/BottomSheet/BottomSheetSwitcher.doc.mjs +219 -0
- package/src/BottomSheet/BottomSheetSwitcher.test.tsx +850 -0
- package/src/BottomSheet/BottomSheetSwitcher.tsx +628 -0
- package/src/BottomSheet/BottomSheetSwitcherContext.ts +51 -0
- package/src/BottomSheet/index.ts +19 -0
- package/src/BottomSheet/snapOffsets.test.ts +254 -0
- package/src/BottomSheet/snapOffsets.ts +245 -0
- package/src/BottomSheet/useMobileKeyboard.ts +499 -0
- package/src/BottomSheet/useSheetGestures.test.ts +1112 -0
- package/src/BottomSheet/useSheetGestures.ts +1503 -0
- package/src/Calendar/Calendar.doc.mjs +16 -0
- package/src/Calendar/Calendar.test.tsx +96 -0
- package/src/Calendar/Calendar.tsx +55 -0
- package/src/Calendar/hooks/useCalendarConstraints.ts +54 -3
- package/src/Chat/ChatComposerInput.tsx +3 -4
- package/src/CheckboxInput/CheckboxInput.tsx +6 -0
- package/src/ComplexSelector/ComplexSelector.tsx +15 -6
- package/src/ContextMenu/ContextMenu.tsx +4 -2
- package/src/DateInput/DateInput.test.tsx +21 -0
- package/src/DateInput/DateInput.tsx +12 -2
- package/src/DateRangeInput/DateRangeInput.doc.mjs +16 -0
- package/src/DateRangeInput/DateRangeInput.test.tsx +81 -1
- package/src/DateRangeInput/DateRangeInput.tsx +72 -1
- package/src/DateTimeInput/DateTimeInput.doc.mjs +4 -0
- package/src/DateTimeInput/DateTimeInput.test.tsx +137 -0
- package/src/DateTimeInput/DateTimeInput.tsx +43 -4
- package/src/Dialog/Dialog.tsx +2 -1
- package/src/Field/Field.doc.mjs +1 -0
- package/src/Field/FieldLabel.tsx +20 -4
- package/src/Field/InputClearButton.test.tsx +25 -0
- package/src/Field/InputClearButton.tsx +4 -1
- package/src/FileInput/FileInput.test.tsx +53 -9
- package/src/FormLayout/FormLayout.doc.mjs +13 -0
- package/src/FormLayout/FormLayout.test.tsx +181 -4
- package/src/FormLayout/FormLayout.tsx +33 -2
- package/src/FormLayout/FormLayoutContext.ts +22 -7
- package/src/FormLayout/index.ts +1 -1
- package/src/Lightbox/Lightbox.test.tsx +49 -28
- package/src/Lightbox/Lightbox.tsx +7 -3
- package/src/MobileNav/MobileNav.tsx +128 -37
- package/src/MobileNav/MobileNavCloseEdgeCases.test.tsx +426 -0
- package/src/MobileNav/MobileNavCloseTiming.test.ts +58 -0
- package/src/MobileNav/MobileNavCloseVisibility.test.tsx +172 -0
- package/src/MultiSelector/MultiSelector.test.tsx +195 -51
- package/src/MultiSelector/MultiSelector.tsx +25 -9
- package/src/NumberInput/NumberInput.test.tsx +18 -0
- package/src/NumberInput/NumberInput.tsx +12 -2
- package/src/PowerSearch/PowerSearchEditPopover.tsx +1 -1
- package/src/RadioList/RadioList.tsx +9 -1
- package/src/Selector/Selector.test.tsx +85 -26
- package/src/Selector/Selector.tsx +16 -5
- package/src/StatusDot/StatusDot.doc.mjs +13 -0
- package/src/StatusDot/StatusDot.test.tsx +115 -8
- package/src/StatusDot/StatusDot.tsx +74 -9
- package/src/Switch/Switch.test.tsx +16 -0
- package/src/Switch/Switch.tsx +13 -0
- package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
- package/src/TextArea/TextArea.tsx +3 -1
- package/src/TextInput/TextInput.tsx +3 -1
- package/src/TimeInput/TimeInput.test.tsx +23 -0
- package/src/TimeInput/TimeInput.tsx +11 -1
- package/src/Tokenizer/Tokenizer.test.tsx +50 -32
- package/src/Tokenizer/Tokenizer.tsx +5 -5
- package/src/Tooltip/useTooltip.tsx +4 -1
- package/src/Typeahead/BaseTypeahead.tsx +10 -3
- package/src/Typeahead/Typeahead.test.tsx +116 -7
- package/src/Typeahead/Typeahead.tsx +10 -1
- package/src/__tests__/stubMatchMedia.test.ts +79 -0
- package/src/__tests__/stubMatchMedia.ts +95 -0
- package/src/hooks/index.ts +9 -5
- package/src/hooks/useFocusTrap.ts +1 -14
- package/src/hooks/useInputStatusIcon.test.tsx +19 -0
- package/src/hooks/useInputStatusIcon.tsx +7 -0
- package/src/hooks/useResolvedRequired.ts +42 -0
- package/src/index.ts +1 -0
- package/src/theme/defineTheme.ts +22 -4
- package/src/theme/expandColorScale.test.ts +138 -0
- package/src/theme/expandColorScale.ts +89 -44
- package/src/utils/ime.test.ts +32 -0
- package/src/utils/ime.ts +69 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/plainDate.test.ts +50 -0
- package/src/utils/plainDate.ts +12 -0
- package/dist/astryx.umd.js +0 -147
- package/dist/astryx.umd.js.map +0 -7
|
@@ -20,6 +20,12 @@ import {
|
|
|
20
20
|
import userEvent from '@testing-library/user-event';
|
|
21
21
|
import {FileInput} from './FileInput';
|
|
22
22
|
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
|
|
23
|
+
import {InternationalizationProvider} from '../i18n';
|
|
24
|
+
|
|
25
|
+
// The `=1` branch names the file; the `other` branch must not. Both come from
|
|
26
|
+
// this test, so neither can pass against a hardcoded English string.
|
|
27
|
+
const FILE_SELECTED = 'Un fichier choisi : {fileName}';
|
|
28
|
+
const FILES_SELECTED = '{count, number} fichiers choisis';
|
|
23
29
|
|
|
24
30
|
afterEach(() => {
|
|
25
31
|
__resetLiveRegionsForTest();
|
|
@@ -324,23 +330,36 @@ describe('FileInput', () => {
|
|
|
324
330
|
|
|
325
331
|
describe('announcements', () => {
|
|
326
332
|
it('announces a single file selection politely', async () => {
|
|
327
|
-
render(
|
|
333
|
+
render(
|
|
334
|
+
<InternationalizationProvider
|
|
335
|
+
locale="fr"
|
|
336
|
+
overrides={{fr: {'@astryx.fileInput.fileSelected': FILE_SELECTED}}}>
|
|
337
|
+
<FileInput label="Upload" value={null} onChange={() => {}} />
|
|
338
|
+
</InternationalizationProvider>,
|
|
339
|
+
);
|
|
328
340
|
fireEvent.change(fileInputEl(), {
|
|
329
341
|
target: {files: [createFile('report.pdf', 100)]},
|
|
330
342
|
});
|
|
331
343
|
await waitFor(() => {
|
|
332
|
-
|
|
344
|
+
// The single-file key, carrying the file name.
|
|
345
|
+
expect(politeRegion()?.textContent).toBe(
|
|
346
|
+
'Un fichier choisi : report.pdf',
|
|
347
|
+
);
|
|
333
348
|
});
|
|
334
349
|
});
|
|
335
350
|
|
|
336
351
|
it('announces a multi-file count politely', async () => {
|
|
337
352
|
render(
|
|
338
|
-
<
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
353
|
+
<InternationalizationProvider
|
|
354
|
+
locale="fr"
|
|
355
|
+
overrides={{fr: {'@astryx.fileInput.filesSelected': FILES_SELECTED}}}>
|
|
356
|
+
<FileInput
|
|
357
|
+
label="Upload"
|
|
358
|
+
value={null}
|
|
359
|
+
onChange={() => {}}
|
|
360
|
+
isMultiple
|
|
361
|
+
/>
|
|
362
|
+
</InternationalizationProvider>,
|
|
344
363
|
);
|
|
345
364
|
const files = [
|
|
346
365
|
createFile('a.txt', 100),
|
|
@@ -349,7 +368,32 @@ describe('FileInput', () => {
|
|
|
349
368
|
];
|
|
350
369
|
fireEvent.change(fileInputEl(), {target: {files}});
|
|
351
370
|
await waitFor(() => {
|
|
352
|
-
|
|
371
|
+
// The multi-file key: a count, and no file name.
|
|
372
|
+
expect(politeRegion()?.textContent).toBe('3 fichiers choisis');
|
|
373
|
+
});
|
|
374
|
+
expect(politeRegion()?.textContent).not.toContain('a.txt');
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('speaks the selection from a provider catalog', async () => {
|
|
378
|
+
render(
|
|
379
|
+
<InternationalizationProvider
|
|
380
|
+
locale="fr"
|
|
381
|
+
messages={{
|
|
382
|
+
fr: {
|
|
383
|
+
'@astryx.fileInput.fileSelected': {defaultMessage: FILE_SELECTED},
|
|
384
|
+
},
|
|
385
|
+
}}>
|
|
386
|
+
<FileInput label="Upload" value={null} onChange={() => {}} />
|
|
387
|
+
</InternationalizationProvider>,
|
|
388
|
+
);
|
|
389
|
+
fireEvent.change(fileInputEl(), {
|
|
390
|
+
target: {files: [createFile('report.pdf', 100)]},
|
|
391
|
+
});
|
|
392
|
+
await waitFor(() => {
|
|
393
|
+
// Same key through the catalog path rather than `overrides`.
|
|
394
|
+
expect(politeRegion()?.textContent).toBe(
|
|
395
|
+
'Un fichier choisi : report.pdf',
|
|
396
|
+
);
|
|
353
397
|
});
|
|
354
398
|
});
|
|
355
399
|
|
|
@@ -16,6 +16,12 @@ export const docs = {
|
|
|
16
16
|
'Controls field arrangement. Vertical stacks top-to-bottom, horizontal arranges left-to-right with equal flex-grow, and horizontal-labels uses CSS Grid with labels to the left of inputs (collapses to vertical on narrow viewports <=480px).',
|
|
17
17
|
default: "'vertical'",
|
|
18
18
|
},
|
|
19
|
+
{
|
|
20
|
+
name: 'defaultOptionality',
|
|
21
|
+
type: "'optional' | 'required'",
|
|
22
|
+
description:
|
|
23
|
+
'The state the form treats as its default, so only the exception shows an optional/required indicator. With "optional", only fields marked isRequired show an indicator; with "required", only fields marked isOptional do. A field that restates the default shows nothing. Under "required" the unmarked fields also expose aria-required so screen readers match the visual default — aria-required only, never the native required attribute. Leave unset for today\'s per-field behavior.',
|
|
24
|
+
},
|
|
19
25
|
{
|
|
20
26
|
name: 'children',
|
|
21
27
|
type: 'ReactNode',
|
|
@@ -64,6 +70,12 @@ export const docsZh = {
|
|
|
64
70
|
'控制字段排列方式。vertical 从上到下堆叠,horizontal 从左到右排列且等比弹性增长,horizontal-labels 使用 CSS Grid 将标签放在输入框左侧(在窄视口 <=480px 时折叠为垂直布局)。',
|
|
65
71
|
default: "'vertical'",
|
|
66
72
|
},
|
|
73
|
+
{
|
|
74
|
+
name: 'defaultOptionality',
|
|
75
|
+
type: "'optional' | 'required'",
|
|
76
|
+
description:
|
|
77
|
+
'表单视为默认的状态,因此仅例外字段显示可选/必填指示器。设为 "optional" 时,仅标记 isRequired 的字段显示指示器;设为 "required" 时,仅标记 isOptional 的字段显示。与默认一致的字段不显示任何内容。设为 "required" 时,未标记的字段仍会暴露 aria-required,使屏幕阅读器与视觉默认一致——仅作用于 aria-required,不改变原生 required 属性。不设置则保持当前逐字段行为。',
|
|
78
|
+
},
|
|
67
79
|
{
|
|
68
80
|
name: 'children',
|
|
69
81
|
type: 'ReactNode',
|
|
@@ -122,6 +134,7 @@ export const docsDense = {
|
|
|
122
134
|
},
|
|
123
135
|
propDescriptions: {
|
|
124
136
|
direction: 'Field arrangement. Vertical stacks top-to-bottom, horizontal arranges left-to-right w/ equal flex-grow, horizontal-labels uses CSS Grid w/ labels left of inputs (collapses <=480px).',
|
|
137
|
+
defaultOptionality: 'State the form treats as default, so only the exception is marked. "optional" → only isRequired fields show an indicator; "required" → only isOptional fields do. Under "required" unmarked fields also expose aria-required (aria only, not native required). Unset = per-field behavior.',
|
|
125
138
|
children: 'Form fields to arrange. Accepts Astryx inputs + Field-wrapped custom controls.',
|
|
126
139
|
xstyle: 'StyleX styles for layout customization. Must be stylex.create() value.',
|
|
127
140
|
},
|
|
@@ -16,6 +16,8 @@ import {FormLayout} from './FormLayout';
|
|
|
16
16
|
import {FormLayoutContext} from './FormLayoutContext';
|
|
17
17
|
import type {FormLayoutDirection} from './FormLayoutContext';
|
|
18
18
|
import {Field} from '../Field';
|
|
19
|
+
import {TextInput} from '../TextInput';
|
|
20
|
+
import {CheckboxInput} from '../CheckboxInput';
|
|
19
21
|
|
|
20
22
|
// Helper component to read context
|
|
21
23
|
function DirectionReader() {
|
|
@@ -23,6 +25,12 @@ function DirectionReader() {
|
|
|
23
25
|
return <span data-testid="direction">{direction}</span>;
|
|
24
26
|
}
|
|
25
27
|
|
|
28
|
+
// Helper component to read the defaultOptionality context value
|
|
29
|
+
function OptionalityReader() {
|
|
30
|
+
const {defaultOptionality} = use(FormLayoutContext);
|
|
31
|
+
return <span data-testid="optionality">{defaultOptionality ?? 'unset'}</span>;
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
describe('FormLayout', () => {
|
|
27
35
|
// ─── Basic rendering ────────────────────────────────────────────────────
|
|
28
36
|
|
|
@@ -154,6 +162,178 @@ describe('FormLayout', () => {
|
|
|
154
162
|
expect(screen.getByTestId('inner-child-2')).toBeInTheDocument();
|
|
155
163
|
});
|
|
156
164
|
|
|
165
|
+
// ─── defaultOptionality context propagation ─────────────────────────────
|
|
166
|
+
|
|
167
|
+
it('leaves defaultOptionality unset by default', () => {
|
|
168
|
+
render(
|
|
169
|
+
<FormLayout>
|
|
170
|
+
<OptionalityReader />
|
|
171
|
+
</FormLayout>,
|
|
172
|
+
);
|
|
173
|
+
expect(screen.getByTestId('optionality')).toHaveTextContent('unset');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('provides defaultOptionality="optional" to children', () => {
|
|
177
|
+
render(
|
|
178
|
+
<FormLayout defaultOptionality="optional">
|
|
179
|
+
<OptionalityReader />
|
|
180
|
+
</FormLayout>,
|
|
181
|
+
);
|
|
182
|
+
expect(screen.getByTestId('optionality')).toHaveTextContent('optional');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('provides defaultOptionality="required" to children', () => {
|
|
186
|
+
render(
|
|
187
|
+
<FormLayout defaultOptionality="required">
|
|
188
|
+
<OptionalityReader />
|
|
189
|
+
</FormLayout>,
|
|
190
|
+
);
|
|
191
|
+
expect(screen.getByTestId('optionality')).toHaveTextContent('required');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('an inner layout shadows the outer defaultOptionality', () => {
|
|
195
|
+
render(
|
|
196
|
+
<FormLayout defaultOptionality="optional">
|
|
197
|
+
<FormLayout defaultOptionality="required">
|
|
198
|
+
<OptionalityReader />
|
|
199
|
+
</FormLayout>
|
|
200
|
+
</FormLayout>,
|
|
201
|
+
);
|
|
202
|
+
expect(screen.getByTestId('optionality')).toHaveTextContent('required');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// ─── defaultOptionality indicator behavior (through Field) ───────────────
|
|
206
|
+
//
|
|
207
|
+
// The rule: only the *exception* is marked. A field that restates the form
|
|
208
|
+
// default shows nothing; a deviation shows its indicator.
|
|
209
|
+
|
|
210
|
+
it('optional default: only isRequired fields show an indicator', () => {
|
|
211
|
+
render(
|
|
212
|
+
<FormLayout defaultOptionality="optional">
|
|
213
|
+
<Field label="Bio" inputID="bio">
|
|
214
|
+
<input id="bio" />
|
|
215
|
+
</Field>
|
|
216
|
+
<Field label="Nickname" inputID="nick" isOptional>
|
|
217
|
+
<input id="nick" />
|
|
218
|
+
</Field>
|
|
219
|
+
<Field label="Email" inputID="email" isRequired>
|
|
220
|
+
<input id="email" />
|
|
221
|
+
</Field>
|
|
222
|
+
</FormLayout>,
|
|
223
|
+
);
|
|
224
|
+
// Plain + isOptional match the default → nothing shown.
|
|
225
|
+
expect(screen.queryByText(/Optional/)).not.toBeInTheDocument();
|
|
226
|
+
// isRequired deviates → the required indicator shows.
|
|
227
|
+
expect(screen.getByText(/Required/)).toBeInTheDocument();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('required default: only isOptional fields show an indicator', () => {
|
|
231
|
+
render(
|
|
232
|
+
<FormLayout defaultOptionality="required">
|
|
233
|
+
<Field label="Name" inputID="name">
|
|
234
|
+
<input id="name" />
|
|
235
|
+
</Field>
|
|
236
|
+
<Field label="Email" inputID="email" isRequired>
|
|
237
|
+
<input id="email" />
|
|
238
|
+
</Field>
|
|
239
|
+
<Field label="Nickname" inputID="nick" isOptional>
|
|
240
|
+
<input id="nick" />
|
|
241
|
+
</Field>
|
|
242
|
+
</FormLayout>,
|
|
243
|
+
);
|
|
244
|
+
// Plain + isRequired match the default → nothing shown.
|
|
245
|
+
expect(screen.queryByText(/Required/)).not.toBeInTheDocument();
|
|
246
|
+
// isOptional deviates → the optional indicator shows.
|
|
247
|
+
expect(screen.getByText(/Optional/)).toBeInTheDocument();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it('unset default preserves per-field indicators (backwards compatible)', () => {
|
|
251
|
+
render(
|
|
252
|
+
<FormLayout>
|
|
253
|
+
<Field label="Email" inputID="email" isRequired>
|
|
254
|
+
<input id="email" />
|
|
255
|
+
</Field>
|
|
256
|
+
<Field label="Nickname" inputID="nick" isOptional>
|
|
257
|
+
<input id="nick" />
|
|
258
|
+
</Field>
|
|
259
|
+
</FormLayout>,
|
|
260
|
+
);
|
|
261
|
+
expect(screen.getByText(/Required/)).toBeInTheDocument();
|
|
262
|
+
expect(screen.getByText(/Optional/)).toBeInTheDocument();
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// ─── defaultOptionality aria-required resolution ─────────────────────────
|
|
266
|
+
//
|
|
267
|
+
// The indicator is suppressed for the unmarked majority, so the matching
|
|
268
|
+
// `aria-required` must still be exposed — otherwise a sighted user reads a
|
|
269
|
+
// field as required (form default, no indicator) while a screen reader hears
|
|
270
|
+
// "not required". Native `required` stays bound to the explicit prop so a
|
|
271
|
+
// layout default never switches on browser validation.
|
|
272
|
+
|
|
273
|
+
it('required default: an unmarked input still exposes aria-required', () => {
|
|
274
|
+
render(
|
|
275
|
+
<FormLayout defaultOptionality="required">
|
|
276
|
+
<TextInput label="Name" value="" onChange={() => {}} />
|
|
277
|
+
</FormLayout>,
|
|
278
|
+
);
|
|
279
|
+
expect(screen.getByLabelText('Name')).toHaveAttribute(
|
|
280
|
+
'aria-required',
|
|
281
|
+
'true',
|
|
282
|
+
);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('required default: an isOptional input is not aria-required', () => {
|
|
286
|
+
render(
|
|
287
|
+
<FormLayout defaultOptionality="required">
|
|
288
|
+
<TextInput label="Nickname" value="" onChange={() => {}} isOptional />
|
|
289
|
+
</FormLayout>,
|
|
290
|
+
);
|
|
291
|
+
expect(screen.getByRole('textbox')).not.toHaveAttribute('aria-required');
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('optional default: an unmarked input is not aria-required', () => {
|
|
295
|
+
render(
|
|
296
|
+
<FormLayout defaultOptionality="optional">
|
|
297
|
+
<TextInput label="Bio" value="" onChange={() => {}} />
|
|
298
|
+
</FormLayout>,
|
|
299
|
+
);
|
|
300
|
+
expect(screen.getByLabelText('Bio')).not.toHaveAttribute('aria-required');
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('no layout: an unmarked input is not aria-required (backwards compatible)', () => {
|
|
304
|
+
render(<TextInput label="Solo" value="" onChange={() => {}} />);
|
|
305
|
+
expect(screen.getByLabelText('Solo')).not.toHaveAttribute('aria-required');
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it('required default resolves aria-required without native required', () => {
|
|
309
|
+
render(
|
|
310
|
+
<FormLayout defaultOptionality="required">
|
|
311
|
+
<CheckboxInput label="Terms" value={false} onChange={() => {}} />
|
|
312
|
+
</FormLayout>,
|
|
313
|
+
);
|
|
314
|
+
const checkbox = screen.getByRole('checkbox', {name: 'Terms'});
|
|
315
|
+
// Announced as required (form default)…
|
|
316
|
+
expect(checkbox).toHaveAttribute('aria-required', 'true');
|
|
317
|
+
// …but the native `required` attribute is not switched on by the layout.
|
|
318
|
+
expect(checkbox).not.toHaveAttribute('required');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('explicit isRequired still drives native required under a layout', () => {
|
|
322
|
+
render(
|
|
323
|
+
<FormLayout defaultOptionality="required">
|
|
324
|
+
<CheckboxInput
|
|
325
|
+
label="Consent"
|
|
326
|
+
value={false}
|
|
327
|
+
onChange={() => {}}
|
|
328
|
+
isRequired
|
|
329
|
+
/>
|
|
330
|
+
</FormLayout>,
|
|
331
|
+
);
|
|
332
|
+
const checkbox = screen.getByRole('checkbox', {name: 'Consent'});
|
|
333
|
+
expect(checkbox).toHaveAttribute('aria-required', 'true');
|
|
334
|
+
expect(checkbox).toHaveAttribute('required');
|
|
335
|
+
});
|
|
336
|
+
|
|
157
337
|
// ─── Snapshot tests ─────────────────────────────────────────────────────
|
|
158
338
|
|
|
159
339
|
it('matches snapshot for vertical direction', () => {
|
|
@@ -223,10 +403,7 @@ describe('FormLayout', () => {
|
|
|
223
403
|
it('horizontal-labels with Field: label and input wrapper are siblings under display:contents', () => {
|
|
224
404
|
render(
|
|
225
405
|
<FormLayout direction="horizontal-labels" data-testid="layout">
|
|
226
|
-
<Field
|
|
227
|
-
label="Username"
|
|
228
|
-
inputID="username"
|
|
229
|
-
data-testid="username-field">
|
|
406
|
+
<Field label="Username" inputID="username" data-testid="username-field">
|
|
230
407
|
<input id="username" data-testid="username-input" />
|
|
231
408
|
</Field>
|
|
232
409
|
</FormLayout>,
|
|
@@ -10,7 +10,10 @@
|
|
|
10
10
|
*
|
|
11
11
|
* SYNC: When modified, update these files to stay in sync:
|
|
12
12
|
* - /packages/core/src/FormLayout/FormLayout.test.tsx (tests for new/changed behavior)
|
|
13
|
+
* - /packages/core/src/FormLayout/FormLayoutContext.ts (context value shape)
|
|
14
|
+
* - /packages/core/src/FormLayout/FormLayout.doc.mjs (props table)
|
|
13
15
|
* - /packages/core/src/FormLayout/index.ts (exports if types change)
|
|
16
|
+
* - /packages/core/src/Field/FieldLabel.tsx (defaultOptionality indicator resolution)
|
|
14
17
|
* - /apps/storybook/stories/FormLayout.stories.tsx (storybook stories)
|
|
15
18
|
* - /packages/cli/assets/templates/blocks/components/FormLayout/ (showcase blocks)
|
|
16
19
|
*/
|
|
@@ -19,7 +22,11 @@ import {useMemo, type ReactNode} from 'react';
|
|
|
19
22
|
import type {BaseProps} from '../BaseProps';
|
|
20
23
|
import * as stylex from '@stylexjs/stylex';
|
|
21
24
|
import {spacingVars} from '../theme/tokens.stylex';
|
|
22
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
FormLayoutContext,
|
|
27
|
+
type FormLayoutDirection,
|
|
28
|
+
type FormOptionality,
|
|
29
|
+
} from './FormLayoutContext';
|
|
23
30
|
import {mergeProps} from '../utils';
|
|
24
31
|
import {themeProps} from '../utils/themeProps';
|
|
25
32
|
|
|
@@ -82,6 +89,26 @@ export interface FormLayoutProps extends BaseProps<HTMLDivElement> {
|
|
|
82
89
|
* @default 'vertical'
|
|
83
90
|
*/
|
|
84
91
|
direction?: FormLayoutDirection;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Which state the form treats as its default, so only the *exception*
|
|
95
|
+
* carries a visible optional/required indicator. It also resolves each
|
|
96
|
+
* field's `aria-required` so the unmarked majority is still announced
|
|
97
|
+
* correctly — but only `aria-required`, never the native `required`
|
|
98
|
+
* attribute, so a layout default can't switch on browser validation.
|
|
99
|
+
*
|
|
100
|
+
* - `'optional'` — fields read as optional; only a field with `isRequired`
|
|
101
|
+
* shows an indicator (the "required" one).
|
|
102
|
+
* - `'required'` — fields read as required; only a field with `isOptional`
|
|
103
|
+
* shows an indicator (the "optional" one). Fields without `isOptional`
|
|
104
|
+
* expose `aria-required` even though they show no indicator.
|
|
105
|
+
* - unset — today's behavior: `isRequired` and `isOptional` each show their
|
|
106
|
+
* own indicator independently.
|
|
107
|
+
*
|
|
108
|
+
* A field that merely restates the default (e.g. `isOptional` under
|
|
109
|
+
* `'optional'`) shows nothing. An inner `FormLayout` shadows an outer one.
|
|
110
|
+
*/
|
|
111
|
+
defaultOptionality?: FormOptionality;
|
|
85
112
|
}
|
|
86
113
|
|
|
87
114
|
// =============================================================================
|
|
@@ -109,13 +136,17 @@ export interface FormLayoutProps extends BaseProps<HTMLDivElement> {
|
|
|
109
136
|
export function FormLayout({
|
|
110
137
|
children,
|
|
111
138
|
direction = 'vertical',
|
|
139
|
+
defaultOptionality,
|
|
112
140
|
xstyle,
|
|
113
141
|
className,
|
|
114
142
|
style,
|
|
115
143
|
ref,
|
|
116
144
|
...props
|
|
117
145
|
}: FormLayoutProps) {
|
|
118
|
-
const contextValue = useMemo(
|
|
146
|
+
const contextValue = useMemo(
|
|
147
|
+
() => ({direction, defaultOptionality}),
|
|
148
|
+
[direction, defaultOptionality],
|
|
149
|
+
);
|
|
119
150
|
|
|
120
151
|
return (
|
|
121
152
|
<FormLayoutContext value={contextValue}>
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* @file FormLayoutContext.ts
|
|
7
7
|
* @input Uses React createContext
|
|
8
|
-
* @output Exports FormLayoutContext and
|
|
9
|
-
* @position Context for form layout direction detection
|
|
8
|
+
* @output Exports FormLayoutContext, FormLayoutDirection, and FormOptionality types
|
|
9
|
+
* @position Context for form layout direction + default-optionality detection
|
|
10
10
|
*
|
|
11
11
|
* SYNC: When modified, update these files to stay in sync:
|
|
12
|
+
* - /packages/core/src/FormLayout/FormLayout.tsx (prop + context value)
|
|
13
|
+
* - /packages/core/src/Field/FieldLabel.tsx (indicator resolution)
|
|
14
|
+
* - /packages/core/src/FormLayout/index.ts (exports if types change)
|
|
12
15
|
*/
|
|
13
16
|
|
|
14
17
|
import {createContext} from 'react';
|
|
@@ -22,15 +25,27 @@ import {createContext} from 'react';
|
|
|
22
25
|
* of their inputs (settings/admin panel pattern).
|
|
23
26
|
*/
|
|
24
27
|
export type FormLayoutDirection =
|
|
25
|
-
| '
|
|
26
|
-
| 'horizontal'
|
|
27
|
-
| 'horizontal-labels';
|
|
28
|
+
'vertical' | 'horizontal' | 'horizontal-labels';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
31
|
+
* Which state a form treats as its default, so only the *exception* carries a
|
|
32
|
+
* visible optional/required indicator.
|
|
33
|
+
*
|
|
34
|
+
* - `'optional'` — fields are optional unless a field opts into `isRequired`;
|
|
35
|
+
* only required fields show an indicator.
|
|
36
|
+
* - `'required'` — fields are required unless a field opts into `isOptional`;
|
|
37
|
+
* only optional fields show an indicator.
|
|
38
|
+
*/
|
|
39
|
+
export type FormOptionality = 'optional' | 'required';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Context for detecting which form layout a component is rendered in. Children
|
|
43
|
+
* can use this to adapt their rendering based on the parent layout — direction
|
|
44
|
+
* for spatial arrangement, and `defaultOptionality` so a field can suppress the
|
|
45
|
+
* indicator that merely restates the form-wide default.
|
|
32
46
|
*/
|
|
33
47
|
export const FormLayoutContext = createContext<{
|
|
34
48
|
direction: FormLayoutDirection;
|
|
49
|
+
defaultOptionality?: FormOptionality;
|
|
35
50
|
}>({direction: 'vertical'});
|
|
36
51
|
FormLayoutContext.displayName = 'FormLayoutContext';
|
package/src/FormLayout/index.ts
CHANGED
|
@@ -13,5 +13,5 @@
|
|
|
13
13
|
|
|
14
14
|
export {FormLayout} from './FormLayout';
|
|
15
15
|
export type {FormLayoutProps} from './FormLayout';
|
|
16
|
-
export type {FormLayoutDirection} from './FormLayoutContext';
|
|
16
|
+
export type {FormLayoutDirection, FormOptionality} from './FormLayoutContext';
|
|
17
17
|
export {FormLayoutContext} from './FormLayoutContext';
|
|
@@ -4,6 +4,7 @@ import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
|
|
|
4
4
|
import {render, screen, fireEvent, waitFor} from '@testing-library/react';
|
|
5
5
|
import {Lightbox} from './Lightbox';
|
|
6
6
|
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
|
|
7
|
+
import {InternationalizationProvider} from '../i18n';
|
|
7
8
|
|
|
8
9
|
// Mock showModal/close for jsdom
|
|
9
10
|
beforeEach(() => {
|
|
@@ -27,6 +28,17 @@ function politeRegion(): HTMLElement | null {
|
|
|
27
28
|
return document.querySelector('[data-astryx-live-region="polite"]');
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
// Both position messages, supplied by the test. Overriding the pair means an
|
|
32
|
+
// assertion also proves which of the two keys the component reached for.
|
|
33
|
+
const POSITION_MESSAGES = {
|
|
34
|
+
fr: {
|
|
35
|
+
'@astryx.lightbox.mediaPosition':
|
|
36
|
+
'{alt}, vue {index, number} sur {total, number}',
|
|
37
|
+
'@astryx.lightbox.imagePosition':
|
|
38
|
+
'Photo {index, number} sur {total, number}',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
30
42
|
describe('Lightbox', () => {
|
|
31
43
|
it('renders as a dialog element', () => {
|
|
32
44
|
render(
|
|
@@ -320,47 +332,53 @@ describe('Lightbox', () => {
|
|
|
320
332
|
|
|
321
333
|
it('announces the new image and position when navigating next via button', async () => {
|
|
322
334
|
render(
|
|
323
|
-
<
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
335
|
+
<InternationalizationProvider locale="fr" overrides={POSITION_MESSAGES}>
|
|
336
|
+
<Lightbox
|
|
337
|
+
isOpen={true}
|
|
338
|
+
onOpenChange={() => {}}
|
|
339
|
+
media={media}
|
|
340
|
+
defaultIndex={0}
|
|
341
|
+
/>
|
|
342
|
+
</InternationalizationProvider>,
|
|
329
343
|
);
|
|
330
344
|
fireEvent.click(screen.getByLabelText('Next'));
|
|
331
345
|
await waitFor(() => {
|
|
332
|
-
expect(politeRegion()).
|
|
346
|
+
expect(politeRegion()?.textContent).toBe('Image B, vue 2 sur 3');
|
|
333
347
|
});
|
|
334
348
|
});
|
|
335
349
|
|
|
336
350
|
it('announces the new image and position when navigating via arrow keys', async () => {
|
|
337
351
|
render(
|
|
338
|
-
<
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
352
|
+
<InternationalizationProvider locale="fr" overrides={POSITION_MESSAGES}>
|
|
353
|
+
<Lightbox
|
|
354
|
+
isOpen={true}
|
|
355
|
+
onOpenChange={() => {}}
|
|
356
|
+
media={media}
|
|
357
|
+
defaultIndex={1}
|
|
358
|
+
/>
|
|
359
|
+
</InternationalizationProvider>,
|
|
344
360
|
);
|
|
345
361
|
const dialog = document.querySelector('dialog')!;
|
|
346
362
|
fireEvent.keyDown(dialog, {key: 'ArrowRight'});
|
|
347
363
|
await waitFor(() => {
|
|
348
|
-
expect(politeRegion()).
|
|
364
|
+
expect(politeRegion()?.textContent).toBe('Image C, vue 3 sur 3');
|
|
349
365
|
});
|
|
350
366
|
});
|
|
351
367
|
|
|
352
368
|
it('announces the new image and position when navigating prev', async () => {
|
|
353
369
|
render(
|
|
354
|
-
<
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
370
|
+
<InternationalizationProvider locale="fr" overrides={POSITION_MESSAGES}>
|
|
371
|
+
<Lightbox
|
|
372
|
+
isOpen={true}
|
|
373
|
+
onOpenChange={() => {}}
|
|
374
|
+
media={media}
|
|
375
|
+
defaultIndex={2}
|
|
376
|
+
/>
|
|
377
|
+
</InternationalizationProvider>,
|
|
360
378
|
);
|
|
361
379
|
fireEvent.click(screen.getByLabelText('Previous'));
|
|
362
380
|
await waitFor(() => {
|
|
363
|
-
expect(politeRegion()).
|
|
381
|
+
expect(politeRegion()?.textContent).toBe('Image B, vue 2 sur 3');
|
|
364
382
|
});
|
|
365
383
|
});
|
|
366
384
|
|
|
@@ -370,16 +388,19 @@ describe('Lightbox', () => {
|
|
|
370
388
|
{src: '/b.jpg', alt: ''},
|
|
371
389
|
];
|
|
372
390
|
render(
|
|
373
|
-
<
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
391
|
+
<InternationalizationProvider locale="fr" overrides={POSITION_MESSAGES}>
|
|
392
|
+
<Lightbox
|
|
393
|
+
isOpen={true}
|
|
394
|
+
onOpenChange={() => {}}
|
|
395
|
+
media={unlabeled}
|
|
396
|
+
defaultIndex={0}
|
|
397
|
+
/>
|
|
398
|
+
</InternationalizationProvider>,
|
|
379
399
|
);
|
|
380
400
|
fireEvent.click(screen.getByLabelText('Next'));
|
|
381
401
|
await waitFor(() => {
|
|
382
|
-
|
|
402
|
+
// imagePosition, not a mediaPosition with an empty {alt}.
|
|
403
|
+
expect(politeRegion()?.textContent).toBe('Photo 2 sur 2');
|
|
383
404
|
});
|
|
384
405
|
});
|
|
385
406
|
|
|
@@ -378,9 +378,13 @@ export function Lightbox({
|
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
380
|
const item = mediaArray[Math.min(index, mediaArray.length - 1)];
|
|
381
|
-
const position =
|
|
382
|
-
announce(
|
|
383
|
-
|
|
381
|
+
const position = {index: index + 1, total: mediaArray.length};
|
|
382
|
+
announce(
|
|
383
|
+
item?.alt
|
|
384
|
+
? t('@astryx.lightbox.mediaPosition', {alt: item.alt, ...position})
|
|
385
|
+
: t('@astryx.lightbox.imagePosition', position),
|
|
386
|
+
);
|
|
387
|
+
}, [index, isOpen, announce, mediaArray, t]);
|
|
384
388
|
|
|
385
389
|
// Open/close dialog
|
|
386
390
|
useIsomorphicLayoutEffect(() => {
|