@human-kit/ui 1.0.0-beta.7 → 1.0.0-beta.8

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 (167) hide show
  1. package/dist/FOCUS_STATE_CONTRACT.md +15 -4
  2. package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
  3. package/dist/avatar/README.md +52 -0
  4. package/dist/avatar/count/avatar-count.svelte +56 -0
  5. package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
  6. package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
  7. package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
  8. package/dist/avatar/group/avatar-group.svelte +65 -0
  9. package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
  10. package/dist/avatar/group/context.d.ts +15 -0
  11. package/dist/avatar/group/context.js +15 -0
  12. package/dist/avatar/image/avatar-image.svelte +104 -0
  13. package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
  14. package/dist/avatar/index.d.ts +22 -0
  15. package/dist/avatar/index.js +10 -0
  16. package/dist/avatar/index.parts.d.ts +5 -0
  17. package/dist/avatar/index.parts.js +5 -0
  18. package/dist/avatar/root/avatar-root.svelte +79 -0
  19. package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
  20. package/dist/avatar/root/context.d.ts +14 -0
  21. package/dist/avatar/root/context.js +15 -0
  22. package/dist/avatar/types.d.ts +84 -0
  23. package/dist/avatar/types.js +1 -0
  24. package/dist/breadcrumbs/README.md +65 -0
  25. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
  26. package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
  27. package/dist/breadcrumbs/index.d.ts +23 -0
  28. package/dist/breadcrumbs/index.js +10 -0
  29. package/dist/breadcrumbs/index.parts.d.ts +6 -0
  30. package/dist/breadcrumbs/index.parts.js +6 -0
  31. package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
  32. package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
  33. package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
  34. package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
  35. package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
  36. package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
  37. package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
  38. package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
  39. package/dist/breadcrumbs/root/context.d.ts +19 -0
  40. package/dist/breadcrumbs/root/context.js +15 -0
  41. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
  42. package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
  43. package/dist/breadcrumbs/types.d.ts +80 -0
  44. package/dist/breadcrumbs/types.js +1 -0
  45. package/dist/combobox/popover/combobox-popover.svelte +4 -56
  46. package/dist/dialog/root/dialog-root.svelte +15 -2
  47. package/dist/drawer/root/drawer-root.svelte +15 -2
  48. package/dist/index.d.ts +14 -0
  49. package/dist/index.js +13 -0
  50. package/dist/internal/localized-strings.d.ts +48 -0
  51. package/dist/internal/localized-strings.js +48 -0
  52. package/dist/internal/number-precision.d.ts +9 -0
  53. package/dist/internal/number-precision.js +27 -0
  54. package/dist/menu/root/focus-state.d.ts +2 -2
  55. package/dist/menu/root/focus-state.js +8 -32
  56. package/dist/menu/root/menu-state.svelte.js +5 -1
  57. package/dist/numberfield/root/number-utils.js +1 -20
  58. package/dist/popover/root/focus-state.d.ts +2 -2
  59. package/dist/popover/root/focus-state.js +7 -34
  60. package/dist/primitives/contain-wheel.d.ts +9 -0
  61. package/dist/primitives/contain-wheel.js +41 -0
  62. package/dist/primitives/floating.d.ts +6 -0
  63. package/dist/primitives/floating.js +26 -5
  64. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  65. package/dist/primitives/keyboard-navigation.js +2 -1
  66. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  67. package/dist/primitives/trigger-focus-state.js +57 -0
  68. package/dist/progress/README.md +54 -0
  69. package/dist/progress/index.d.ts +21 -0
  70. package/dist/progress/index.js +9 -0
  71. package/dist/progress/index.parts.d.ts +5 -0
  72. package/dist/progress/index.parts.js +5 -0
  73. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  74. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  75. package/dist/progress/label/progress-label.svelte +34 -0
  76. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  77. package/dist/progress/root/context.d.ts +26 -0
  78. package/dist/progress/root/context.js +15 -0
  79. package/dist/progress/root/progress-root.svelte +136 -0
  80. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  81. package/dist/progress/root/progress-utils.d.ts +12 -0
  82. package/dist/progress/root/progress-utils.js +41 -0
  83. package/dist/progress/track/progress-track.svelte +27 -0
  84. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  85. package/dist/progress/types.d.ts +81 -0
  86. package/dist/progress/types.js +1 -0
  87. package/dist/progress/value/progress-value.svelte +36 -0
  88. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  89. package/dist/select/README.md +129 -0
  90. package/dist/select/index.d.ts +30 -0
  91. package/dist/select/index.js +16 -0
  92. package/dist/select/index.parts.d.ts +8 -0
  93. package/dist/select/index.parts.js +9 -0
  94. package/dist/select/item/select-item.svelte +68 -0
  95. package/dist/select/item/select-item.svelte.d.ts +10 -0
  96. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  97. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  98. package/dist/select/label/select-label.svelte +46 -0
  99. package/dist/select/label/select-label.svelte.d.ts +4 -0
  100. package/dist/select/list/select-list.svelte +241 -0
  101. package/dist/select/list/select-list.svelte.d.ts +62 -0
  102. package/dist/select/popover/select-popover.svelte +80 -0
  103. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  104. package/dist/select/root/context.d.ts +106 -0
  105. package/dist/select/root/context.js +22 -0
  106. package/dist/select/root/select-root.svelte +544 -0
  107. package/dist/select/root/select-root.svelte.d.ts +25 -0
  108. package/dist/select/trigger/select-trigger.svelte +192 -0
  109. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  110. package/dist/select/types.d.ts +133 -0
  111. package/dist/select/types.js +1 -0
  112. package/dist/select/value/select-value.svelte +61 -0
  113. package/dist/select/value/select-value.svelte.d.ts +4 -0
  114. package/dist/separator/README.md +35 -0
  115. package/dist/separator/index.d.ts +7 -0
  116. package/dist/separator/index.js +3 -0
  117. package/dist/separator/separator.svelte +254 -0
  118. package/dist/separator/separator.svelte.d.ts +45 -0
  119. package/dist/separator/types.d.ts +1 -0
  120. package/dist/separator/types.js +1 -0
  121. package/dist/slider/README.md +61 -0
  122. package/dist/slider/fill/slider-fill.svelte +40 -0
  123. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  124. package/dist/slider/index.d.ts +9 -0
  125. package/dist/slider/index.js +8 -0
  126. package/dist/slider/index.parts.d.ts +6 -0
  127. package/dist/slider/index.parts.js +6 -0
  128. package/dist/slider/label/slider-label.svelte +44 -0
  129. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  130. package/dist/slider/output/slider-output.svelte +46 -0
  131. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  132. package/dist/slider/root/context.d.ts +106 -0
  133. package/dist/slider/root/context.js +15 -0
  134. package/dist/slider/root/slider-root.svelte +545 -0
  135. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  136. package/dist/slider/root/slider-utils.d.ts +57 -0
  137. package/dist/slider/root/slider-utils.js +88 -0
  138. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  139. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  140. package/dist/slider/track/slider-track.svelte +60 -0
  141. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  142. package/dist/slider/types.d.ts +144 -0
  143. package/dist/slider/types.js +1 -0
  144. package/dist/tooltip/README.md +53 -0
  145. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  146. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  147. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  148. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  149. package/dist/tooltip/index.d.ts +8 -0
  150. package/dist/tooltip/index.js +7 -0
  151. package/dist/tooltip/index.parts.d.ts +5 -0
  152. package/dist/tooltip/index.parts.js +5 -0
  153. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  154. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  155. package/dist/tooltip/root/context.d.ts +46 -0
  156. package/dist/tooltip/root/context.js +22 -0
  157. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  158. package/dist/tooltip/root/safe-polygon.js +66 -0
  159. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  160. package/dist/tooltip/root/tooltip-group.js +41 -0
  161. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  162. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  163. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  164. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  165. package/dist/tooltip/types.d.ts +105 -0
  166. package/dist/tooltip/types.js +1 -0
  167. package/package.json +36 -1
@@ -0,0 +1,55 @@
1
+ <script lang="ts">
2
+ import { getContext } from 'svelte';
3
+ import { SELECT_ITEM_CONTEXT_KEY, type SelectItemContext } from '../item/select-item.svelte';
4
+ import { useSelectContext } from '../root/context';
5
+ import type { SelectItemIndicatorProps } from '../types';
6
+
7
+ /**
8
+ * Select.ItemIndicator — the mark of a selected option. It is in the DOM only while its
9
+ * option is selected, unless `forceMount` keeps it.
10
+ */
11
+ let {
12
+ children,
13
+ forceMount = false,
14
+ class: className = '',
15
+ ...restProps
16
+ }: SelectItemIndicatorProps = $props();
17
+
18
+ const ctx = useSelectContext('Select.ItemIndicator');
19
+ const itemCtx = getContext<SelectItemContext | undefined>(SELECT_ITEM_CONTEXT_KEY);
20
+
21
+ if (!itemCtx) {
22
+ throw new Error('Select.ItemIndicator must be used inside a Select.Item');
23
+ }
24
+
25
+ const item = itemCtx;
26
+ const isSelected = $derived(ctx.selectedKeys.has(item.id));
27
+ const shouldRender = $derived(forceMount || isSelected);
28
+ </script>
29
+
30
+ {#if shouldRender}
31
+ <span
32
+ {...restProps}
33
+ aria-hidden="true"
34
+ class={className}
35
+ data-select-item-indicator="true"
36
+ data-state={isSelected ? 'checked' : 'unchecked'}
37
+ >
38
+ {#if children}
39
+ {@render children()}
40
+ {:else}
41
+ <svg
42
+ xmlns="http://www.w3.org/2000/svg"
43
+ viewBox="0 0 16 16"
44
+ fill="currentColor"
45
+ style="width:1rem;height:1rem"
46
+ >
47
+ <path
48
+ fill-rule="evenodd"
49
+ d="M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z"
50
+ clip-rule="evenodd"
51
+ />
52
+ </svg>
53
+ {/if}
54
+ </span>
55
+ {/if}
@@ -0,0 +1,4 @@
1
+ import type { SelectItemIndicatorProps } from '../types';
2
+ declare const SelectItemIndicator: import("svelte").Component<SelectItemIndicatorProps, {}, "">;
3
+ type SelectItemIndicator = ReturnType<typeof SelectItemIndicator>;
4
+ export default SelectItemIndicator;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { useSelectContext } from '../root/context';
3
+ import type { SelectLabelProps } from '../types';
4
+
5
+ /**
6
+ * Select.Label — the accessible name of the field.
7
+ *
8
+ * It is a native `<label>` for the trigger: a button is a labelable element, thus a click
9
+ * on the text moves the focus to the trigger. It also registers its id with the root, and
10
+ * the trigger reads it into `aria-labelledby`, because the combobox role takes its name
11
+ * from that attribute and not from the content of the button.
12
+ */
13
+ let {
14
+ children,
15
+ class: className = '',
16
+ id: idProp,
17
+ onclick: onClickExternal,
18
+ ...restProps
19
+ }: SelectLabelProps = $props();
20
+
21
+ const ctx = useSelectContext('Select.Label');
22
+ const id = $derived(idProp ?? `select-label-${ctx.instanceId}`);
23
+
24
+ $effect(() => ctx.registerLabel(id));
25
+
26
+ // A click on a native label activates its button, and that would open the list. A click on
27
+ // the label of a native select only moves the focus, and this does the same.
28
+ function handleClick(event: MouseEvent & { currentTarget: EventTarget & HTMLLabelElement }) {
29
+ onClickExternal?.(event);
30
+ if (event.defaultPrevented) return;
31
+ event.preventDefault();
32
+ if (!ctx.isDisabled) ctx.triggerRef?.focus();
33
+ }
34
+ </script>
35
+
36
+ <label
37
+ {...restProps}
38
+ {id}
39
+ for={ctx.triggerId}
40
+ class={className}
41
+ onclick={handleClick}
42
+ data-select-label="true"
43
+ data-disabled={ctx.isDisabled || undefined}
44
+ >
45
+ {@render children?.()}
46
+ </label>
@@ -0,0 +1,4 @@
1
+ import type { SelectLabelProps } from '../types';
2
+ declare const SelectLabel: import("svelte").Component<SelectLabelProps, {}, "">;
3
+ type SelectLabel = ReturnType<typeof SelectLabel>;
4
+ export default SelectLabel;
@@ -0,0 +1,241 @@
1
+ <script lang="ts" generics="T extends object = object">
2
+ import { tick, untrack } from 'svelte';
3
+ import { ListBoxRoot as ListBox, type ListBoxContext } from '../../listbox';
4
+ import { useSelectContext, type SelectKey } from '../root/context';
5
+ import type { ComponentProps, Snippet } from 'svelte';
6
+
7
+ type SelectListProps = Omit<
8
+ ComponentProps<typeof ListBox>,
9
+ | 'selectionMode'
10
+ | 'selectionBehavior'
11
+ | 'value'
12
+ | 'defaultValue'
13
+ | 'controlledValue'
14
+ | 'onChange'
15
+ | 'context'
16
+ | 'element'
17
+ | 'children'
18
+ | 'items'
19
+ | 'id'
20
+ | 'disabledKeys'
21
+ | 'disableFocusHandling'
22
+ | 'loop'
23
+ | 'typeahead'
24
+ | 'aria-label'
25
+ | 'aria-labelledby'
26
+ > & {
27
+ /**
28
+ * The items, for a list that the component makes from an array. Use it with a snippet that
29
+ * receives one item. Give the same array to the root, so the trigger knows the text of each
30
+ * key while the popover is closed.
31
+ */
32
+ items?: Iterable<T>;
33
+ /** The content of the list. From an array of items, it receives one item. */
34
+ children?: Snippet<[T]> | Snippet;
35
+ };
36
+
37
+ /**
38
+ * Select.List — the listbox inside the popover.
39
+ *
40
+ * It is `ListBox.Root` with the selection of the select. The focus goes into it when the
41
+ * popover opens, on the selected option, thus the arrow keys, `Home`, `End` and the
42
+ * typeahead of the listbox operate the select. It adds `PageUp` and `PageDown`, which move
43
+ * the focus ten options, and it closes the popover on `Tab`.
44
+ */
45
+ let {
46
+ children,
47
+ items,
48
+ onkeydowncapture: onKeyDownCaptureExternal,
49
+ onfocusin: onFocusInExternal,
50
+ onfocusout: onFocusOutExternal,
51
+ ...props
52
+ }: SelectListProps = $props();
53
+
54
+ const ctx = useSelectContext('Select.List');
55
+
56
+ let listboxCtx: ListBoxContext | undefined = $state();
57
+ let listboxElement: HTMLElement | undefined = $state();
58
+
59
+ const listboxSelection = $derived(Array.from(ctx.selectedKeys));
60
+ const disabledKeys = $derived(Array.from(ctx.disabledKeys));
61
+ // A second press on the selected option must not clear it: the field always has an answer,
62
+ // the same as a native select. In the multiple mode a press toggles.
63
+ const selectionBehavior = $derived(ctx.selectionMode === 'single' ? 'replace' : 'toggle');
64
+
65
+ $effect(() => {
66
+ const current = listboxCtx ?? null;
67
+ ctx.setListboxCtx(current);
68
+ return () => {
69
+ if (ctx.listboxCtx === current) ctx.setListboxCtx(null);
70
+ };
71
+ });
72
+
73
+ $effect(() => {
74
+ const current = listboxElement ?? null;
75
+ ctx.setListboxRef(current);
76
+ return () => {
77
+ if (ctx.listboxRef === current) ctx.setListboxRef(null);
78
+ };
79
+ });
80
+
81
+ function handleSelectionChange(selection: Set<SelectKey>) {
82
+ ctx.commitSelection(selection);
83
+ }
84
+
85
+ // The root shows one focus state for the trigger and the list together: the list is in a
86
+ // portal, thus the root cannot read it from its own descendants.
87
+ $effect(() => {
88
+ if (!listboxCtx) return;
89
+ return listboxCtx.subscribeToFocusVisible((visible) => {
90
+ if (ctx.isFocusWithin) ctx.setFocusVisible(visible);
91
+ });
92
+ });
93
+
94
+ function handleFocusIn(event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) {
95
+ ctx.setFocusWithin(true);
96
+ onFocusInExternal?.(event);
97
+ }
98
+
99
+ function handleFocusOut(event: FocusEvent & { currentTarget: EventTarget & HTMLDivElement }) {
100
+ queueMicrotask(() => {
101
+ const active = document.activeElement;
102
+ const trigger = ctx.triggerRef;
103
+ const inTrigger = !!trigger && (active === trigger || trigger.contains(active));
104
+ const inList =
105
+ !!listboxElement && (active === listboxElement || listboxElement.contains(active));
106
+ if (!inTrigger && !inList) {
107
+ ctx.setFocusWithin(false);
108
+ }
109
+ });
110
+ onFocusOutExternal?.(event);
111
+ }
112
+
113
+ function getEnabledOptions(): HTMLElement[] {
114
+ if (!listboxElement) return [];
115
+ return Array.from(
116
+ listboxElement.querySelectorAll<HTMLElement>('[data-navigation-item]:not([data-disabled])')
117
+ );
118
+ }
119
+
120
+ function readOptionKey(option: HTMLElement | null): SelectKey | null {
121
+ if (!option || option.getAttribute('role') !== 'option') return null;
122
+ const raw = option.dataset.itemId;
123
+ if (raw === undefined) return null;
124
+ return option.dataset.itemIdType === 'number' ? Number(raw) : raw;
125
+ }
126
+
127
+ function focusOptionByKey(key: SelectKey) {
128
+ listboxCtx?.keyboardNav.focusById(key);
129
+ }
130
+
131
+ /**
132
+ * Puts the focus in the list when the popover opens.
133
+ *
134
+ * The selected option, when there is one and it is enabled; otherwise the first or the
135
+ * last option, as the key that opened the popover asked. A character typed on the closed
136
+ * trigger is searched afterwards, thus the focus lands on the option that starts with it.
137
+ */
138
+ async function applyOpenFocus() {
139
+ await tick();
140
+ if (!ctx.isOpen || !listboxCtx || !listboxElement) return;
141
+ listboxCtx.keyboardNav.updateItems();
142
+ const intent = ctx.consumeOpenFocus();
143
+ const [selected] = ctx.selectedKeys;
144
+ const enabledKeys = new Set(
145
+ getEnabledOptions()
146
+ .map((option) => readOptionKey(option))
147
+ .filter((key): key is SelectKey => key !== null)
148
+ );
149
+
150
+ if (intent === 'last') {
151
+ listboxCtx.keyboardNav.focusLast();
152
+ } else if (intent === 'selected' && selected !== undefined && enabledKeys.has(selected)) {
153
+ focusOptionByKey(selected);
154
+ } else {
155
+ listboxCtx.keyboardNav.focusFirst();
156
+ }
157
+
158
+ const char = ctx.consumePendingTypeahead();
159
+ if (char) {
160
+ listboxCtx.keyboardNav.typeahead(char);
161
+ }
162
+ }
163
+
164
+ let wasOpen = false;
165
+ $effect(() => {
166
+ const open = ctx.isOpen;
167
+ const ready = Boolean(listboxCtx && listboxElement);
168
+ if (open && ready && !wasOpen) {
169
+ wasOpen = true;
170
+ untrack(() => void applyOpenFocus());
171
+ } else if (!open) {
172
+ wasOpen = false;
173
+ }
174
+ });
175
+
176
+ // The listbox itself has the arrows, `Home`, `End`, `Enter`, `Space` and the typeahead. This
177
+ // runs in the capture phase, before the listbox: its own handler takes `ArrowUp` for a move,
178
+ // and it would move the focus before `Alt+ArrowUp` can close.
179
+ function handleKeyDownCapture(
180
+ event: KeyboardEvent & { currentTarget: EventTarget & HTMLDivElement }
181
+ ) {
182
+ onKeyDownCaptureExternal?.(event);
183
+ if (event.defaultPrevented) return;
184
+
185
+ if (event.key === 'Tab') {
186
+ // The focus goes to the trigger first, without `preventDefault`, so the browser
187
+ // continues from there: from the portal it would land at the end of the document.
188
+ ctx.triggerRef?.focus();
189
+ ctx.close('focus-out', event);
190
+ return;
191
+ }
192
+
193
+ if (event.key === 'PageUp' || event.key === 'PageDown') {
194
+ event.preventDefault();
195
+ const options = getEnabledOptions();
196
+ if (options.length === 0) return;
197
+ const active = document.activeElement as HTMLElement | null;
198
+ const currentIndex = active ? options.indexOf(active) : -1;
199
+ const step = event.key === 'PageDown' ? 10 : -10;
200
+ const nextIndex = Math.min(options.length - 1, Math.max(0, currentIndex + step));
201
+ const key = readOptionKey(options[nextIndex]);
202
+ if (key !== null) focusOptionByKey(key);
203
+ return;
204
+ }
205
+
206
+ // Alt+ArrowUp selects the focused option and closes the list, as in the APG pattern. With
207
+ // nothing focused it only closes.
208
+ if (event.key === 'ArrowUp' && event.altKey) {
209
+ event.preventDefault();
210
+ event.stopPropagation();
211
+ const active = document.activeElement as HTMLElement | null;
212
+ const key = readOptionKey(active);
213
+ if (key !== null && listboxCtx && !listboxCtx.isDisabled(key)) {
214
+ listboxCtx.select(key);
215
+ if (!ctx.isOpen) return;
216
+ }
217
+ ctx.close('imperative-action', event);
218
+ }
219
+ }
220
+ </script>
221
+
222
+ <ListBox
223
+ {...props}
224
+ bind:context={listboxCtx}
225
+ bind:element={listboxElement}
226
+ id={ctx.listboxId}
227
+ {items}
228
+ {children}
229
+ selectionMode={ctx.selectionMode}
230
+ {selectionBehavior}
231
+ {disabledKeys}
232
+ loop={ctx.loop}
233
+ typeahead={true}
234
+ value={listboxSelection}
235
+ onChange={handleSelectionChange}
236
+ aria-labelledby={ctx.triggerId}
237
+ data-select-list="true"
238
+ onkeydowncapture={handleKeyDownCapture}
239
+ onfocusin={handleFocusIn}
240
+ onfocusout={handleFocusOut}
241
+ />
@@ -0,0 +1,62 @@
1
+ import { type ListBoxContext } from '../../listbox';
2
+ import type { Snippet } from 'svelte';
3
+ declare function $$render<T extends object = object>(): {
4
+ props: Omit<{
5
+ selectionBehavior?: "toggle" | "replace";
6
+ emptyPlaceholder?: string | Snippet;
7
+ items?: Iterable<object> | undefined;
8
+ getItemKey?: ((item: object) => string | number) | undefined;
9
+ disabledKeys?: Iterable<string | number>;
10
+ selectionMode?: "single" | "multiple";
11
+ value?: Iterable<string | number>;
12
+ defaultValue?: Iterable<string | number>;
13
+ controlledValue?: boolean;
14
+ children?: Snippet<[]> | Snippet<[object]> | undefined;
15
+ header?: Snippet;
16
+ class?: string;
17
+ id?: string;
18
+ 'aria-label'?: string;
19
+ 'aria-labelledby'?: string;
20
+ onChange?: ((value: Set<string | number>) => void) | undefined;
21
+ disableFocusHandling?: boolean;
22
+ loop?: boolean;
23
+ typeahead?: boolean;
24
+ virtualizer?: {
25
+ rowHeight?: number;
26
+ overscan?: number;
27
+ } | undefined;
28
+ } & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class" | "id" | "role" | "aria-label" | "aria-labelledby" | "onchange"> & {
29
+ context?: ListBoxContext;
30
+ element?: HTMLElement;
31
+ }, "children" | "id" | "aria-label" | "aria-labelledby" | "value" | "element" | "defaultValue" | "controlledValue" | "onChange" | "selectionMode" | "loop" | "context" | "typeahead" | "disableFocusHandling" | "selectionBehavior" | "items" | "disabledKeys"> & {
32
+ /**
33
+ * The items, for a list that the component makes from an array. Use it with a snippet that
34
+ * receives one item. Give the same array to the root, so the trigger knows the text of each
35
+ * key while the popover is closed.
36
+ */
37
+ items?: Iterable<T>;
38
+ /** The content of the list. From an array of items, it receives one item. */
39
+ children?: Snippet<[T]> | Snippet;
40
+ };
41
+ exports: {};
42
+ bindings: "";
43
+ slots: {};
44
+ events: {};
45
+ };
46
+ declare class __sveltets_Render<T extends object = object> {
47
+ props(): ReturnType<typeof $$render<T>>['props'];
48
+ events(): ReturnType<typeof $$render<T>>['events'];
49
+ slots(): ReturnType<typeof $$render<T>>['slots'];
50
+ bindings(): "";
51
+ exports(): {};
52
+ }
53
+ interface $$IsomorphicComponent {
54
+ new <T extends object = object>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
55
+ $$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
56
+ } & ReturnType<__sveltets_Render<T>['exports']>;
57
+ <T extends object = object>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
58
+ z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
59
+ }
60
+ declare const SelectList: $$IsomorphicComponent;
61
+ type SelectList<T extends object = object> = InstanceType<typeof SelectList<T>>;
62
+ export default SelectList;
@@ -0,0 +1,80 @@
1
+ <script lang="ts">
2
+ import { Popover } from '../../popover';
3
+ import type { PopoverOpenChangeDetails } from '../../popover/root/context';
4
+ import { containWheel } from '../../primitives/contain-wheel';
5
+ import { useSelectContext, type SelectCloseReason } from '../root/context';
6
+ import type { ComponentProps, Snippet } from 'svelte';
7
+
8
+ type SelectPopoverProps = Omit<
9
+ ComponentProps<typeof Popover.Content>,
10
+ 'open' | 'triggerRef' | 'onOpenChange' | 'children' | 'role' | 'initialFocus'
11
+ > & {
12
+ /** The content: the list. */
13
+ children?: Snippet;
14
+ };
15
+
16
+ /**
17
+ * Select.Popover — the floating panel that holds the list.
18
+ *
19
+ * It is `Popover.Content` with the state of the select. The panel is not a dialog: it has
20
+ * `role="presentation"`, thus the listbox inside it is what the trigger controls and what
21
+ * assistive technology lands on.
22
+ */
23
+ let {
24
+ class: className = '',
25
+ children,
26
+ placement = 'bottom-start',
27
+ nonModal = true,
28
+ onwheel: onWheelExternal,
29
+ ...contentProps
30
+ }: SelectPopoverProps = $props();
31
+
32
+ const ctx = useSelectContext('Select.Popover');
33
+
34
+ const POPOVER_TO_SELECT_REASON: Record<string, SelectCloseReason> = {
35
+ 'escape-key': 'escape-key',
36
+ 'outside-press': 'outside-press',
37
+ 'focus-out': 'focus-out',
38
+ scroll: 'scroll',
39
+ 'close-press': 'imperative-action',
40
+ 'imperative-action': 'imperative-action',
41
+ none: 'none'
42
+ };
43
+
44
+ // The root holds the open state. A close that `Popover.Content` asks for (Escape, an
45
+ // outside press, a Tab out, a scroll) goes to the root, and a refusal of the consumer goes
46
+ // back to `Popover.Root` through the same details, so both agree. `Popover.Root` then
47
+ // applies the focus state of the trigger, as it does for every popover.
48
+ function handleOpenChange(open: boolean, details: PopoverOpenChangeDetails) {
49
+ if (open) {
50
+ ctx.open('trigger-press', details.event);
51
+ return;
52
+ }
53
+ const reason = POPOVER_TO_SELECT_REASON[details.reason] ?? 'imperative-action';
54
+ if (!ctx.close(reason, details.event)) {
55
+ details.cancel();
56
+ }
57
+ }
58
+
59
+ function handleWheel(event: WheelEvent & { currentTarget: EventTarget & HTMLDivElement }) {
60
+ containWheel(event, event.currentTarget);
61
+ onWheelExternal?.(event);
62
+ }
63
+ </script>
64
+
65
+ <Popover.Root open={ctx.isOpen} triggerRef={ctx.triggerRef} onOpenChange={handleOpenChange}>
66
+ <Popover.Content
67
+ {nonModal}
68
+ {placement}
69
+ class={className}
70
+ role="presentation"
71
+ aria-modal={undefined}
72
+ data-select-popover="true"
73
+ onwheel={handleWheel}
74
+ {...contentProps}
75
+ >
76
+ {#if children}
77
+ {@render children()}
78
+ {/if}
79
+ </Popover.Content>
80
+ </Popover.Root>
@@ -0,0 +1,9 @@
1
+ import { Popover } from '../../popover';
2
+ import type { ComponentProps, Snippet } from 'svelte';
3
+ type SelectPopoverProps = Omit<ComponentProps<typeof Popover.Content>, 'open' | 'triggerRef' | 'onOpenChange' | 'children' | 'role' | 'initialFocus'> & {
4
+ /** The content: the list. */
5
+ children?: Snippet;
6
+ };
7
+ declare const SelectPopover: import("svelte").Component<SelectPopoverProps, {}, "">;
8
+ type SelectPopover = ReturnType<typeof SelectPopover>;
9
+ export default SelectPopover;
@@ -0,0 +1,106 @@
1
+ import type { ListBoxContext } from '../../listbox/root/context';
2
+ import type { PopoverCloseReason } from '../../popover/root/context';
3
+ export type SelectKey = string | number;
4
+ /**
5
+ * The reasons of Popover, less its close button, plus the two of a select: a press on the open
6
+ * trigger, and a selection.
7
+ */
8
+ export type SelectCloseReason = Exclude<PopoverCloseReason, 'close-press'> | 'trigger-press' | 'item-select';
9
+ export type SelectOpenReason = 'trigger-press' | 'imperative-action' | 'none';
10
+ export type SelectChangeReason = SelectOpenReason | SelectCloseReason;
11
+ export type SelectOpenChangeDetails = {
12
+ reason: SelectChangeReason;
13
+ event?: Event;
14
+ cancel: () => void;
15
+ isCanceled: boolean;
16
+ };
17
+ /** Where the focus lands in the list when the popover opens. */
18
+ export type SelectOpenFocusIntent = 'selected' | 'first' | 'last';
19
+ /**
20
+ * Context shared between Select.Root and its parts.
21
+ */
22
+ export type SelectContext = {
23
+ /** The instance id. Every ARIA id of the parts is made from it. */
24
+ instanceId: string;
25
+ /** The id of the trigger element. */
26
+ triggerId: string;
27
+ /** The id of the listbox element. */
28
+ listboxId: string;
29
+ /** The id of the `Select.Value` element, when one is in the DOM. */
30
+ valueId: string | null;
31
+ /** The id of the `Select.Label` element, when one is in the DOM. */
32
+ labelId: string | null;
33
+ /** Whether the popover is open. */
34
+ isOpen: boolean;
35
+ /** The selected keys. One key at most in the single mode. */
36
+ selectedKeys: Set<SelectKey>;
37
+ /** The selection mode. */
38
+ selectionMode: 'single' | 'multiple';
39
+ /** Whether the whole select is disabled. */
40
+ isDisabled: boolean;
41
+ /** Whether the select is read-only: it keeps the focus, and it refuses to open. */
42
+ isReadOnly: boolean;
43
+ /** Whether a form must have a value here. */
44
+ isRequired: boolean;
45
+ /** Whether the value failed a validation. */
46
+ isInvalid: boolean;
47
+ /** The `name` of the hidden form control. */
48
+ name: string | undefined;
49
+ /** The keys the user cannot select. */
50
+ disabledKeys: Set<SelectKey>;
51
+ /** Whether the arrow keys wrap at the ends of the list. */
52
+ loop: boolean;
53
+ /** The reference to the trigger element. */
54
+ triggerRef: HTMLElement | null;
55
+ /** The reference to the listbox element. */
56
+ listboxRef: HTMLElement | null;
57
+ /** The context of the inner ListBox, once it is in the DOM. */
58
+ listboxCtx: ListBoxContext | null;
59
+ /** The text of a key, from `items` or from an option that registered it. */
60
+ getLabel: (key: SelectKey) => string;
61
+ /** The keys in list order, when the root knows them from `items`. */
62
+ orderedKeys: SelectKey[];
63
+ /** The placeholder text, from the prop or from the locale. */
64
+ placeholder: string;
65
+ /** The `aria-label` given to the root. The trigger carries it. */
66
+ ariaLabel: string | undefined;
67
+ /** The `aria-labelledby` given to the root. The trigger carries it. */
68
+ ariaLabelledBy: string | undefined;
69
+ /** The `aria-describedby` given to the root. The trigger carries it. */
70
+ ariaDescribedBy: string | undefined;
71
+ setTriggerRef: (el: HTMLElement | null) => void;
72
+ setListboxRef: (el: HTMLElement | null) => void;
73
+ setListboxCtx: (ctx: ListBoxContext | null) => void;
74
+ /** Registers the id of `Select.Value`. Returns the unregister function. */
75
+ registerValue: (id: string) => () => void;
76
+ /** Registers the id of `Select.Label`. Returns the unregister function. */
77
+ registerLabel: (id: string) => () => void;
78
+ /** Registers the text of an option, so the trigger can show it after the option leaves the DOM. */
79
+ registerItemLabel: (key: SelectKey, label: string) => void;
80
+ open: (reason?: SelectOpenReason, event?: Event, focus?: SelectOpenFocusIntent) => void;
81
+ /** Closes the popover. Returns false when it was closed already, or when the consumer refused. */
82
+ close: (reason?: SelectCloseReason, event?: Event) => boolean;
83
+ toggle: (reason?: SelectOpenReason, event?: Event) => void;
84
+ /** Opens the popover with a character for the list to search with. */
85
+ openWithTypeahead: (char: string, event?: Event) => void;
86
+ /** Applies a selection that the list reports, and closes the popover when the mode asks for it. */
87
+ commitSelection: (keys: Set<SelectKey>) => void;
88
+ /** Reads and clears where the focus must land at the next open. */
89
+ consumeOpenFocus: () => SelectOpenFocusIntent;
90
+ /** Reads and clears a character typed on the closed trigger, for the list to search with. */
91
+ consumePendingTypeahead: () => string | null;
92
+ /** Whether the focus is on the trigger or in the list. */
93
+ isFocusWithin: boolean;
94
+ /** Whether the focus in the select must show as keyboard focus. */
95
+ isFocusVisible: boolean;
96
+ setFocusWithin: (within: boolean) => void;
97
+ setFocusVisible: (visible: boolean) => void;
98
+ };
99
+ export declare function setSelectContext(ctx: SelectContext): void;
100
+ export declare function getSelectContext(): SelectContext | undefined;
101
+ export declare function useSelectContext(part: string): SelectContext;
102
+ /**
103
+ * A deterministic DOM id for an option. A key can hold characters that are not safe in an id
104
+ * reference, so it is sanitized first.
105
+ */
106
+ export declare function getSelectItemDomId(instanceId: string, key: SelectKey): string;
@@ -0,0 +1,22 @@
1
+ import { setContext, getContext } from 'svelte';
2
+ const SELECT_KEY = Symbol('select');
3
+ export function setSelectContext(ctx) {
4
+ setContext(SELECT_KEY, ctx);
5
+ }
6
+ export function getSelectContext() {
7
+ return getContext(SELECT_KEY);
8
+ }
9
+ export function useSelectContext(part) {
10
+ const ctx = getSelectContext();
11
+ if (!ctx) {
12
+ throw new Error(`${part} must be used inside a Select.Root`);
13
+ }
14
+ return ctx;
15
+ }
16
+ /**
17
+ * A deterministic DOM id for an option. A key can hold characters that are not safe in an id
18
+ * reference, so it is sanitized first.
19
+ */
20
+ export function getSelectItemDomId(instanceId, key) {
21
+ return `select-item-${instanceId}-${String(key).replace(/[^a-zA-Z0-9_-]/g, '_')}`;
22
+ }