@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.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/THIRD_PARTY_NOTICES.md +201 -0
  3. package/package.json +8 -2
  4. package/dist/components/__tests__/overlay-scrim-source.test.js +0 -134
  5. package/dist/components/accordion/__tests__/AccordionTest.svelte +0 -31
  6. package/dist/components/accordion/__tests__/accordion.test.svelte.js +0 -139
  7. package/dist/components/alert-dialog/__tests__/AlertDialogTest.svelte +0 -28
  8. package/dist/components/alert-dialog/__tests__/alert-dialog.a11y.test.js +0 -42
  9. package/dist/components/alert-dialog/__tests__/alert-dialog.integration.test.svelte.js +0 -51
  10. package/dist/components/alert-dialog/__tests__/alert-dialog.test.svelte.js +0 -113
  11. package/dist/components/app-bar/__tests__/app-bar.test.svelte.js +0 -30
  12. package/dist/components/aspect-ratio/__tests__/aspect-ratio.test.svelte.js +0 -22
  13. package/dist/components/avatar/__tests__/avatar.test.svelte.js +0 -26
  14. package/dist/components/badge/__tests__/badge.test.svelte.js +0 -30
  15. package/dist/components/bottom-sheet/__tests__/BottomSheetTest.svelte +0 -22
  16. package/dist/components/bottom-sheet/__tests__/bottom-sheet.test.svelte.js +0 -83
  17. package/dist/components/button/__tests__/button.test.svelte.js +0 -63
  18. package/dist/components/calendar/__tests__/CalendarTest.svelte +0 -56
  19. package/dist/components/calendar/__tests__/calendar.test.svelte.js +0 -190
  20. package/dist/components/card/__tests__/card.test.svelte.js +0 -30
  21. package/dist/components/checkbox/__tests__/checkbox.test.svelte.js +0 -44
  22. package/dist/components/chips/__tests__/chips.test.svelte.js +0 -26
  23. package/dist/components/collapsible/__tests__/CollapsibleTest.svelte +0 -18
  24. package/dist/components/collapsible/__tests__/collapsible.test.svelte.js +0 -125
  25. package/dist/components/combobox/__tests__/ComboboxTest.svelte +0 -40
  26. package/dist/components/combobox/__tests__/combobox.test.svelte.js +0 -255
  27. package/dist/components/command/__tests__/CommandInlineDirectTest.svelte +0 -29
  28. package/dist/components/command/__tests__/CommandInlineTest.svelte +0 -89
  29. package/dist/components/command/__tests__/CommandTest.svelte +0 -77
  30. package/dist/components/command/__tests__/command-inline.test.svelte.js +0 -392
  31. package/dist/components/command/__tests__/command-item-passthrough.test.svelte.js +0 -284
  32. package/dist/components/command/__tests__/command.a11y.test.js +0 -30
  33. package/dist/components/command/__tests__/command.integration.test.svelte.js +0 -68
  34. package/dist/components/command/__tests__/command.test.svelte.js +0 -230
  35. package/dist/components/context-menu/__tests__/ContextMenuNonInteractiveTest.svelte +0 -32
  36. package/dist/components/context-menu/__tests__/ContextMenuTest.svelte +0 -25
  37. package/dist/components/context-menu/__tests__/context-menu.test.svelte.js +0 -141
  38. package/dist/components/date-field/__tests__/DateFieldTest.svelte +0 -20
  39. package/dist/components/date-field/__tests__/date-field.test.svelte.js +0 -139
  40. package/dist/components/date-picker/__tests__/DatePickerTest.svelte +0 -20
  41. package/dist/components/date-picker/__tests__/date-picker.test.svelte.js +0 -190
  42. package/dist/components/date-range-field/__tests__/DateRangeFieldTest.svelte +0 -20
  43. package/dist/components/date-range-field/__tests__/date-range-field.test.svelte.js +0 -130
  44. package/dist/components/date-range-picker/__tests__/DateRangePickerTest.svelte +0 -18
  45. package/dist/components/date-range-picker/__tests__/date-range-picker.test.svelte.js +0 -156
  46. package/dist/components/dialog/__tests__/DialogTest.svelte +0 -34
  47. package/dist/components/dialog/__tests__/dialog.test.svelte.js +0 -184
  48. package/dist/components/drop-zone/__tests__/drop-zone.test.svelte.js +0 -26
  49. package/dist/components/dropdown-menu/__tests__/DropdownMenuRadioTest.svelte +0 -90
  50. package/dist/components/dropdown-menu/__tests__/DropdownMenuTest.svelte +0 -71
  51. package/dist/components/dropdown-menu/__tests__/dropdown-menu-radio-group.test.svelte.js +0 -306
  52. package/dist/components/dropdown-menu/__tests__/dropdown-menu.test.svelte.js +0 -567
  53. package/dist/components/empty-state/__tests__/empty-state.test.svelte.js +0 -26
  54. package/dist/components/fab/__tests__/fab.test.svelte.js +0 -30
  55. package/dist/components/field/__tests__/FieldTest.svelte +0 -26
  56. package/dist/components/field/__tests__/field.test.svelte.js +0 -74
  57. package/dist/components/grid-list/__tests__/GridListTest.svelte +0 -46
  58. package/dist/components/grid-list/__tests__/grid-list.test.svelte.js +0 -231
  59. package/dist/components/hover-card/__tests__/HoverCardTest.svelte +0 -30
  60. package/dist/components/hover-card/__tests__/hover-card.test.svelte.js +0 -236
  61. package/dist/components/indicator/__tests__/indicator.test.svelte.js +0 -30
  62. package/dist/components/input/__tests__/input.test.svelte.js +0 -67
  63. package/dist/components/label/__tests__/label.test.svelte.js +0 -22
  64. package/dist/components/language-select/__tests__/language-select.test.svelte.js +0 -199
  65. package/dist/components/language-select/__tests__/languages.test.js +0 -87
  66. package/dist/components/link-preview/__tests__/LinkPreviewTest.svelte +0 -37
  67. package/dist/components/link-preview/__tests__/link-preview.a11y.test.js +0 -28
  68. package/dist/components/link-preview/__tests__/link-preview.integration.test.svelte.js +0 -54
  69. package/dist/components/link-preview/__tests__/link-preview.test.svelte.js +0 -215
  70. package/dist/components/list/__tests__/list.test.svelte.js +0 -22
  71. package/dist/components/menubar/__tests__/MenubarTest.svelte +0 -52
  72. package/dist/components/menubar/__tests__/menubar.a11y.test.js +0 -28
  73. package/dist/components/menubar/__tests__/menubar.integration.test.svelte.js +0 -57
  74. package/dist/components/menubar/__tests__/menubar.test.svelte.js +0 -328
  75. package/dist/components/meter/__tests__/meter.test.svelte.js +0 -26
  76. package/dist/components/nav-bar/__tests__/nav-bar.test.svelte.js +0 -23
  77. package/dist/components/nav-drawer/__tests__/nav-drawer.test.svelte.js +0 -28
  78. package/dist/components/nav-rail/__tests__/nav-rail.test.svelte.js +0 -28
  79. package/dist/components/pagination/__tests__/pagination.test.svelte.js +0 -26
  80. package/dist/components/pin-input/__tests__/pin-input.test.svelte.js +0 -71
  81. package/dist/components/popover/__tests__/PopoverTest.svelte +0 -27
  82. package/dist/components/popover/__tests__/popover.test.svelte.js +0 -196
  83. package/dist/components/progress/__tests__/progress.test.svelte.js +0 -32
  84. package/dist/components/radio-group/__tests__/radio-group.test.svelte.js +0 -22
  85. package/dist/components/range-calendar/__tests__/RangeCalendarTest.svelte +0 -23
  86. package/dist/components/range-calendar/__tests__/range-calendar.test.svelte.js +0 -105
  87. package/dist/components/rating-group/__tests__/rating-group.test.svelte.js +0 -26
  88. package/dist/components/scroll-area/__tests__/scroll-area.test.svelte.js +0 -34
  89. package/dist/components/search-field/__tests__/SearchFieldTest.svelte +0 -34
  90. package/dist/components/search-field/__tests__/search-field.test.svelte.js +0 -118
  91. package/dist/components/select/__tests__/SelectLabelPersistenceTest.svelte +0 -31
  92. package/dist/components/select/__tests__/SelectTest.svelte +0 -33
  93. package/dist/components/select/__tests__/select.test.svelte.js +0 -221
  94. package/dist/components/separator/__tests__/separator.test.svelte.js +0 -39
  95. package/dist/components/sheet/__tests__/SheetTest.svelte +0 -34
  96. package/dist/components/sheet/__tests__/sheet.test.svelte.js +0 -193
  97. package/dist/components/side-sheet/__tests__/side-sheet.test.svelte.js +0 -138
  98. package/dist/components/sidebar/__tests__/SidebarFullTest.svelte +0 -45
  99. package/dist/components/sidebar/__tests__/SidebarTest.svelte +0 -9
  100. package/dist/components/sidebar/__tests__/sidebar.test.svelte.js +0 -186
  101. package/dist/components/simple-dialog/__tests__/SimpleDialogTest.svelte +0 -40
  102. package/dist/components/simple-dialog/__tests__/simple-dialog.test.svelte.js +0 -50
  103. package/dist/components/simple-tooltip/__tests__/SimpleTooltipTest.svelte +0 -19
  104. package/dist/components/simple-tooltip/__tests__/simple-tooltip.test.svelte.js +0 -61
  105. package/dist/components/slider/__tests__/slider.test.svelte.js +0 -42
  106. package/dist/components/sortable-list/__tests__/NestedSortableListTest.svelte +0 -49
  107. package/dist/components/sortable-list/__tests__/SortableListTest.svelte +0 -42
  108. package/dist/components/sortable-list/__tests__/sortable-list.nested.test.svelte.js +0 -112
  109. package/dist/components/sortable-list/__tests__/sortable-list.test.svelte.js +0 -175
  110. package/dist/components/splitter/__tests__/splitter.test.svelte.js +0 -26
  111. package/dist/components/switch/__tests__/switch.test.svelte.js +0 -44
  112. package/dist/components/table/__tests__/table.test.svelte.js +0 -22
  113. package/dist/components/tabs/__tests__/TabsTest.svelte +0 -32
  114. package/dist/components/tabs/__tests__/tabs.test.svelte.js +0 -227
  115. package/dist/components/textarea/__tests__/textarea.test.svelte.js +0 -55
  116. package/dist/components/time-field/__tests__/TimeFieldTest.svelte +0 -20
  117. package/dist/components/time-field/__tests__/time-field.test.svelte.js +0 -100
  118. package/dist/components/time-range-field/__tests__/TimeRangeFieldTest.svelte +0 -20
  119. package/dist/components/time-range-field/__tests__/time-range-field.test.svelte.js +0 -124
  120. package/dist/components/toast/__tests__/toast.test.svelte.js +0 -46
  121. package/dist/components/toggle/__tests__/toggle.test.svelte.js +0 -38
  122. package/dist/components/toggle-group/__tests__/toggle-group.test.svelte.js +0 -22
  123. package/dist/components/toolbar/__tests__/ToolbarCompositionTest.svelte +0 -18
  124. package/dist/components/toolbar/__tests__/ToolbarTabstopTest.svelte +0 -10
  125. package/dist/components/toolbar/__tests__/toolbar.test.svelte.js +0 -63
  126. package/dist/components/tooltip/__tests__/TooltipTest.svelte +0 -22
  127. package/dist/components/tooltip/__tests__/tooltip.test.svelte.js +0 -225
  128. package/dist/components/tree/__tests__/TreeLabelContentTest.svelte +0 -21
  129. package/dist/components/tree/__tests__/TreeTest.svelte +0 -24
  130. package/dist/components/tree/__tests__/tree.test.svelte.js +0 -229
  131. package/dist/components/virtualizer/__tests__/waterfall-layout.test.js +0 -82
  132. package/dist/internal/announcer/__tests__/announcer.test.js +0 -42
  133. package/dist/internal/dismissible-layer/__tests__/dismissible-layer.test.js +0 -196
  134. package/dist/internal/drag-drop/__tests__/auto-scroll.test.js +0 -104
  135. package/dist/internal/drag-drop/__tests__/drag-session.test.svelte.js +0 -803
  136. package/dist/internal/drag-drop/__tests__/drag-source.test.svelte.js +0 -130
  137. package/dist/internal/drag-drop/__tests__/drop-delegate.test.js +0 -223
  138. package/dist/internal/drag-drop/__tests__/types.test.js +0 -20
  139. package/dist/internal/escape-layer/__tests__/escape-layer.test.js +0 -113
  140. package/dist/internal/focus-scope/__tests__/focus-scope.test.js +0 -225
  141. package/dist/internal/grace-area/__tests__/grace-area.test.js +0 -67
  142. package/dist/internal/helpers/__tests__/helpers.test.js +0 -123
  143. package/dist/internal/portal/__tests__/PortalTest.svelte +0 -21
  144. package/dist/internal/portal/__tests__/portal.test.js +0 -29
  145. package/dist/internal/portal/__tests__/portal.test.svelte.js +0 -57
  146. package/dist/internal/scroll-lock/__tests__/scroll-lock.test.js +0 -160
  147. package/dist/internal/typeahead/__tests__/typeahead.test.js +0 -61
  148. package/src/themes/__tests__/carbon-dark-contrast.test.ts +0 -170
  149. package/src/themes/__tests__/generated-css-drift.test.ts +0 -53
  150. package/src/themes/__tests__/scrim-opaque.test.ts +0 -52
@@ -1,392 +0,0 @@
1
- import { flushSync, mount, unmount } from 'svelte';
2
- import { afterEach, describe, expect, it, vi } from 'vitest';
3
- import { EscapeLayerState, resetEscapeLayerStack } from '../../../internal/escape-layer/index.js';
4
- import CommandInlineDirectTest from './CommandInlineDirectTest.svelte';
5
- import CommandInlineTest from './CommandInlineTest.svelte';
6
- /**
7
- * `mode: 'inline'` — a persistent field with non-modal results.
8
- *
9
- * The contract these pins defend is not "the list is hidden": it is that a
10
- * CLOSED palette is inert. It executes nothing, it claims no key, it holds no
11
- * slot in the global layer stacks, and it names no option that is not on
12
- * screen. `modal` is the default and must come through untouched.
13
- */
14
- if (typeof globalThis.PointerEvent === 'undefined') {
15
- // @ts-expect-error — minimal polyfill for testing
16
- globalThis.PointerEvent = class PointerEvent extends MouseEvent {
17
- constructor(type, init) {
18
- super(type, init);
19
- }
20
- };
21
- }
22
- describe('command — inline mode', () => {
23
- let target;
24
- let instance;
25
- function setup(props = {}) {
26
- target = document.createElement('div');
27
- document.body.appendChild(target);
28
- instance = mount(CommandInlineTest, { target, props });
29
- flushSync();
30
- return target;
31
- }
32
- afterEach(() => {
33
- if (instance)
34
- unmount(instance);
35
- instance = undefined;
36
- target?.remove();
37
- resetEscapeLayerStack();
38
- document.body.innerHTML = '';
39
- });
40
- const input = () => target.querySelector('input.probe-input');
41
- const options = () => [...target.querySelectorAll('[data-command-item]')];
42
- const activeId = () => input().getAttribute('aria-activedescendant');
43
- function press(key, init = {}) {
44
- const event = new KeyboardEvent('keydown', { key, bubbles: true, cancelable: true, ...init });
45
- input().dispatchEvent(event);
46
- flushSync();
47
- return event;
48
- }
49
- function type(text) {
50
- const el = input();
51
- el.value = text;
52
- el.dispatchEvent(new Event('input', { bubbles: true }));
53
- flushSync();
54
- }
55
- // --- The field outlives the results ------------------------------------
56
- it('closed: the field is rendered and NO option is', () => {
57
- setup({ initialOpen: false });
58
- expect(input()).toBeTruthy();
59
- expect(options()).toHaveLength(0);
60
- expect(target.querySelector('[role="listbox"]')).toBeNull();
61
- });
62
- it('closed: aria-expanded is false, and the relations that would dangle are absent', () => {
63
- setup({ initialOpen: false });
64
- expect(input().getAttribute('aria-expanded')).toBe('false');
65
- expect(input().getAttribute('aria-controls')).toBeNull();
66
- expect(activeId()).toBeNull();
67
- });
68
- it('the SAME input element survives a close and a reopen — never a second field', () => {
69
- setup({ initialOpen: true });
70
- const first = input();
71
- instance.setOpen(false);
72
- flushSync();
73
- expect(options()).toHaveLength(0);
74
- const whileClosed = input();
75
- instance.setOpen(true);
76
- flushSync();
77
- // Node identity, not a lookalike: a remounted field would lose focus,
78
- // selection and any consumer `bind:element` reference.
79
- expect(whileClosed).toBe(first);
80
- expect(input()).toBe(first);
81
- });
82
- it('exposes the real input element through `bind:element`, with no internal selector', () => {
83
- setup({ initialOpen: false });
84
- expect(instance.getElement()).toBe(input());
85
- instance.getElement().focus();
86
- expect(document.activeElement).toBe(input());
87
- });
88
- // --- A closed palette claims nothing -----------------------------------
89
- it('closed: Enter executes nothing and is NOT prevented — it belongs to the page', () => {
90
- const onSelect = vi.fn();
91
- setup({ initialOpen: false, onSelect });
92
- const event = press('Enter');
93
- expect(onSelect).not.toHaveBeenCalled();
94
- expect(event.defaultPrevented).toBe(false);
95
- });
96
- it('closed: a third-party Escape layer mounted FIRST still receives the key', () => {
97
- const onEscapeKeydown = vi.fn();
98
- // Mounted BEFORE the palette, so it sits at the BOTTOM of the stack. The
99
- // stack offers the keystroke to the topmost 'close' layer and stops there:
100
- // a palette that illicitly kept its layer while closed would be above this
101
- // one and would swallow the key. Mounted after, it would win either way
102
- // and the test would pass on a broken implementation.
103
- const other = new EscapeLayerState({ enabled: true, onEscapeKeydown });
104
- other.mount();
105
- setup({ initialOpen: false });
106
- const event = press('Escape');
107
- expect(onEscapeKeydown).toHaveBeenCalledTimes(1);
108
- expect(event.defaultPrevented).toBe(false);
109
- other.unmount();
110
- });
111
- it('open: the palette DOES take the key from a layer mounted before it — the test above discriminates', () => {
112
- const onEscapeKeydown = vi.fn();
113
- const other = new EscapeLayerState({ enabled: true, onEscapeKeydown });
114
- other.mount();
115
- setup({ initialOpen: true });
116
- press('Escape');
117
- // Same order, results open: the palette is topmost and answers, so the
118
- // previous test really observes the layer being absent, not the ordering.
119
- expect(onEscapeKeydown).not.toHaveBeenCalled();
120
- expect(instance.getOpen()).toBe(false);
121
- other.unmount();
122
- });
123
- it('closed: Home and End stay with the caret — native editing is preserved', () => {
124
- setup({ initialOpen: false });
125
- expect(press('Home').defaultPrevented).toBe(false);
126
- expect(press('End').defaultPrevented).toBe(false);
127
- });
128
- it('closed: an arrow OPENS the results instead of moving an unseen selection', () => {
129
- const onOpenChange = vi.fn();
130
- setup({ initialOpen: false, onOpenChange });
131
- const event = press('ArrowDown');
132
- expect(event.defaultPrevented).toBe(true);
133
- expect(onOpenChange).toHaveBeenCalledWith(true);
134
- expect(instance.getOpen()).toBe(true);
135
- flushSync();
136
- expect(options().length).toBeGreaterThan(0);
137
- });
138
- // --- Open: the engine is the one that shipped ---------------------------
139
- it('open: keyword filtering still decides — a term absent from the label finds the option', () => {
140
- setup({ initialOpen: true });
141
- type('duplicate');
142
- const values = options().map((el) => el.dataset.value);
143
- expect(values).toEqual(['copy']);
144
- });
145
- it('open: arrow then Enter activates the option exactly ONCE', () => {
146
- const onSelect = vi.fn();
147
- setup({ initialOpen: true, onSelect });
148
- press('ArrowDown');
149
- const selected = options().find((el) => el.dataset.selected === 'true');
150
- press('Enter');
151
- expect(onSelect).toHaveBeenCalledTimes(1);
152
- expect(onSelect).toHaveBeenCalledWith(selected.dataset.value);
153
- });
154
- it('open: aria-activedescendant names the rendered option’s DOM id, never its value', () => {
155
- setup({ initialOpen: true });
156
- const selected = options().find((el) => el.dataset.selected === 'true');
157
- expect(activeId()).toBe(selected.id);
158
- expect(activeId()).not.toBe(selected.dataset.value);
159
- // And it resolves to a node that is really in the document.
160
- expect(document.getElementById(activeId())).toBe(selected);
161
- expect(input().getAttribute('aria-controls')).toBe(target.querySelector('[role="listbox"]').id);
162
- });
163
- // --- The reference cannot outlive what it names -------------------------
164
- it('after filtering, the reference follows the surviving option', () => {
165
- setup({ initialOpen: true });
166
- type('duplicate');
167
- const selected = options().find((el) => el.dataset.selected === 'true');
168
- expect(selected.dataset.value).toBe('copy');
169
- expect(activeId()).toBe(selected.id);
170
- });
171
- it('when nothing matches, there is no active option and no reference', () => {
172
- setup({ initialOpen: true });
173
- type('zzzzz');
174
- expect(options()).toHaveLength(0);
175
- expect(activeId()).toBeNull();
176
- });
177
- it('removing the active option leaves no dead reference', () => {
178
- setup({
179
- initialOpen: true,
180
- initialEntries: [
181
- { value: 'copy', label: 'Copy' },
182
- { value: 'paste', label: 'Paste' },
183
- ],
184
- });
185
- expect(options().find((el) => el.dataset.selected === 'true').dataset.value).toBe('copy');
186
- // The consumer drops the option that is currently active.
187
- instance.setEntries([{ value: 'paste', label: 'Paste' }]);
188
- flushSync();
189
- const id = activeId();
190
- expect(id).not.toBeNull();
191
- const named = document.getElementById(id);
192
- expect(named).not.toBeNull();
193
- expect(named.dataset.value).toBe('paste');
194
- });
195
- it('reopening after the options changed: no stale selection, no dead reference, no lost first arrow', () => {
196
- const onSelect = vi.fn();
197
- setup({
198
- initialOpen: true,
199
- onSelect,
200
- initialEntries: [
201
- { value: 'copy', label: 'Copy' },
202
- { value: 'paste', label: 'Paste' },
203
- ],
204
- });
205
- // Move the selection away from the first option, then close.
206
- press('ArrowDown');
207
- expect(options().find((el) => el.dataset.selected === 'true').dataset.value).toBe('paste');
208
- instance.setOpen(false);
209
- flushSync();
210
- expect(activeId()).toBeNull();
211
- // A completely different collection comes back.
212
- instance.setEntries([
213
- { value: 'rename', label: 'Rename' },
214
- { value: 'delete', label: 'Delete' },
215
- ]);
216
- instance.setOpen(true);
217
- flushSync();
218
- const selected = options().find((el) => el.dataset.selected === 'true');
219
- // Not the stale `paste`, which no longer exists.
220
- expect(selected.dataset.value).toBe('rename');
221
- expect(activeId()).toBe(selected.id);
222
- // The first arrow MOVES; it is not spent recovering from a stale value.
223
- press('ArrowDown');
224
- expect(options().find((el) => el.dataset.selected === 'true').dataset.value).toBe('delete');
225
- press('Enter');
226
- expect(onSelect).toHaveBeenCalledTimes(1);
227
- expect(onSelect).toHaveBeenCalledWith('delete');
228
- });
229
- // --- A retained query must survive a remount (review of #224, [P1]) -----
230
- /**
231
- * One symptom — zero options after a close and a reopen with the query still
232
- * in the field — hiding TWO mechanisms, so each gets its own pin.
233
- *
234
- * · `Command.Group` gated its children on `hasVisibleItems()`, a predicate
235
- * over the very registry those children fill. Empty registry + retained
236
- * query ⇒ children never mount ⇒ registry stays empty. A deadlock.
237
- * · An item's `isVisible` reads `getScore()` from a plain Map during
238
- * RENDER, while `registerItem` writes that score from an `$effect`, i.e.
239
- * afterwards. Nothing woke the derived, so a matching item stayed hidden.
240
- *
241
- * Both make `aria-activedescendant` name a node that is not in the document,
242
- * which is why every pin here resolves the id rather than trusting it.
243
- */
244
- function activeElement() {
245
- const id = activeId();
246
- return id === null ? null : document.getElementById(id);
247
- }
248
- it('a query kept across a close and a reopen still renders its match, named and actionable', () => {
249
- const onSelect = vi.fn();
250
- setup({ initialOpen: true, onSelect });
251
- type('duplicate');
252
- expect(options().map((el) => el.dataset.value)).toEqual(['copy']);
253
- instance.setOpen(false);
254
- flushSync();
255
- expect(options()).toHaveLength(0);
256
- instance.setOpen(true);
257
- flushSync();
258
- expect(options().map((el) => el.dataset.value)).toEqual(['copy']);
259
- // The reference resolves to a node that is really in the document.
260
- expect(activeElement()).not.toBeNull();
261
- expect(activeElement()).toBe(options()[0]);
262
- press('Enter');
263
- expect(onSelect).toHaveBeenCalledTimes(1);
264
- expect(onSelect).toHaveBeenCalledWith('copy');
265
- });
266
- it('a query typed while CLOSED renders its match when an arrow opens the list', () => {
267
- setup({ initialOpen: false });
268
- type('duplicate');
269
- expect(options()).toHaveLength(0);
270
- press('ArrowDown');
271
- expect(options().map((el) => el.dataset.value)).toEqual(['copy']);
272
- expect(activeElement()).toBe(options()[0]);
273
- });
274
- it('same, with NO Command.Group: the item mechanism alone is enough to break it', () => {
275
- target = document.createElement('div');
276
- document.body.appendChild(target);
277
- instance = mount(CommandInlineDirectTest, { target });
278
- flushSync();
279
- type('duplicate');
280
- press('ArrowDown');
281
- expect(options().map((el) => el.dataset.value)).toEqual(['copy']);
282
- expect(activeElement()).not.toBeNull();
283
- expect(activeElement()).toBe(options()[0]);
284
- });
285
- // --- Event composition --------------------------------------------------
286
- it('a consumer onkeydown runs first and its preventDefault cancels the local handling', () => {
287
- const onOpenChange = vi.fn();
288
- setup({
289
- initialOpen: false,
290
- onOpenChange,
291
- inputAttrs: { onkeydown: (e) => e.preventDefault() },
292
- });
293
- press('ArrowDown');
294
- expect(onOpenChange).not.toHaveBeenCalled();
295
- expect(instance.getOpen()).toBe(false);
296
- });
297
- it('a consumer onkeydown cannot retract a close already performed in the capture phase', () => {
298
- const onEscapeKeydown = vi.fn();
299
- setup({
300
- initialOpen: true,
301
- onEscapeKeydown,
302
- inputAttrs: { onkeydown: (e) => e.preventDefault() },
303
- });
304
- press('Escape');
305
- // The layer listens on `document` in capture — it read `defaultPrevented`
306
- // before the input's handler ever ran. `onEscapeKeydown` is the hook.
307
- expect(onEscapeKeydown).toHaveBeenCalledTimes(1);
308
- expect(instance.getOpen()).toBe(false);
309
- });
310
- // --- Anchorable, and no focus trap --------------------------------------
311
- it('renders IN PLACE with the inline chrome released, so results can be anchored', () => {
312
- setup({ initialOpen: true });
313
- const root = target.querySelector('.sp-command');
314
- // In place — not portalled to document.body, which would break both the
315
- // consumer's scoped CSS and any anchoring to the field.
316
- expect(root.parentElement).not.toBe(document.body);
317
- expect(target.contains(root)).toBe(true);
318
- expect(root.dataset.mode).toBe('inline');
319
- // The field and the results share one owner, which is what lets a consumer
320
- // anchor the second to the first.
321
- const field = root.querySelector('.sp-command-input-wrapper');
322
- const list = root.querySelector('[role="listbox"]');
323
- expect(field.parentElement).toBe(root);
324
- expect(list.parentElement).toBe(root);
325
- // Whether the released `overflow` really keeps the list unclipped is a
326
- // LAYOUT fact, and this environment has no CSS at all — vite does not load
327
- // the components' stylesheets into jsdom. It is proven in a real Chromium
328
- // by `tests/e2e/command-inline.spec.ts`, on the docs page's live demo.
329
- });
330
- it('does not trap focus: an outside control keeps it', () => {
331
- setup({ initialOpen: true });
332
- const outside = document.createElement('button');
333
- document.body.appendChild(outside);
334
- outside.focus();
335
- flushSync();
336
- expect(document.activeElement).toBe(outside);
337
- outside.remove();
338
- });
339
- it('the consumer names the field; the component keeps its structure', () => {
340
- setup({
341
- initialOpen: true,
342
- inputAttrs: {
343
- 'aria-label': 'Site search',
344
- 'aria-describedby': 'hint-id',
345
- title: 'Search',
346
- 'data-testid': 'field',
347
- // Refused by the type; spread anyway to prove the markup order wins.
348
- role: 'textbox',
349
- id: 'consumer-id',
350
- 'aria-expanded': 'false',
351
- 'aria-activedescendant': 'nope',
352
- },
353
- });
354
- const el = input();
355
- // The consumer's naming and description reach the real combobox…
356
- expect(el.getAttribute('aria-label')).toBe('Site search');
357
- expect(el.getAttribute('aria-describedby')).toBe('hint-id');
358
- expect(el.getAttribute('title')).toBe('Search');
359
- expect(el.getAttribute('data-testid')).toBe('field');
360
- // …while the structure stays the component's, whatever is spread.
361
- expect(el.getAttribute('role')).toBe('combobox');
362
- expect(el.id).not.toBe('consumer-id');
363
- expect(el.getAttribute('aria-expanded')).toBe('true');
364
- expect(el.getAttribute('aria-activedescendant')).not.toBe('nope');
365
- expect(el.getAttribute('aria-activedescendant')).toBe(options().find((o) => o.dataset.selected === 'true').id);
366
- });
367
- it('exposes the wrapper through `wrapperClass` while `class` stays on the input', () => {
368
- setup({ initialOpen: false });
369
- const wrapper = target.querySelector('.sp-command-input-wrapper');
370
- expect(wrapper.classList.contains('probe-wrapper')).toBe(true);
371
- expect(input().classList.contains('probe-input')).toBe(true);
372
- expect(input().classList.contains('probe-wrapper')).toBe(false);
373
- });
374
- // --- The default mode is untouched --------------------------------------
375
- it('modal stays the default: closing unmounts the field itself', () => {
376
- // `portalTo` keeps the modal content inside `target` for querying — the
377
- // modal default is `document.body`, which is itself part of the contract.
378
- target = document.createElement('div');
379
- document.body.appendChild(target);
380
- instance = mount(CommandInlineTest, {
381
- target,
382
- props: { mode: 'modal', initialOpen: true, portalTo: target },
383
- });
384
- flushSync();
385
- expect(input()).toBeTruthy();
386
- expect(input().getAttribute('aria-expanded')).toBe('true');
387
- instance.setOpen(false);
388
- flushSync();
389
- expect(target.querySelector('input')).toBeNull();
390
- expect(target.querySelector('.sp-command')).toBeNull();
391
- });
392
- });
@@ -1,284 +0,0 @@
1
- import { flushSync, mount, unmount } from 'svelte';
2
- import { afterEach, describe, expect, it } from 'vitest';
3
- import CommandTest from './CommandTest.svelte';
4
- // jsdom does not define PointerEvent — polyfill it for tests
5
- if (typeof globalThis.PointerEvent === 'undefined') {
6
- // @ts-expect-error — minimal polyfill for testing
7
- globalThis.PointerEvent = class PointerEvent extends MouseEvent {
8
- constructor(type, init) {
9
- super(type, init);
10
- }
11
- };
12
- }
13
- /**
14
- * spectral-ui#205 — `Command.Item` forwards native HTML attributes and handlers
15
- * to its real `role="option"` node.
16
- *
17
- * Contract pinned here:
18
- * - consumer attributes (`title`, `aria-*`, `data-testid`, `style`, …) reach
19
- * the option, and a value reassigned by the parent AFTER mount is reflected;
20
- * - the option's IDENTITY stays under the component's control: `role`, `id`,
21
- * `tabindex`, `aria-selected`, `aria-disabled` and the internal `data-*`
22
- * (`data-command-item`, `data-value`, `data-selected`, `data-disabled`)
23
- * cannot be overridden — the spread comes FIRST, the identity comes after;
24
- * - native handlers COMPOSE with the built-in behaviour: the consumer's runs
25
- * first, `preventDefault()` cancels the Spectral selection, `onSelect` only
26
- * fires after a real selection;
27
- * - activation of a disabled row is inert: consumer `onclick` / `onkeydown` do
28
- * not run either, while `onpointermove` stays observable (a dimmed row can
29
- * still be hovered) without ever selecting the row.
30
- *
31
- * Tests titled `guard —` were already green on the pre-#205 tree (nothing was
32
- * forwarded, so nothing could be overridden, leaked or mis-composed); their
33
- * discriminating power comes from the mutant campaign below, each mutant
34
- * applied alone on the final tree and killed by the named test(s):
35
- * - spread placed LAST → identity guard, Enter-from-input guard
36
- * - rest not spread → forwarding, post-mount reactivity, identity
37
- * - `keywords` left in rest → no-leak guard
38
- * - consumer handler run BEFORE the disabled guard → disabled-inert guard
39
- * - onclick / onkeydown / onpointermove ignore `defaultPrevented` → cancel pins
40
- * - onkeydown not composed → onkeydown compose + cancel
41
- * - rest captured statically at init → post-mount reactivity
42
- * - `data-command-item` rendered boolean → identity
43
- * - onpointermove guarded on disabled → disabled-observable pin
44
- * - hover routed through `select()` → hover-does-not-fire-onSelect guard
45
- * - Space branch dropped → Space activation guard
46
- * - disabled keydown returns before `preventDefault()` → disabled-Space pin
47
- * - `'id'` dropped from the type's `Omit` → `src/__typecheck__` pin
48
- *
49
- * Keyboard note: Enter pressed in the INPUT activates the selected option
50
- * through a synthetic `click()` (command-input.svelte), so a consumer observes
51
- * that path through `onclick`, not `onkeydown`.
52
- */
53
- describe('command item — native attribute passthrough (#205)', () => {
54
- let target;
55
- let instance;
56
- function setup(props = {}) {
57
- target = document.createElement('div');
58
- document.body.appendChild(target);
59
- instance = mount(CommandTest, { target, props: { portalTo: target, ...props } });
60
- flushSync();
61
- flushSync(); // $effect item registration
62
- return target;
63
- }
64
- const option = (value) => target.querySelector(`[role="option"][data-value="${value}"]`);
65
- const input = () => target.querySelector('input[role="combobox"]');
66
- afterEach(() => {
67
- if (instance)
68
- unmount(instance);
69
- target?.remove();
70
- });
71
- // ── Forwarding ────────────────────────────────────────────────────────
72
- it('forwards consumer HTML attributes to the option element', () => {
73
- setup({
74
- itemAttrs: {
75
- title: 'Copy the selection',
76
- 'aria-label': 'Copy',
77
- 'aria-describedby': 'copy-hint',
78
- 'data-testid': 'opt-copy',
79
- style: 'color: red',
80
- },
81
- });
82
- const el = option('copy');
83
- expect(el.getAttribute('title')).toBe('Copy the selection');
84
- expect(el.getAttribute('aria-label')).toBe('Copy');
85
- expect(el.getAttribute('aria-describedby')).toBe('copy-hint');
86
- expect(el.getAttribute('data-testid')).toBe('opt-copy');
87
- expect(el.style.color).toBe('red');
88
- });
89
- it('reflects a consumer attribute reassigned by the parent after mount', () => {
90
- target = document.createElement('div');
91
- document.body.appendChild(target);
92
- const props = $state({
93
- portalTo: target,
94
- itemAttrs: { title: 'Before', 'aria-describedby': 'hint-before' },
95
- });
96
- instance = mount(CommandTest, { target, props });
97
- flushSync();
98
- expect(option('copy').getAttribute('title')).toBe('Before');
99
- props.itemAttrs = { title: 'After', 'aria-describedby': 'hint-after' };
100
- flushSync();
101
- expect(option('copy').getAttribute('title')).toBe('After');
102
- expect(option('copy').getAttribute('aria-describedby')).toBe('hint-after');
103
- });
104
- it('guard — keeps the DS class alongside a consumer class', () => {
105
- setup({ itemAttrs: { class: 'mine' } });
106
- const el = option('copy');
107
- expect(el.classList.contains('sp-command-item')).toBe(true);
108
- expect(el.classList.contains('mine')).toBe(true);
109
- });
110
- // ── Identity stays ours ───────────────────────────────────────────────
111
- it('keeps its identity attributes when a consumer tries to override them', () => {
112
- setup({
113
- itemAttrs: {
114
- role: 'menuitem',
115
- id: 'consumer-id',
116
- tabindex: 0,
117
- 'aria-selected': 'false',
118
- 'aria-disabled': 'true',
119
- 'data-selected': 'false',
120
- 'data-value': 'leak',
121
- 'data-disabled': '',
122
- 'data-command-item': 'nope',
123
- 'data-testid': 'still-forwarded',
124
- },
125
- });
126
- // `copy` is the first enabled item → auto-selected.
127
- const el = target.querySelector('[data-testid="still-forwarded"]');
128
- expect(el).toBeTruthy();
129
- expect(el.getAttribute('role')).toBe('option');
130
- expect(el.id).toMatch(/^sp-command-item-\d+$/);
131
- expect(el.getAttribute('tabindex')).toBe('-1');
132
- expect(el.getAttribute('aria-selected')).toBe('true');
133
- expect(el.hasAttribute('aria-disabled')).toBe(false);
134
- expect(el.getAttribute('data-selected')).toBe('true');
135
- expect(el.getAttribute('data-value')).toBe('copy');
136
- expect(el.hasAttribute('data-disabled')).toBe(false);
137
- // `data-command-item` keeps its shipped form: present, empty-valued.
138
- expect(el.hasAttribute('data-command-item')).toBe(true);
139
- expect(el.getAttribute('data-command-item')).toBe('');
140
- });
141
- it('guard — Enter in the input activates the item Spectral selected, whatever the consumer claims', () => {
142
- const selected = [];
143
- setup({
144
- itemAttrs: { 'data-selected': 'false' },
145
- onItemSelect: (v) => selected.push(v),
146
- });
147
- input().dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
148
- flushSync();
149
- expect(selected).toEqual(['copy']);
150
- });
151
- it('guard — does not leak component props to the DOM', () => {
152
- setup({ onItemSelect: () => { } });
153
- const copy = option('copy');
154
- // (`on*` keys never surface as attributes in Svelte, so only these can fail.)
155
- for (const attr of ['value', 'keywords']) {
156
- expect(copy.hasAttribute(attr)).toBe(false);
157
- }
158
- expect(option('settings').hasAttribute('disabled')).toBe(false);
159
- });
160
- // ── Handler composition ───────────────────────────────────────────────
161
- it('composes a consumer onclick with the built-in selection (consumer first)', () => {
162
- const seen = [];
163
- setup({
164
- itemAttrs: { onclick: () => seen.push('consumer') },
165
- onItemSelect: (v) => seen.push(`selected:${v}`),
166
- });
167
- option('copy').click();
168
- flushSync();
169
- expect(seen).toEqual(['consumer', 'selected:copy']);
170
- });
171
- it('lets a consumer onclick cancel the selection with preventDefault', () => {
172
- const selected = [];
173
- setup({
174
- itemAttrs: { onclick: (e) => e.preventDefault() },
175
- onItemSelect: (v) => selected.push(v),
176
- });
177
- // Move the selection away first, so a (wrongly) successful click is visible.
178
- input().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }));
179
- flushSync();
180
- expect(option('paste').getAttribute('data-selected')).toBe('true');
181
- option('copy').click();
182
- flushSync();
183
- expect(selected).toEqual([]);
184
- expect(option('copy').getAttribute('data-selected')).toBe('false');
185
- expect(option('paste').getAttribute('data-selected')).toBe('true');
186
- });
187
- it('composes a consumer onkeydown with Enter on the option (consumer first)', () => {
188
- const seen = [];
189
- setup({
190
- itemAttrs: { onkeydown: () => seen.push('consumer') },
191
- onItemSelect: (v) => seen.push(`selected:${v}`),
192
- });
193
- option('copy').dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true }));
194
- flushSync();
195
- expect(seen).toEqual(['consumer', 'selected:copy']);
196
- });
197
- it('guard — composes a consumer onkeydown with Space on the option (consumer first)', () => {
198
- const seen = [];
199
- setup({
200
- itemAttrs: { onkeydown: () => seen.push('consumer') },
201
- onItemSelect: (v) => seen.push(`selected:${v}`),
202
- });
203
- option('copy').dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true, cancelable: true }));
204
- flushSync();
205
- expect(seen).toEqual(['consumer', 'selected:copy']);
206
- });
207
- it('lets a consumer onkeydown cancel the Enter/Space activation with preventDefault', () => {
208
- const selected = [];
209
- setup({
210
- itemAttrs: { onkeydown: (e) => e.preventDefault() },
211
- onItemSelect: (v) => selected.push(v),
212
- });
213
- option('copy').dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true, cancelable: true }));
214
- flushSync();
215
- expect(selected).toEqual([]);
216
- });
217
- it('composes a consumer onpointermove with the hover-selection — which never fires onSelect', () => {
218
- const seen = [];
219
- setup({
220
- itemAttrs: { onpointermove: () => seen.push('consumer') },
221
- onItemSelect: (v) => seen.push(`selected:${v}`),
222
- });
223
- // Start from a different selection so the hover-select is observable.
224
- input().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }));
225
- flushSync();
226
- expect(option('paste').getAttribute('data-selected')).toBe('true');
227
- option('copy').dispatchEvent(new PointerEvent('pointermove', { bubbles: true, cancelable: true }));
228
- flushSync();
229
- expect(seen).toEqual(['consumer']);
230
- expect(option('copy').getAttribute('data-selected')).toBe('true');
231
- });
232
- it('lets a consumer onpointermove cancel the hover-selection with preventDefault', () => {
233
- setup({ itemAttrs: { onpointermove: (e) => e.preventDefault() } });
234
- input().dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }));
235
- flushSync();
236
- option('copy').dispatchEvent(new PointerEvent('pointermove', { bubbles: true, cancelable: true }));
237
- flushSync();
238
- expect(option('copy').getAttribute('data-selected')).toBe('false');
239
- expect(option('paste').getAttribute('data-selected')).toBe('true');
240
- });
241
- // ── Disabled: activation inert, hover observable ──────────────────────
242
- it('guard — activation of a disabled item is inert: consumer onclick/onkeydown do not run', () => {
243
- const seen = [];
244
- setup({
245
- disabledItemAttrs: {
246
- onclick: () => seen.push('click'),
247
- onkeydown: () => seen.push('keydown'),
248
- },
249
- onDisabledItemSelect: (v) => seen.push(`selected:${v}`),
250
- });
251
- const settings = option('settings');
252
- settings.click();
253
- settings.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
254
- flushSync();
255
- expect(seen).toEqual([]);
256
- expect(option('copy').getAttribute('data-selected')).toBe('true');
257
- expect(settings.getAttribute('data-selected')).toBe('false');
258
- });
259
- it('still prevents the Space default on a focused disabled item, without running the consumer onkeydown', () => {
260
- const seen = [];
261
- setup({ disabledItemAttrs: { onkeydown: () => seen.push('keydown') } });
262
- const event = new KeyboardEvent('keydown', { key: ' ', bubbles: true, cancelable: true });
263
- option('settings').dispatchEvent(event);
264
- flushSync();
265
- // Pre-#205 the item prevented Enter/Space before bailing on `disabled`,
266
- // so Space on a dimmed, focused row never scrolled the list.
267
- expect(event.defaultPrevented).toBe(true);
268
- expect(seen).toEqual([]);
269
- expect(option('copy').getAttribute('data-selected')).toBe('true');
270
- });
271
- it('keeps a consumer onpointermove observable on a disabled item without selecting it', () => {
272
- const seen = [];
273
- setup({
274
- disabledItemAttrs: { onpointermove: () => seen.push('move') },
275
- onDisabledItemSelect: (v) => seen.push(`selected:${v}`),
276
- });
277
- const settings = option('settings');
278
- settings.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, cancelable: true }));
279
- flushSync();
280
- expect(seen).toEqual(['move']);
281
- expect(settings.getAttribute('data-selected')).toBe('false');
282
- expect(option('copy').getAttribute('data-selected')).toBe('true');
283
- });
284
- });