@astryxdesign/core 0.4.3 → 0.4.4-canary.0f4d45f
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 +66 -0
- package/dist/BottomSheet/BottomSheet.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheet.js +392 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts +60 -0
- package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -0
- package/dist/BottomSheet/BottomSheetPanel.js +398 -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 +72 -0
- package/dist/BottomSheet/snapOffsets.d.ts.map +1 -0
- package/dist/BottomSheet/snapOffsets.js +130 -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 +180 -0
- package/dist/BottomSheet/useSheetGestures.d.ts.map +1 -0
- package/dist/BottomSheet/useSheetGestures.js +989 -0
- package/dist/Chat/ChatComposerInput.d.ts.map +1 -1
- package/dist/Chat/ChatComposerInput.js +3 -4
- package/dist/ComplexSelector/ComplexSelector.d.ts.map +1 -1
- package/dist/ComplexSelector/ComplexSelector.js +12 -6
- 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 +9 -1
- package/dist/DateTimeInput/DateTimeInput.d.ts.map +1 -1
- package/dist/DateTimeInput/DateTimeInput.js +31 -1
- package/dist/Dialog/Dialog.d.ts.map +1 -1
- package/dist/Dialog/Dialog.js +2 -1
- 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/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 +21 -7
- package/dist/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/NumberInput/NumberInput.js +9 -1
- package/dist/PowerSearch/PowerSearchEditPopover.js +1 -1
- package/dist/Selector/Selector.d.ts.map +1 -1
- package/dist/Selector/Selector.js +14 -3
- 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 +5 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.d.ts.map +1 -1
- package/dist/Table/plugins/rowExpansion/useTableRowExpansion.js +7 -2
- package/dist/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/TimeInput/TimeInput.js +8 -1
- 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/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/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 +48 -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 +36 -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 +266 -0
- package/src/BottomSheet/BottomSheet.test.tsx +2114 -0
- package/src/BottomSheet/BottomSheet.tsx +545 -0
- package/src/BottomSheet/BottomSheetPanel.test.tsx +240 -0
- package/src/BottomSheet/BottomSheetPanel.tsx +547 -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 +15 -0
- package/src/BottomSheet/snapOffsets.test.ts +187 -0
- package/src/BottomSheet/snapOffsets.ts +159 -0
- package/src/BottomSheet/useMobileKeyboard.ts +499 -0
- package/src/BottomSheet/useSheetGestures.test.ts +1059 -0
- package/src/BottomSheet/useSheetGestures.ts +1459 -0
- package/src/Chat/ChatComposerInput.tsx +3 -4
- package/src/ComplexSelector/ComplexSelector.tsx +12 -5
- package/src/ContextMenu/ContextMenu.tsx +4 -2
- package/src/DateInput/DateInput.test.tsx +21 -0
- package/src/DateInput/DateInput.tsx +9 -1
- package/src/DateTimeInput/DateTimeInput.doc.mjs +4 -0
- package/src/DateTimeInput/DateTimeInput.test.tsx +137 -0
- package/src/DateTimeInput/DateTimeInput.tsx +39 -2
- package/src/Dialog/Dialog.tsx +2 -1
- package/src/Field/Field.doc.mjs +1 -0
- 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/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 +22 -8
- package/src/NumberInput/NumberInput.test.tsx +18 -0
- package/src/NumberInput/NumberInput.tsx +9 -1
- package/src/PowerSearch/PowerSearchEditPopover.tsx +1 -1
- package/src/Selector/Selector.test.tsx +85 -26
- package/src/Selector/Selector.tsx +13 -4
- 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 +7 -0
- package/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx +20 -2
- package/src/TimeInput/TimeInput.test.tsx +23 -0
- package/src/TimeInput/TimeInput.tsx +8 -0
- 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/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/dist/astryx.umd.js +0 -147
- package/dist/astryx.umd.js.map +0 -7
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from '../Layer/useLayer';
|
|
29
29
|
import {layerAnimations} from '../Layer/layerAnimations.stylex';
|
|
30
30
|
import {themeProps} from '../utils/themeProps';
|
|
31
|
+
import {isImeKeyEvent} from '../utils/ime';
|
|
31
32
|
import {
|
|
32
33
|
colorVars,
|
|
33
34
|
radiusVars,
|
|
@@ -454,7 +455,9 @@ export function useTooltip(options: TooltipOptions = {}): TooltipReturn {
|
|
|
454
455
|
if (e.key !== 'Escape') {
|
|
455
456
|
return;
|
|
456
457
|
}
|
|
457
|
-
if (e
|
|
458
|
+
if (isImeKeyEvent(e)) {
|
|
459
|
+
// Ignore Escape that is committing/cancelling an IME composition;
|
|
460
|
+
// see utils/ime.ts for why.
|
|
458
461
|
return;
|
|
459
462
|
}
|
|
460
463
|
clearTimeouts();
|
|
@@ -30,7 +30,7 @@ import * as stylex from '@stylexjs/stylex';
|
|
|
30
30
|
import type {StyleXStyles} from '@stylexjs/stylex';
|
|
31
31
|
import {usePopover} from '../Popover/usePopover';
|
|
32
32
|
import {useAnnounce} from '../hooks/useAnnounce';
|
|
33
|
-
import {isImeKeyEvent} from '../
|
|
33
|
+
import {isImeKeyEvent} from '../utils/ime';
|
|
34
34
|
import {TypeaheadItem} from './TypeaheadItem';
|
|
35
35
|
import {Icon} from '../Icon';
|
|
36
36
|
import {
|
|
@@ -449,7 +449,7 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({
|
|
|
449
449
|
announce(
|
|
450
450
|
shown.length === 0
|
|
451
451
|
? emptySearchResultsText
|
|
452
|
-
:
|
|
452
|
+
: t('@astryx.typeahead.resultCount', {count: shown.length}),
|
|
453
453
|
);
|
|
454
454
|
}
|
|
455
455
|
} catch {
|
|
@@ -464,7 +464,14 @@ export const BaseTypeahead = function BaseTypeahead<T extends SearchableItem>({
|
|
|
464
464
|
}
|
|
465
465
|
}
|
|
466
466
|
},
|
|
467
|
-
[
|
|
467
|
+
[
|
|
468
|
+
searchSource,
|
|
469
|
+
maxMenuItems,
|
|
470
|
+
showLayer,
|
|
471
|
+
announce,
|
|
472
|
+
emptySearchResultsText,
|
|
473
|
+
t,
|
|
474
|
+
],
|
|
468
475
|
);
|
|
469
476
|
|
|
470
477
|
// Perform bootstrap
|
|
@@ -23,6 +23,7 @@ import userEvent from '@testing-library/user-event';
|
|
|
23
23
|
import {Typeahead} from './Typeahead';
|
|
24
24
|
import {BaseTypeahead} from './BaseTypeahead';
|
|
25
25
|
import type {SearchSource, SearchableItem} from './types';
|
|
26
|
+
import {InternationalizationProvider} from '../i18n';
|
|
26
27
|
|
|
27
28
|
// Store original matches to restore later
|
|
28
29
|
const originalMatches = HTMLElement.prototype.matches;
|
|
@@ -132,21 +133,94 @@ describe('BaseTypeahead', () => {
|
|
|
132
133
|
|
|
133
134
|
it('announces the result count to a live region (comboboxes-6)', async () => {
|
|
134
135
|
render(
|
|
135
|
-
<
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
<InternationalizationProvider
|
|
137
|
+
locale="fr"
|
|
138
|
+
overrides={{
|
|
139
|
+
fr: {
|
|
140
|
+
'@astryx.typeahead.resultCount':
|
|
141
|
+
'{count, number} {count, plural, one {résultat} other {résultats}}',
|
|
142
|
+
},
|
|
143
|
+
}}>
|
|
144
|
+
<BaseTypeahead
|
|
145
|
+
searchSource={fruitSource}
|
|
146
|
+
value={null}
|
|
147
|
+
onChange={() => {}}
|
|
148
|
+
debounceMs={0}
|
|
149
|
+
/>
|
|
150
|
+
</InternationalizationProvider>,
|
|
141
151
|
);
|
|
142
152
|
const input = screen.getByRole('combobox');
|
|
153
|
+
// "Ap" matches Apple only — the singular ICU branch.
|
|
143
154
|
fireEvent.change(input, {target: {value: 'Ap'}});
|
|
144
155
|
|
|
145
156
|
await waitFor(() => {
|
|
146
157
|
const region = document.querySelector(
|
|
147
158
|
'[data-astryx-live-region="polite"]',
|
|
148
159
|
);
|
|
149
|
-
|
|
160
|
+
// Exact, so the plural branch ("1 résultats") would fail.
|
|
161
|
+
expect(region?.textContent).toBe('1 résultat');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('announces the plural result count', async () => {
|
|
166
|
+
render(
|
|
167
|
+
<InternationalizationProvider
|
|
168
|
+
locale="fr"
|
|
169
|
+
overrides={{
|
|
170
|
+
fr: {
|
|
171
|
+
'@astryx.typeahead.resultCount':
|
|
172
|
+
'{count, number} {count, plural, one {résultat} other {résultats}}',
|
|
173
|
+
},
|
|
174
|
+
}}>
|
|
175
|
+
<BaseTypeahead
|
|
176
|
+
searchSource={fruitSource}
|
|
177
|
+
value={null}
|
|
178
|
+
onChange={() => {}}
|
|
179
|
+
debounceMs={0}
|
|
180
|
+
/>
|
|
181
|
+
</InternationalizationProvider>,
|
|
182
|
+
);
|
|
183
|
+
const input = screen.getByRole('combobox');
|
|
184
|
+
// "err" matches Cherry and Elderberry.
|
|
185
|
+
fireEvent.change(input, {target: {value: 'err'}});
|
|
186
|
+
|
|
187
|
+
await waitFor(() => {
|
|
188
|
+
const region = document.querySelector(
|
|
189
|
+
'[data-astryx-live-region="polite"]',
|
|
190
|
+
);
|
|
191
|
+
expect(region?.textContent).toBe('2 résultats');
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('speaks the result count from a provider catalog', async () => {
|
|
196
|
+
render(
|
|
197
|
+
<InternationalizationProvider
|
|
198
|
+
locale="fr"
|
|
199
|
+
messages={{
|
|
200
|
+
fr: {
|
|
201
|
+
'@astryx.typeahead.resultCount': {
|
|
202
|
+
defaultMessage:
|
|
203
|
+
'{count, number} {count, plural, one {résultat} other {résultats}}',
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
}}>
|
|
207
|
+
<BaseTypeahead
|
|
208
|
+
searchSource={fruitSource}
|
|
209
|
+
value={null}
|
|
210
|
+
onChange={() => {}}
|
|
211
|
+
debounceMs={0}
|
|
212
|
+
/>
|
|
213
|
+
</InternationalizationProvider>,
|
|
214
|
+
);
|
|
215
|
+
const input = screen.getByRole('combobox');
|
|
216
|
+
fireEvent.change(input, {target: {value: 'err'}});
|
|
217
|
+
|
|
218
|
+
await waitFor(() => {
|
|
219
|
+
const region = document.querySelector(
|
|
220
|
+
'[data-astryx-live-region="polite"]',
|
|
221
|
+
);
|
|
222
|
+
// Same key through the catalog path rather than `overrides`.
|
|
223
|
+
expect(region?.textContent).toBe('2 résultats');
|
|
150
224
|
});
|
|
151
225
|
});
|
|
152
226
|
|
|
@@ -796,6 +870,41 @@ describe('Typeahead edit mode', () => {
|
|
|
796
870
|
// onChange should not have been called — value restored
|
|
797
871
|
expect(onChange).not.toHaveBeenCalled();
|
|
798
872
|
});
|
|
873
|
+
|
|
874
|
+
it('does not exit edit mode on a composing Escape (IME)', async () => {
|
|
875
|
+
const onChange = vi.fn();
|
|
876
|
+
render(
|
|
877
|
+
<Typeahead
|
|
878
|
+
label="Fruit"
|
|
879
|
+
searchSource={fruitSource}
|
|
880
|
+
value={fruits[0]}
|
|
881
|
+
onChange={onChange}
|
|
882
|
+
/>,
|
|
883
|
+
);
|
|
884
|
+
|
|
885
|
+
// Enter edit mode by clicking the token; the input uncollapses and
|
|
886
|
+
// rejoins the Tab order (tabindex is cleared).
|
|
887
|
+
const tokenText = screen.getByText(fruits[0].label);
|
|
888
|
+
fireEvent.click(tokenText.closest('div')!);
|
|
889
|
+
await act(async () => {
|
|
890
|
+
await new Promise(r => requestAnimationFrame(r));
|
|
891
|
+
});
|
|
892
|
+
const input = screen.getByRole('combobox');
|
|
893
|
+
expect(input).not.toHaveAttribute('tabindex', '-1');
|
|
894
|
+
|
|
895
|
+
// BaseTypeahead invokes this external handler before its own IME guard, so
|
|
896
|
+
// a composing Escape (isComposing / legacy keyCode 229) — which an IME uses
|
|
897
|
+
// to cancel the pending candidate — must not exit edit mode here.
|
|
898
|
+
fireEvent.keyDown(input, {key: 'Escape', isComposing: true});
|
|
899
|
+
expect(screen.getByRole('combobox')).not.toHaveAttribute('tabindex', '-1');
|
|
900
|
+
fireEvent.keyDown(input, {key: 'Escape', keyCode: 229});
|
|
901
|
+
expect(screen.getByRole('combobox')).not.toHaveAttribute('tabindex', '-1');
|
|
902
|
+
|
|
903
|
+
// A real, non-composing Escape still exits edit mode: the token is
|
|
904
|
+
// restored and the collapsed input drops back out of the Tab order.
|
|
905
|
+
fireEvent.keyDown(input, {key: 'Escape'});
|
|
906
|
+
expect(screen.getByRole('combobox')).toHaveAttribute('tabindex', '-1');
|
|
907
|
+
});
|
|
799
908
|
});
|
|
800
909
|
|
|
801
910
|
describe('Typeahead collapsed input tab order', () => {
|
|
@@ -45,7 +45,7 @@ import {VisuallyHidden} from '../VisuallyHidden';
|
|
|
45
45
|
import {spacingVars, sizeVars} from '../theme/tokens.stylex';
|
|
46
46
|
import {groupStyles} from '../InputGroup/groupStyles';
|
|
47
47
|
import {useInputGroup} from '../InputGroup/InputGroupContext';
|
|
48
|
-
import {getInputARIA, mergeProps, mergeRefs} from '../utils';
|
|
48
|
+
import {getInputARIA, isImeKeyEvent, mergeProps, mergeRefs} from '../utils';
|
|
49
49
|
import type {BaseProps} from '../BaseProps';
|
|
50
50
|
import type {SizeValue} from '../utils/types';
|
|
51
51
|
import type {SearchableItem, SearchSource} from './types';
|
|
@@ -369,6 +369,15 @@ export function Typeahead<T extends SearchableItem>({
|
|
|
369
369
|
// Handle Escape during edit mode — restore token
|
|
370
370
|
const handleKeyDown = useCallback(
|
|
371
371
|
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
372
|
+
// BaseTypeahead invokes this external handler *before* its own IME
|
|
373
|
+
// guard, so we must guard here too: an IME candidate window uses Escape
|
|
374
|
+
// to cancel the pending composition, and that composing Escape fires
|
|
375
|
+
// before compositionend. Without this, a Korean/Japanese/Chinese user
|
|
376
|
+
// cancelling a candidate would instead exit edit mode and blur the
|
|
377
|
+
// field. See utils/ime.ts.
|
|
378
|
+
if (isImeKeyEvent(e.nativeEvent)) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
372
381
|
if (e.key === 'Escape' && editingValue) {
|
|
373
382
|
e.preventDefault();
|
|
374
383
|
setIsEditing(false);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file stubMatchMedia.test.ts
|
|
5
|
+
* @input Uses vitest, stubMatchMedia
|
|
6
|
+
* @output Unit coverage for the shared query-aware matchMedia stub
|
|
7
|
+
* @position Testing; guards the helper other suites trust to route queries
|
|
8
|
+
*
|
|
9
|
+
* The helper exists because a stub that ignores its query silently reroutes
|
|
10
|
+
* code branching on a different one — the failure mode leaves every test
|
|
11
|
+
* green. A helper sold on that promise has to be held to it, so these assert
|
|
12
|
+
* the routing itself rather than any component behaviour.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {describe, it, expect, afterEach, vi} from 'vitest';
|
|
16
|
+
import {stubMatchMedia} from './stubMatchMedia';
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
vi.unstubAllGlobals();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('stubMatchMedia', () => {
|
|
23
|
+
it('routes prefers-reduced-motion independently of every other query', () => {
|
|
24
|
+
// The exact combination the blanket stub could not express: below a
|
|
25
|
+
// breakpoint (matches) while motion is NOT reduced.
|
|
26
|
+
stubMatchMedia({reduceMotion: false, matches: true});
|
|
27
|
+
|
|
28
|
+
expect(matchMedia('(prefers-reduced-motion: reduce)').matches).toBe(false);
|
|
29
|
+
expect(matchMedia('(max-width: 768px)').matches).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('answers no-preference as the opposite of reduce', () => {
|
|
33
|
+
// Two spellings, opposite meanings. A substring test on
|
|
34
|
+
// 'prefers-reduced-motion' alone would hand both the same answer.
|
|
35
|
+
stubMatchMedia({reduceMotion: true});
|
|
36
|
+
|
|
37
|
+
expect(matchMedia('(prefers-reduced-motion: reduce)').matches).toBe(true);
|
|
38
|
+
expect(matchMedia('(prefers-reduced-motion: no-preference)').matches).toBe(
|
|
39
|
+
false,
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('treats the bare preference query as reduce', () => {
|
|
44
|
+
stubMatchMedia({reduceMotion: true});
|
|
45
|
+
expect(matchMedia('(prefers-reduced-motion)').matches).toBe(true);
|
|
46
|
+
|
|
47
|
+
stubMatchMedia({reduceMotion: false});
|
|
48
|
+
expect(matchMedia('(prefers-reduced-motion)').matches).toBe(false);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('defaults to full motion and matching everything else', () => {
|
|
52
|
+
stubMatchMedia();
|
|
53
|
+
|
|
54
|
+
expect(matchMedia('(prefers-reduced-motion: reduce)').matches).toBe(false);
|
|
55
|
+
expect(matchMedia('(max-width: 768px)').matches).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('lets a non-motion query be answered false', () => {
|
|
59
|
+
// Above the breakpoint, motion still reduced — the other axis of the
|
|
60
|
+
// combination, so neither knob can be quietly driving both.
|
|
61
|
+
stubMatchMedia({reduceMotion: true, matches: false});
|
|
62
|
+
|
|
63
|
+
expect(matchMedia('(prefers-reduced-motion: reduce)').matches).toBe(true);
|
|
64
|
+
expect(matchMedia('(max-width: 768px)').matches).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('echoes the query and exposes the listener API components subscribe to', () => {
|
|
68
|
+
stubMatchMedia();
|
|
69
|
+
const mql = matchMedia('(max-width: 768px)');
|
|
70
|
+
|
|
71
|
+
// useMediaQuery subscribes; a stub without these throws on mount rather
|
|
72
|
+
// than failing an assertion, which reads as an unrelated crash.
|
|
73
|
+
expect(mql.media).toBe('(max-width: 768px)');
|
|
74
|
+
expect(typeof mql.addEventListener).toBe('function');
|
|
75
|
+
expect(typeof mql.removeEventListener).toBe('function');
|
|
76
|
+
expect(typeof mql.addListener).toBe('function');
|
|
77
|
+
expect(typeof mql.removeListener).toBe('function');
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file stubMatchMedia.ts
|
|
5
|
+
* @input Uses vitest
|
|
6
|
+
* @output stubMatchMedia — a query-aware window.matchMedia stub
|
|
7
|
+
* @position Shared test helper; imported by component tests that render below
|
|
8
|
+
* a breakpoint while also exercising motion-sensitive behaviour
|
|
9
|
+
*
|
|
10
|
+
* jsdom has no matchMedia, so tests stub it. The usual stub answers every query
|
|
11
|
+
* with one boolean:
|
|
12
|
+
*
|
|
13
|
+
* vi.stubGlobal('matchMedia', vi.fn().mockReturnValue({matches: true, ...}))
|
|
14
|
+
*
|
|
15
|
+
* That is enough to put AppShell below its breakpoint — and it silently also
|
|
16
|
+
* matches `prefers-reduced-motion`, rerouting any code that branches on motion.
|
|
17
|
+
* MobileNav's close delay is capped at 0 under reduced motion, so a suite using
|
|
18
|
+
* the blanket stub runs against an immediate close while its test names claim
|
|
19
|
+
* it is exercising the real delay. The failure mode is invisible: every test
|
|
20
|
+
* still passes.
|
|
21
|
+
*
|
|
22
|
+
* So the two answers are separate knobs here. `reduceMotion` answers
|
|
23
|
+
* `prefers-reduced-motion` only; `matches` answers everything else (breakpoint
|
|
24
|
+
* width queries, which tests below a breakpoint want to be true).
|
|
25
|
+
*
|
|
26
|
+
* SYNC: When modified, update this header.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import {vi} from 'vitest';
|
|
30
|
+
|
|
31
|
+
export interface StubMatchMediaOptions {
|
|
32
|
+
/** Whether the user prefers reduced motion. */
|
|
33
|
+
reduceMotion?: boolean;
|
|
34
|
+
/** Answer for every other query — width breakpoints, hover, etc. */
|
|
35
|
+
matches?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Answer a `prefers-reduced-motion` query, or null if it isn't one.
|
|
40
|
+
*
|
|
41
|
+
* The preference has two spellings and they are opposites, so a single
|
|
42
|
+
* `includes('prefers-reduced-motion')` would answer `no-preference` with the
|
|
43
|
+
* value meant for `reduce` — the same answer-without-reading mistake this
|
|
44
|
+
* helper exists to prevent. Core only queries `reduce` today (MobileNav,
|
|
45
|
+
* Carousel); handling both is what keeps that true if one changes.
|
|
46
|
+
*/
|
|
47
|
+
function answerReducedMotion(
|
|
48
|
+
query: string,
|
|
49
|
+
reduceMotion: boolean,
|
|
50
|
+
): boolean | null {
|
|
51
|
+
if (query.includes('prefers-reduced-motion: reduce')) {
|
|
52
|
+
return reduceMotion;
|
|
53
|
+
}
|
|
54
|
+
if (query.includes('prefers-reduced-motion: no-preference')) {
|
|
55
|
+
return !reduceMotion;
|
|
56
|
+
}
|
|
57
|
+
// Bare `(prefers-reduced-motion)` is true for any value other than
|
|
58
|
+
// no-preference, i.e. the same as `reduce`.
|
|
59
|
+
if (query.includes('prefers-reduced-motion')) {
|
|
60
|
+
return reduceMotion;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Install a `window.matchMedia` stub whose answer depends on the query.
|
|
67
|
+
*
|
|
68
|
+
* Call from `beforeEach` (or inside a test that needs different motion
|
|
69
|
+
* settings) and pair with `vi.unstubAllGlobals()` in `afterEach`.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```
|
|
73
|
+
* beforeEach(() => {
|
|
74
|
+
* stubMatchMedia({reduceMotion: false});
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export function stubMatchMedia({
|
|
79
|
+
reduceMotion = false,
|
|
80
|
+
matches = true,
|
|
81
|
+
}: StubMatchMediaOptions = {}): void {
|
|
82
|
+
vi.stubGlobal(
|
|
83
|
+
'matchMedia',
|
|
84
|
+
vi.fn((query: string) => ({
|
|
85
|
+
matches: answerReducedMotion(query, reduceMotion) ?? matches,
|
|
86
|
+
media: query,
|
|
87
|
+
onchange: null,
|
|
88
|
+
addEventListener: vi.fn(),
|
|
89
|
+
removeEventListener: vi.fn(),
|
|
90
|
+
addListener: vi.fn(),
|
|
91
|
+
removeListener: vi.fn(),
|
|
92
|
+
dispatchEvent: vi.fn(),
|
|
93
|
+
})),
|
|
94
|
+
);
|
|
95
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
* SYNC: When modified, update this header
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
export {
|
|
15
|
-
hasActiveFocusTrapEscape,
|
|
16
|
-
isImeKeyEvent,
|
|
17
|
-
useFocusTrap,
|
|
18
|
-
} from './useFocusTrap';
|
|
14
|
+
export {hasActiveFocusTrapEscape, useFocusTrap} from './useFocusTrap';
|
|
19
15
|
export type {UseFocusTrapOptions, UseFocusTrapReturn} from './useFocusTrap';
|
|
20
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Import from `@astryxdesign/core/utils` instead — this is a pure
|
|
19
|
+
* predicate, not a hook, and the `hooks` barrel is a `'use client'` boundary.
|
|
20
|
+
* Re-exported here for one release so consumers can move; will be removed in
|
|
21
|
+
* an upcoming major.
|
|
22
|
+
*/
|
|
23
|
+
export {isImeKeyEvent} from '../utils/ime';
|
|
24
|
+
|
|
21
25
|
export {useAnnounce} from './useAnnounce';
|
|
22
26
|
export type {AnnounceFn, AnnouncePoliteness} from './useAnnounce';
|
|
23
27
|
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import {useCallback, useEffect, useRef} from 'react';
|
|
20
20
|
|
|
21
21
|
import {FOCUSABLE_SELECTOR} from './focusableSelector';
|
|
22
|
+
import {isImeKeyEvent} from '../utils/ime';
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* Module-level stack of active focus-trap Escape handlers.
|
|
@@ -94,20 +95,6 @@ export function hasActiveFocusTrapEscape(): boolean {
|
|
|
94
95
|
return escapeStack.length > 0;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
/**
|
|
98
|
-
* Whether an Escape keydown should be ignored because it is cancelling an
|
|
99
|
-
* in-progress IME composition. CJK/IME users press Escape to cancel
|
|
100
|
-
* composition; that must not close the surrounding overlay. `keyCode === 229`
|
|
101
|
-
* covers browsers that fire keydown before `isComposing` is set. Exported so
|
|
102
|
-
* other overlays (Dialog, Drawer, CommandPalette) share one definition.
|
|
103
|
-
*/
|
|
104
|
-
export function isImeKeyEvent(event: {
|
|
105
|
-
isComposing?: boolean;
|
|
106
|
-
keyCode?: number;
|
|
107
|
-
}): boolean {
|
|
108
|
-
return event.isComposing === true || event.keyCode === 229;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
98
|
/**
|
|
112
99
|
* Whether an element is currently perceivable/focusable — excludes ones hidden
|
|
113
100
|
* via `display:none`/`visibility:hidden` or inside an `inert`/`hidden` subtree,
|
|
@@ -159,6 +159,25 @@ describe('useInputStatusIcon — no dangling aria-describedby (WCAG 1.3.1)', ()
|
|
|
159
159
|
).not.toBeInTheDocument();
|
|
160
160
|
expectNoDanglingDescribedBy(container);
|
|
161
161
|
});
|
|
162
|
+
|
|
163
|
+
it('keeps the tooltip status button interactive inside a non-interactive trailing slot', () => {
|
|
164
|
+
// TextArea positions its trailing slot as an absolute overlay with
|
|
165
|
+
// `pointer-events: none` (correct for the decorative spinner/icon it was
|
|
166
|
+
// built for). The focusable status button owns its own interactivity so
|
|
167
|
+
// hover still opens the tooltip there — keyboard focus always worked, the
|
|
168
|
+
// pointer path did not until the button set `pointer-events: auto`.
|
|
169
|
+
render(
|
|
170
|
+
<TextArea
|
|
171
|
+
label="Field"
|
|
172
|
+
value=""
|
|
173
|
+
onChange={() => {}}
|
|
174
|
+
status={{type: 'error', message: 'Message'}}
|
|
175
|
+
statusVariant="tooltip"
|
|
176
|
+
/>,
|
|
177
|
+
);
|
|
178
|
+
const statusButton = screen.getByRole('button', {name: 'Error details'});
|
|
179
|
+
expect(statusButton).toHaveStyle({pointerEvents: 'auto'});
|
|
180
|
+
});
|
|
162
181
|
});
|
|
163
182
|
|
|
164
183
|
describe('useInputStatusIcon — input-status-icon theme target', () => {
|
|
@@ -82,6 +82,13 @@ const styles = stylex.create({
|
|
|
82
82
|
background: 'none',
|
|
83
83
|
color: 'inherit',
|
|
84
84
|
cursor: 'pointer',
|
|
85
|
+
// Own the interactivity so the tooltip opens on hover even when the field
|
|
86
|
+
// renders this affordance inside a non-interactive trailing slot. TextArea
|
|
87
|
+
// positions its end slot as an absolute overlay with `pointer-events: none`
|
|
88
|
+
// (right for the decorative spinner/icon it was built for), which otherwise
|
|
89
|
+
// swallows this button's hover — keyboard focus still worked, pointer did
|
|
90
|
+
// not.
|
|
91
|
+
pointerEvents: 'auto',
|
|
85
92
|
borderRadius: radiusVars['--radius-full'],
|
|
86
93
|
// Not the shared offset: this button sits inside the field, and measured at
|
|
87
94
|
// the standard 3px its ring crosses the field border.
|
package/src/index.ts
CHANGED
package/src/theme/defineTheme.ts
CHANGED
|
@@ -248,20 +248,38 @@ export interface DefineThemeInput {
|
|
|
248
248
|
*/
|
|
249
249
|
radius?: RadiusScaleConfig;
|
|
250
250
|
/**
|
|
251
|
-
* Color scale configuration. Generates color token overrides from
|
|
252
|
-
*
|
|
251
|
+
* Color scale configuration. Generates color token overrides from an
|
|
252
|
+
* accent seed using the HCT perceptual color model.
|
|
253
253
|
*
|
|
254
254
|
* Only generates tokens derivable from the accent — status colors,
|
|
255
255
|
* categorical hues, and fixed tokens (on-dark/on-light) use defaults.
|
|
256
|
-
*
|
|
256
|
+
*
|
|
257
|
+
* `accent` accepts a single hex (same seed for both color schemes) or a
|
|
258
|
+
* `[light, dark]` tuple, matching `TokenValue`. With a tuple, the light
|
|
259
|
+
* scheme's full palette derives from the light seed and the dark
|
|
260
|
+
* scheme's from the dark seed.
|
|
257
261
|
*
|
|
258
262
|
* `accent` is optional — omit it for a neutral-only theme, which keeps
|
|
259
263
|
* the default accent tokens and only themes the neutrals.
|
|
260
264
|
*
|
|
265
|
+
* Precedence vs `tokens`: explicit `tokens` entries win over generated
|
|
266
|
+
* values, token by token. Because `--color-accent-muted`,
|
|
267
|
+
* `--color-text-accent` and `--color-icon-accent` are generated as
|
|
268
|
+
* `var(--color-accent)` references, a `tokens['--color-accent']`
|
|
269
|
+
* override re-points them at runtime. `--color-on-accent` does NOT
|
|
270
|
+
* follow: it is baked from the `color.accent` seed (a contrast
|
|
271
|
+
* computation CSS cannot express), so overriding the accent through
|
|
272
|
+
* `tokens` without also overriding `--color-on-accent` leaves the two
|
|
273
|
+
* out of sync. To re-seat the whole palette per scheme, prefer a tuple
|
|
274
|
+
* `color.accent` over the `tokens['--color-accent']` workaround.
|
|
275
|
+
*
|
|
261
276
|
* @example
|
|
262
|
-
* ```
|
|
277
|
+
* ```
|
|
263
278
|
* color: { accent: '#0064E0', neutralStyle: 'cool', contrast: 'standard' }
|
|
264
279
|
*
|
|
280
|
+
* // Per-scheme accents — light palette from the first seed, dark from the second
|
|
281
|
+
* color: { accent: ['#0064E0', '#48CAE4'] }
|
|
282
|
+
*
|
|
265
283
|
* // Neutral-only — accent tokens stay at their defaults
|
|
266
284
|
* color: { neutralStyle: 'warm' }
|
|
267
285
|
* ```
|