@spectral_labs/ui 1.7.0 → 1.8.0-next.0
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/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.md +201 -0
- package/package.json +8 -2
- package/dist/components/__tests__/overlay-scrim-source.test.js +0 -134
- package/dist/components/accordion/__tests__/AccordionTest.svelte +0 -31
- package/dist/components/accordion/__tests__/accordion.test.svelte.js +0 -139
- package/dist/components/alert-dialog/__tests__/AlertDialogTest.svelte +0 -28
- package/dist/components/alert-dialog/__tests__/alert-dialog.a11y.test.js +0 -42
- package/dist/components/alert-dialog/__tests__/alert-dialog.integration.test.svelte.js +0 -51
- package/dist/components/alert-dialog/__tests__/alert-dialog.test.svelte.js +0 -113
- package/dist/components/app-bar/__tests__/app-bar.test.svelte.js +0 -30
- package/dist/components/aspect-ratio/__tests__/aspect-ratio.test.svelte.js +0 -22
- package/dist/components/avatar/__tests__/avatar.test.svelte.js +0 -26
- package/dist/components/badge/__tests__/badge.test.svelte.js +0 -30
- package/dist/components/bottom-sheet/__tests__/BottomSheetTest.svelte +0 -22
- package/dist/components/bottom-sheet/__tests__/bottom-sheet.test.svelte.js +0 -83
- package/dist/components/button/__tests__/button.test.svelte.js +0 -63
- package/dist/components/calendar/__tests__/CalendarTest.svelte +0 -56
- package/dist/components/calendar/__tests__/calendar.test.svelte.js +0 -190
- package/dist/components/card/__tests__/card.test.svelte.js +0 -30
- package/dist/components/checkbox/__tests__/checkbox.test.svelte.js +0 -44
- package/dist/components/chips/__tests__/chips.test.svelte.js +0 -26
- package/dist/components/collapsible/__tests__/CollapsibleTest.svelte +0 -18
- package/dist/components/collapsible/__tests__/collapsible.test.svelte.js +0 -125
- package/dist/components/combobox/__tests__/ComboboxTest.svelte +0 -40
- package/dist/components/combobox/__tests__/combobox.test.svelte.js +0 -255
- package/dist/components/command/__tests__/CommandInlineDirectTest.svelte +0 -29
- package/dist/components/command/__tests__/CommandInlineTest.svelte +0 -89
- package/dist/components/command/__tests__/CommandTest.svelte +0 -77
- package/dist/components/command/__tests__/command-inline.test.svelte.js +0 -392
- package/dist/components/command/__tests__/command-item-passthrough.test.svelte.js +0 -284
- package/dist/components/command/__tests__/command.a11y.test.js +0 -30
- package/dist/components/command/__tests__/command.integration.test.svelte.js +0 -68
- package/dist/components/command/__tests__/command.test.svelte.js +0 -230
- package/dist/components/context-menu/__tests__/ContextMenuNonInteractiveTest.svelte +0 -32
- package/dist/components/context-menu/__tests__/ContextMenuTest.svelte +0 -25
- package/dist/components/context-menu/__tests__/context-menu.test.svelte.js +0 -141
- package/dist/components/date-field/__tests__/DateFieldTest.svelte +0 -20
- package/dist/components/date-field/__tests__/date-field.test.svelte.js +0 -139
- package/dist/components/date-picker/__tests__/DatePickerTest.svelte +0 -20
- package/dist/components/date-picker/__tests__/date-picker.test.svelte.js +0 -190
- package/dist/components/date-range-field/__tests__/DateRangeFieldTest.svelte +0 -20
- package/dist/components/date-range-field/__tests__/date-range-field.test.svelte.js +0 -130
- package/dist/components/date-range-picker/__tests__/DateRangePickerTest.svelte +0 -18
- package/dist/components/date-range-picker/__tests__/date-range-picker.test.svelte.js +0 -156
- package/dist/components/dialog/__tests__/DialogTest.svelte +0 -34
- package/dist/components/dialog/__tests__/dialog.test.svelte.js +0 -184
- package/dist/components/drop-zone/__tests__/drop-zone.test.svelte.js +0 -26
- package/dist/components/dropdown-menu/__tests__/DropdownMenuRadioTest.svelte +0 -90
- package/dist/components/dropdown-menu/__tests__/DropdownMenuTest.svelte +0 -71
- package/dist/components/dropdown-menu/__tests__/dropdown-menu-radio-group.test.svelte.js +0 -306
- package/dist/components/dropdown-menu/__tests__/dropdown-menu.test.svelte.js +0 -567
- package/dist/components/empty-state/__tests__/empty-state.test.svelte.js +0 -26
- package/dist/components/fab/__tests__/fab.test.svelte.js +0 -30
- package/dist/components/field/__tests__/FieldTest.svelte +0 -26
- package/dist/components/field/__tests__/field.test.svelte.js +0 -74
- package/dist/components/grid-list/__tests__/GridListTest.svelte +0 -46
- package/dist/components/grid-list/__tests__/grid-list.test.svelte.js +0 -231
- package/dist/components/hover-card/__tests__/HoverCardTest.svelte +0 -30
- package/dist/components/hover-card/__tests__/hover-card.test.svelte.js +0 -236
- package/dist/components/indicator/__tests__/indicator.test.svelte.js +0 -30
- package/dist/components/input/__tests__/input.test.svelte.js +0 -67
- package/dist/components/label/__tests__/label.test.svelte.js +0 -22
- package/dist/components/language-select/__tests__/language-select.test.svelte.js +0 -199
- package/dist/components/language-select/__tests__/languages.test.js +0 -87
- package/dist/components/link-preview/__tests__/LinkPreviewTest.svelte +0 -37
- package/dist/components/link-preview/__tests__/link-preview.a11y.test.js +0 -28
- package/dist/components/link-preview/__tests__/link-preview.integration.test.svelte.js +0 -54
- package/dist/components/link-preview/__tests__/link-preview.test.svelte.js +0 -215
- package/dist/components/list/__tests__/list.test.svelte.js +0 -22
- package/dist/components/menubar/__tests__/MenubarTest.svelte +0 -52
- package/dist/components/menubar/__tests__/menubar.a11y.test.js +0 -28
- package/dist/components/menubar/__tests__/menubar.integration.test.svelte.js +0 -57
- package/dist/components/menubar/__tests__/menubar.test.svelte.js +0 -328
- package/dist/components/meter/__tests__/meter.test.svelte.js +0 -26
- package/dist/components/nav-bar/__tests__/nav-bar.test.svelte.js +0 -23
- package/dist/components/nav-drawer/__tests__/nav-drawer.test.svelte.js +0 -28
- package/dist/components/nav-rail/__tests__/nav-rail.test.svelte.js +0 -28
- package/dist/components/pagination/__tests__/pagination.test.svelte.js +0 -26
- package/dist/components/pin-input/__tests__/pin-input.test.svelte.js +0 -71
- package/dist/components/popover/__tests__/PopoverTest.svelte +0 -27
- package/dist/components/popover/__tests__/popover.test.svelte.js +0 -196
- package/dist/components/progress/__tests__/progress.test.svelte.js +0 -32
- package/dist/components/radio-group/__tests__/radio-group.test.svelte.js +0 -22
- package/dist/components/range-calendar/__tests__/RangeCalendarTest.svelte +0 -23
- package/dist/components/range-calendar/__tests__/range-calendar.test.svelte.js +0 -105
- package/dist/components/rating-group/__tests__/rating-group.test.svelte.js +0 -26
- package/dist/components/scroll-area/__tests__/scroll-area.test.svelte.js +0 -34
- package/dist/components/search-field/__tests__/SearchFieldTest.svelte +0 -34
- package/dist/components/search-field/__tests__/search-field.test.svelte.js +0 -118
- package/dist/components/select/__tests__/SelectLabelPersistenceTest.svelte +0 -31
- package/dist/components/select/__tests__/SelectTest.svelte +0 -33
- package/dist/components/select/__tests__/select.test.svelte.js +0 -221
- package/dist/components/separator/__tests__/separator.test.svelte.js +0 -39
- package/dist/components/sheet/__tests__/SheetTest.svelte +0 -34
- package/dist/components/sheet/__tests__/sheet.test.svelte.js +0 -193
- package/dist/components/side-sheet/__tests__/side-sheet.test.svelte.js +0 -138
- package/dist/components/sidebar/__tests__/SidebarFullTest.svelte +0 -45
- package/dist/components/sidebar/__tests__/SidebarTest.svelte +0 -9
- package/dist/components/sidebar/__tests__/sidebar.test.svelte.js +0 -186
- package/dist/components/simple-dialog/__tests__/SimpleDialogTest.svelte +0 -40
- package/dist/components/simple-dialog/__tests__/simple-dialog.test.svelte.js +0 -50
- package/dist/components/simple-tooltip/__tests__/SimpleTooltipTest.svelte +0 -19
- package/dist/components/simple-tooltip/__tests__/simple-tooltip.test.svelte.js +0 -61
- package/dist/components/slider/__tests__/slider.test.svelte.js +0 -42
- package/dist/components/sortable-list/__tests__/NestedSortableListTest.svelte +0 -49
- package/dist/components/sortable-list/__tests__/SortableListTest.svelte +0 -42
- package/dist/components/sortable-list/__tests__/sortable-list.nested.test.svelte.js +0 -112
- package/dist/components/sortable-list/__tests__/sortable-list.test.svelte.js +0 -175
- package/dist/components/splitter/__tests__/splitter.test.svelte.js +0 -26
- package/dist/components/switch/__tests__/switch.test.svelte.js +0 -44
- package/dist/components/table/__tests__/table.test.svelte.js +0 -22
- package/dist/components/tabs/__tests__/TabsTest.svelte +0 -32
- package/dist/components/tabs/__tests__/tabs.test.svelte.js +0 -227
- package/dist/components/textarea/__tests__/textarea.test.svelte.js +0 -55
- package/dist/components/time-field/__tests__/TimeFieldTest.svelte +0 -20
- package/dist/components/time-field/__tests__/time-field.test.svelte.js +0 -100
- package/dist/components/time-range-field/__tests__/TimeRangeFieldTest.svelte +0 -20
- package/dist/components/time-range-field/__tests__/time-range-field.test.svelte.js +0 -124
- package/dist/components/toast/__tests__/toast.test.svelte.js +0 -46
- package/dist/components/toggle/__tests__/toggle.test.svelte.js +0 -38
- package/dist/components/toggle-group/__tests__/toggle-group.test.svelte.js +0 -22
- package/dist/components/toolbar/__tests__/ToolbarCompositionTest.svelte +0 -18
- package/dist/components/toolbar/__tests__/ToolbarTabstopTest.svelte +0 -10
- package/dist/components/toolbar/__tests__/toolbar.test.svelte.js +0 -63
- package/dist/components/tooltip/__tests__/TooltipTest.svelte +0 -22
- package/dist/components/tooltip/__tests__/tooltip.test.svelte.js +0 -225
- package/dist/components/tree/__tests__/TreeLabelContentTest.svelte +0 -21
- package/dist/components/tree/__tests__/TreeTest.svelte +0 -24
- package/dist/components/tree/__tests__/tree.test.svelte.js +0 -229
- package/dist/components/virtualizer/__tests__/waterfall-layout.test.js +0 -82
- package/dist/internal/announcer/__tests__/announcer.test.js +0 -42
- package/dist/internal/dismissible-layer/__tests__/dismissible-layer.test.js +0 -196
- package/dist/internal/drag-drop/__tests__/auto-scroll.test.js +0 -104
- package/dist/internal/drag-drop/__tests__/drag-session.test.svelte.js +0 -803
- package/dist/internal/drag-drop/__tests__/drag-source.test.svelte.js +0 -130
- package/dist/internal/drag-drop/__tests__/drop-delegate.test.js +0 -223
- package/dist/internal/drag-drop/__tests__/types.test.js +0 -20
- package/dist/internal/escape-layer/__tests__/escape-layer.test.js +0 -113
- package/dist/internal/focus-scope/__tests__/focus-scope.test.js +0 -225
- package/dist/internal/grace-area/__tests__/grace-area.test.js +0 -67
- package/dist/internal/helpers/__tests__/helpers.test.js +0 -123
- package/dist/internal/portal/__tests__/PortalTest.svelte +0 -21
- package/dist/internal/portal/__tests__/portal.test.js +0 -29
- package/dist/internal/portal/__tests__/portal.test.svelte.js +0 -57
- package/dist/internal/scroll-lock/__tests__/scroll-lock.test.js +0 -160
- package/dist/internal/typeahead/__tests__/typeahead.test.js +0 -61
- package/src/themes/__tests__/carbon-dark-contrast.test.ts +0 -170
- package/src/themes/__tests__/generated-css-drift.test.ts +0 -53
- package/src/themes/__tests__/scrim-opaque.test.ts +0 -52
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import { flushSync, mount, unmount } from 'svelte';
|
|
2
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
-
import DropdownMenuRadioTest from './DropdownMenuRadioTest.svelte';
|
|
4
|
-
/**
|
|
5
|
-
* `DropdownMenu.RadioGroup` / `RadioItem` — the single-choice row family.
|
|
6
|
-
*
|
|
7
|
-
* These rows exist because a menu that offers "pick exactly one of N" had no
|
|
8
|
-
* honest markup here: `CheckboxItem` announces `menuitemcheckbox`, which tells
|
|
9
|
-
* a screen-reader user the options are independent when they are not.
|
|
10
|
-
*
|
|
11
|
-
* The suite also pins the two properties this family is REQUIRED to have from
|
|
12
|
-
* birth, and which the older rows lack (spectral-ui#201): consumer HTML
|
|
13
|
-
* attributes reach the DOM node, and a consumer event handler COMPOSES with
|
|
14
|
-
* the built-in one instead of being dropped.
|
|
15
|
-
*/
|
|
16
|
-
describe('dropdown-menu radio group', () => {
|
|
17
|
-
let target;
|
|
18
|
-
let instance;
|
|
19
|
-
function setup(props = {}) {
|
|
20
|
-
target = document.createElement('div');
|
|
21
|
-
document.body.appendChild(target);
|
|
22
|
-
instance = mount(DropdownMenuRadioTest, {
|
|
23
|
-
target,
|
|
24
|
-
props: { portalTo: target, ...props },
|
|
25
|
-
});
|
|
26
|
-
flushSync();
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
function radios() {
|
|
30
|
-
return Array.from(target.querySelectorAll('[role="menuitemradio"]'));
|
|
31
|
-
}
|
|
32
|
-
function radio(value) {
|
|
33
|
-
const el = target.querySelector(`[role="menuitemradio"][data-value="${value}"]`);
|
|
34
|
-
if (!el)
|
|
35
|
-
throw new Error(`no radio item for value "${value}"`);
|
|
36
|
-
return el;
|
|
37
|
-
}
|
|
38
|
-
/** Same idiom as `dropdown-menu.test.svelte.ts`: drive the REAL focused
|
|
39
|
-
* element, so the Content -> collection -> focus chain is exercised rather
|
|
40
|
-
* than merely inspected. */
|
|
41
|
-
function pressKey(key) {
|
|
42
|
-
const el = document.activeElement;
|
|
43
|
-
el.dispatchEvent(new KeyboardEvent('keydown', { key, bubbles: true }));
|
|
44
|
-
flushSync();
|
|
45
|
-
}
|
|
46
|
-
function activeValue() {
|
|
47
|
-
return document.activeElement?.getAttribute('data-value') ?? null;
|
|
48
|
-
}
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
if (instance)
|
|
51
|
-
unmount(instance);
|
|
52
|
-
instance = undefined;
|
|
53
|
-
target?.remove();
|
|
54
|
-
});
|
|
55
|
-
// ── ARIA ──────────────────────────────────────────────────────────────
|
|
56
|
-
it('wraps its rows in role="group" — never role="radiogroup", invalid inside a menu', () => {
|
|
57
|
-
setup();
|
|
58
|
-
expect(target.querySelector('.sp-dropdown-menu-radio-group')?.getAttribute('role')).toBe('group');
|
|
59
|
-
// The ratified contract FORBIDS `radiogroup`: a `menu` may only own
|
|
60
|
-
// menuitem / menuitemcheckbox / menuitemradio / group / separator.
|
|
61
|
-
expect(target.querySelector('[role="radiogroup"]')).toBeNull();
|
|
62
|
-
const items = radios();
|
|
63
|
-
expect(items).toHaveLength(3);
|
|
64
|
-
expect(items.map((el) => el.getAttribute('aria-checked'))).toEqual(['true', 'false', 'false']);
|
|
65
|
-
});
|
|
66
|
-
it('reflects the selected value in data-state, for styling parity with CheckboxItem', () => {
|
|
67
|
-
setup();
|
|
68
|
-
expect(radio('document').getAttribute('data-state')).toBe('checked');
|
|
69
|
-
expect(radio('placeholders').getAttribute('data-state')).toBe('unchecked');
|
|
70
|
-
});
|
|
71
|
-
it('moves the checked row when the PARENT changes `value` after mount', () => {
|
|
72
|
-
// Mounting straight at the target value would stay green even if the group
|
|
73
|
-
// snapshotted the prop at init — the move has to happen AFTER mount, driven
|
|
74
|
-
// from outside, with the menu open.
|
|
75
|
-
const calls = [];
|
|
76
|
-
setup({ onValueChange: (v) => calls.push(v) });
|
|
77
|
-
expect(radios().map((el) => el.getAttribute('aria-checked'))).toEqual([
|
|
78
|
-
'true',
|
|
79
|
-
'false',
|
|
80
|
-
'false',
|
|
81
|
-
]);
|
|
82
|
-
target.querySelector('[data-testid="parent-set"]').click();
|
|
83
|
-
flushSync();
|
|
84
|
-
expect(radios().map((el) => el.getAttribute('aria-checked'))).toEqual([
|
|
85
|
-
'false',
|
|
86
|
-
'false',
|
|
87
|
-
'true',
|
|
88
|
-
]);
|
|
89
|
-
expect(radio('bibliographie').getAttribute('data-state')).toBe('checked');
|
|
90
|
-
// The parent moved it; the group has nothing to report back.
|
|
91
|
-
expect(calls).toEqual([]);
|
|
92
|
-
});
|
|
93
|
-
// ── Selection ─────────────────────────────────────────────────────────
|
|
94
|
-
// `closeOnSelect: false` in the selection tests below is not incidental: the
|
|
95
|
-
// default closes the menu, which unmounts the rows — a post-click assertion
|
|
96
|
-
// on `aria-checked` would then fail for the wrong reason. Closing has its
|
|
97
|
-
// own test.
|
|
98
|
-
it('selects on click and notifies once with the new value', () => {
|
|
99
|
-
const calls = [];
|
|
100
|
-
let selects = 0;
|
|
101
|
-
setup({
|
|
102
|
-
closeOnSelect: false,
|
|
103
|
-
onItemSelect: () => selects++,
|
|
104
|
-
onValueChange: (v) => calls.push(v),
|
|
105
|
-
});
|
|
106
|
-
radio('placeholders').click();
|
|
107
|
-
flushSync();
|
|
108
|
-
expect(calls).toEqual(['placeholders']);
|
|
109
|
-
expect(radio('placeholders').getAttribute('aria-checked')).toBe('true');
|
|
110
|
-
expect(radio('document').getAttribute('aria-checked')).toBe('false');
|
|
111
|
-
// Proves the `onSelect` wiring is live — without this, the `select: 0` of
|
|
112
|
-
// the disabled test below would hold no matter what the component did.
|
|
113
|
-
expect(selects).toBe(1);
|
|
114
|
-
});
|
|
115
|
-
it('does NOT re-notify when the already-selected row is chosen again', () => {
|
|
116
|
-
const calls = [];
|
|
117
|
-
setup({ onValueChange: (v) => calls.push(v) });
|
|
118
|
-
radio('document').click();
|
|
119
|
-
flushSync();
|
|
120
|
-
expect(calls).toEqual([]);
|
|
121
|
-
});
|
|
122
|
-
it('selects on Enter and on Space', () => {
|
|
123
|
-
const calls = [];
|
|
124
|
-
setup({ closeOnSelect: false, onValueChange: (v) => calls.push(v) });
|
|
125
|
-
radio('placeholders').dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
126
|
-
flushSync();
|
|
127
|
-
expect(calls).toEqual(['placeholders']);
|
|
128
|
-
radio('bibliographie').dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
|
|
129
|
-
flushSync();
|
|
130
|
-
expect(calls).toEqual(['placeholders', 'bibliographie']);
|
|
131
|
-
});
|
|
132
|
-
it('closes the menu after a selection, and keeps it open when closeOnSelect is false', () => {
|
|
133
|
-
setup();
|
|
134
|
-
radio('placeholders').click();
|
|
135
|
-
flushSync();
|
|
136
|
-
expect(target.querySelector('[role="menu"]')).toBeNull();
|
|
137
|
-
unmount(instance);
|
|
138
|
-
instance = undefined;
|
|
139
|
-
target.remove();
|
|
140
|
-
setup({ closeOnSelect: false });
|
|
141
|
-
radio('placeholders').click();
|
|
142
|
-
flushSync();
|
|
143
|
-
expect(target.querySelector('[role="menu"]')).toBeTruthy();
|
|
144
|
-
});
|
|
145
|
-
// ── Disabled ──────────────────────────────────────────────────────────
|
|
146
|
-
it('a disabled row is TOTALLY inert — the consumer handler does not run either', () => {
|
|
147
|
-
const counts = { click: 0, keydown: 0, select: 0, change: 0 };
|
|
148
|
-
setup({
|
|
149
|
-
disabledValue: 'placeholders',
|
|
150
|
-
onItemClick: () => counts.click++,
|
|
151
|
-
onItemKeydown: () => counts.keydown++,
|
|
152
|
-
onItemSelect: () => counts.select++,
|
|
153
|
-
onValueChange: () => counts.change++,
|
|
154
|
-
});
|
|
155
|
-
const disabled = radio('placeholders');
|
|
156
|
-
expect(disabled.getAttribute('aria-disabled')).toBe('true');
|
|
157
|
-
expect(disabled.hasAttribute('data-disabled')).toBe(true);
|
|
158
|
-
disabled.click();
|
|
159
|
-
flushSync();
|
|
160
|
-
disabled.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
|
|
161
|
-
flushSync();
|
|
162
|
-
disabled.dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
|
|
163
|
-
flushSync();
|
|
164
|
-
// A dimmed, unselectable row that still fires an application effect is not
|
|
165
|
-
// disabled — it only LOOKS disabled.
|
|
166
|
-
expect(counts).toEqual({ click: 0, keydown: 0, select: 0, change: 0 });
|
|
167
|
-
expect(disabled.getAttribute('aria-checked')).toBe('false');
|
|
168
|
-
// ... and none of it dismissed the menu.
|
|
169
|
-
expect(target.querySelector('[role="menu"]')).toBeTruthy();
|
|
170
|
-
// `getOwnLevelMenuItems` filters on `[data-roving-focus-item]:not([data-disabled])`.
|
|
171
|
-
const rovable = target.querySelectorAll('[data-roving-focus-item]:not([data-disabled])');
|
|
172
|
-
expect(Array.from(rovable)).not.toContain(disabled);
|
|
173
|
-
});
|
|
174
|
-
// ── Keyboard: the chain, not the wiring ───────────────────────────────
|
|
175
|
-
//
|
|
176
|
-
// The `data-*` hooks below can all be present while the
|
|
177
|
-
// Content -> collection -> focus chain is broken, so these drive the real
|
|
178
|
-
// focused element instead of asserting attributes.
|
|
179
|
-
it('is reachable by ArrowDown from a plain Item, and Enter selects the FOCUSED row', () => {
|
|
180
|
-
const calls = [];
|
|
181
|
-
setup({
|
|
182
|
-
withLeadingItem: true,
|
|
183
|
-
closeOnSelect: false,
|
|
184
|
-
onValueChange: (v) => calls.push(v),
|
|
185
|
-
});
|
|
186
|
-
// Opening autofocuses the first roving row — the plain Item.
|
|
187
|
-
expect(document.activeElement?.textContent?.trim()).toBe('Plan');
|
|
188
|
-
pressKey('ArrowDown');
|
|
189
|
-
expect(document.activeElement?.getAttribute('role')).toBe('menuitemradio');
|
|
190
|
-
expect(activeValue()).toBe('document');
|
|
191
|
-
pressKey('ArrowDown');
|
|
192
|
-
expect(activeValue()).toBe('placeholders');
|
|
193
|
-
pressKey('Enter');
|
|
194
|
-
expect(calls).toEqual(['placeholders']);
|
|
195
|
-
expect(radio('placeholders').getAttribute('aria-checked')).toBe('true');
|
|
196
|
-
});
|
|
197
|
-
it('roving SKIPS a disabled row on ArrowDown', () => {
|
|
198
|
-
setup({ withLeadingItem: true, disabledValue: 'placeholders' });
|
|
199
|
-
expect(document.activeElement?.textContent?.trim()).toBe('Plan');
|
|
200
|
-
pressKey('ArrowDown');
|
|
201
|
-
expect(activeValue()).toBe('document');
|
|
202
|
-
pressKey('ArrowDown');
|
|
203
|
-
// `placeholders` is disabled — roving lands on the next enabled row.
|
|
204
|
-
expect(activeValue()).toBe('bibliographie');
|
|
205
|
-
});
|
|
206
|
-
it('typeahead focuses the matching row, and `textValue` redirects the match', () => {
|
|
207
|
-
setup({ withLeadingItem: true });
|
|
208
|
-
pressKey('b');
|
|
209
|
-
expect(activeValue()).toBe('bibliographie');
|
|
210
|
-
unmount(instance);
|
|
211
|
-
instance = undefined;
|
|
212
|
-
target.remove();
|
|
213
|
-
// With the override, `Bibliographie` no longer answers to `b` — and no
|
|
214
|
-
// other row does, so focus stays put.
|
|
215
|
-
setup({ withLeadingItem: true, textValues: { bibliographie: 'zzz' } });
|
|
216
|
-
const before = document.activeElement;
|
|
217
|
-
pressKey('b');
|
|
218
|
-
expect(document.activeElement).toBe(before);
|
|
219
|
-
// Remount before the second probe: typeahead ACCUMULATES a buffer, so a
|
|
220
|
-
// `z` typed after a failed `b` searches for "bz" and would match nothing —
|
|
221
|
-
// the test would then pass or fail for a reason unrelated to `textValue`.
|
|
222
|
-
unmount(instance);
|
|
223
|
-
instance = undefined;
|
|
224
|
-
target.remove();
|
|
225
|
-
setup({ withLeadingItem: true, textValues: { bibliographie: 'zzz' } });
|
|
226
|
-
pressKey('z');
|
|
227
|
-
expect(activeValue()).toBe('bibliographie');
|
|
228
|
-
});
|
|
229
|
-
// ── Roving focus + typeahead wiring ───────────────────────────────────
|
|
230
|
-
it('joins the roving collection alongside plain items', () => {
|
|
231
|
-
setup({ withLeadingItem: true });
|
|
232
|
-
const rovable = Array.from(target.querySelectorAll('[data-roving-focus-item]:not([data-disabled])'));
|
|
233
|
-
// Plan + the three radio rows, in document order.
|
|
234
|
-
expect(rovable).toHaveLength(4);
|
|
235
|
-
expect(rovable[0].getAttribute('role')).toBe('menuitem');
|
|
236
|
-
expect(rovable.slice(1).map((el) => el.getAttribute('role'))).toEqual([
|
|
237
|
-
'menuitemradio',
|
|
238
|
-
'menuitemradio',
|
|
239
|
-
'menuitemradio',
|
|
240
|
-
]);
|
|
241
|
-
});
|
|
242
|
-
it('exposes its label to typeahead, and lets `textValue` override it', () => {
|
|
243
|
-
setup({ textValues: { bibliographie: 'zzz' } });
|
|
244
|
-
// No override → the content's typeahead falls back to textContent.
|
|
245
|
-
expect(radio('document').getAttribute('data-text-value')).toBeNull();
|
|
246
|
-
expect(radio('document').textContent?.trim()).toBe('Document');
|
|
247
|
-
// Override → the attribute the content reads FIRST.
|
|
248
|
-
expect(radio('bibliographie').getAttribute('data-text-value')).toBe('zzz');
|
|
249
|
-
});
|
|
250
|
-
// ── The two properties #201 costs the older rows ───────────────────────
|
|
251
|
-
it('forwards consumer HTML attributes to the GROUP element', () => {
|
|
252
|
-
setup({ groupAttrs: { 'aria-label': 'Panneau', 'data-testid': 'view-group' } });
|
|
253
|
-
const group = target.querySelector('.sp-dropdown-menu-radio-group');
|
|
254
|
-
expect(group.getAttribute('aria-label')).toBe('Panneau');
|
|
255
|
-
expect(group.getAttribute('data-testid')).toBe('view-group');
|
|
256
|
-
// The role stays ours.
|
|
257
|
-
expect(group.getAttribute('role')).toBe('group');
|
|
258
|
-
});
|
|
259
|
-
it('forwards consumer HTML attributes to the row element', () => {
|
|
260
|
-
setup({ itemAttrs: { 'data-testid': 'view-placeholders', 'aria-keyshortcuts': 'p' } });
|
|
261
|
-
const el = radio('placeholders');
|
|
262
|
-
expect(el.getAttribute('data-testid')).toBe('view-placeholders');
|
|
263
|
-
expect(el.getAttribute('aria-keyshortcuts')).toBe('p');
|
|
264
|
-
});
|
|
265
|
-
it('keeps its own class alongside a consumer class', () => {
|
|
266
|
-
setup({ itemAttrs: { class: 'view-row' } });
|
|
267
|
-
const el = radio('placeholders');
|
|
268
|
-
expect(el.classList.contains('view-row')).toBe(true);
|
|
269
|
-
expect(el.classList.contains('sp-dropdown-menu-item')).toBe(true);
|
|
270
|
-
});
|
|
271
|
-
it('cOMPOSES a consumer handler with the built-in selection', () => {
|
|
272
|
-
const seen = [];
|
|
273
|
-
setup({
|
|
274
|
-
closeOnSelect: false,
|
|
275
|
-
onItemClick: () => seen.push('consumer'),
|
|
276
|
-
onValueChange: (v) => seen.push(`selected:${v}`),
|
|
277
|
-
});
|
|
278
|
-
radio('placeholders').click();
|
|
279
|
-
flushSync();
|
|
280
|
-
// Both ran, consumer first — and selection actually happened.
|
|
281
|
-
expect(seen).toEqual(['consumer', 'selected:placeholders']);
|
|
282
|
-
});
|
|
283
|
-
it('lets a consumer handler cancel the selection with preventDefault', () => {
|
|
284
|
-
const calls = [];
|
|
285
|
-
setup({
|
|
286
|
-
onItemClick: (event) => event.preventDefault(),
|
|
287
|
-
onValueChange: (v) => calls.push(v),
|
|
288
|
-
});
|
|
289
|
-
radio('placeholders').click();
|
|
290
|
-
flushSync();
|
|
291
|
-
expect(calls).toEqual([]);
|
|
292
|
-
expect(radio('placeholders').getAttribute('aria-checked')).toBe('false');
|
|
293
|
-
// A cancelled selection must not close the menu either.
|
|
294
|
-
expect(target.querySelector('[role="menu"]')).toBeTruthy();
|
|
295
|
-
});
|
|
296
|
-
// ── Guard rail ────────────────────────────────────────────────────────
|
|
297
|
-
it('throws a NAMED error when a RadioItem is used outside a RadioGroup', () => {
|
|
298
|
-
const spy = vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
299
|
-
try {
|
|
300
|
-
expect(() => setup({ orphan: true })).toThrow(/RadioGroup/);
|
|
301
|
-
}
|
|
302
|
-
finally {
|
|
303
|
-
spy.mockRestore();
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
});
|