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

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 (203) 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 +16 -0
  49. package/dist/index.js +15 -0
  50. package/dist/internal/localized-strings.d.ts +72 -0
  51. package/dist/internal/localized-strings.js +72 -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/aria-hide-outside.d.ts +13 -0
  61. package/dist/primitives/aria-hide-outside.js +7 -1
  62. package/dist/primitives/contain-wheel.d.ts +9 -0
  63. package/dist/primitives/contain-wheel.js +41 -0
  64. package/dist/primitives/floating.d.ts +6 -0
  65. package/dist/primitives/floating.js +26 -5
  66. package/dist/primitives/focus-trap.d.ts +2 -0
  67. package/dist/primitives/focus-trap.js +7 -1
  68. package/dist/primitives/keyboard-navigation.d.ts +6 -0
  69. package/dist/primitives/keyboard-navigation.js +2 -1
  70. package/dist/primitives/presence.svelte.js +6 -1
  71. package/dist/primitives/trigger-focus-state.d.ts +29 -0
  72. package/dist/primitives/trigger-focus-state.js +57 -0
  73. package/dist/progress/README.md +54 -0
  74. package/dist/progress/index.d.ts +21 -0
  75. package/dist/progress/index.js +9 -0
  76. package/dist/progress/index.parts.d.ts +5 -0
  77. package/dist/progress/index.parts.js +5 -0
  78. package/dist/progress/indicator/progress-indicator.svelte +37 -0
  79. package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
  80. package/dist/progress/label/progress-label.svelte +34 -0
  81. package/dist/progress/label/progress-label.svelte.d.ts +4 -0
  82. package/dist/progress/root/context.d.ts +26 -0
  83. package/dist/progress/root/context.js +15 -0
  84. package/dist/progress/root/progress-root.svelte +136 -0
  85. package/dist/progress/root/progress-root.svelte.d.ts +4 -0
  86. package/dist/progress/root/progress-utils.d.ts +12 -0
  87. package/dist/progress/root/progress-utils.js +41 -0
  88. package/dist/progress/track/progress-track.svelte +27 -0
  89. package/dist/progress/track/progress-track.svelte.d.ts +4 -0
  90. package/dist/progress/types.d.ts +81 -0
  91. package/dist/progress/types.js +1 -0
  92. package/dist/progress/value/progress-value.svelte +36 -0
  93. package/dist/progress/value/progress-value.svelte.d.ts +4 -0
  94. package/dist/select/README.md +129 -0
  95. package/dist/select/index.d.ts +30 -0
  96. package/dist/select/index.js +16 -0
  97. package/dist/select/index.parts.d.ts +8 -0
  98. package/dist/select/index.parts.js +9 -0
  99. package/dist/select/item/select-item.svelte +68 -0
  100. package/dist/select/item/select-item.svelte.d.ts +10 -0
  101. package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
  102. package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
  103. package/dist/select/label/select-label.svelte +46 -0
  104. package/dist/select/label/select-label.svelte.d.ts +4 -0
  105. package/dist/select/list/select-list.svelte +241 -0
  106. package/dist/select/list/select-list.svelte.d.ts +62 -0
  107. package/dist/select/popover/select-popover.svelte +80 -0
  108. package/dist/select/popover/select-popover.svelte.d.ts +9 -0
  109. package/dist/select/root/context.d.ts +106 -0
  110. package/dist/select/root/context.js +22 -0
  111. package/dist/select/root/select-root.svelte +544 -0
  112. package/dist/select/root/select-root.svelte.d.ts +25 -0
  113. package/dist/select/trigger/select-trigger.svelte +192 -0
  114. package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
  115. package/dist/select/types.d.ts +133 -0
  116. package/dist/select/types.js +1 -0
  117. package/dist/select/value/select-value.svelte +61 -0
  118. package/dist/select/value/select-value.svelte.d.ts +4 -0
  119. package/dist/separator/README.md +35 -0
  120. package/dist/separator/index.d.ts +7 -0
  121. package/dist/separator/index.js +3 -0
  122. package/dist/separator/separator.svelte +254 -0
  123. package/dist/separator/separator.svelte.d.ts +45 -0
  124. package/dist/separator/types.d.ts +1 -0
  125. package/dist/separator/types.js +1 -0
  126. package/dist/slider/README.md +61 -0
  127. package/dist/slider/fill/slider-fill.svelte +40 -0
  128. package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
  129. package/dist/slider/index.d.ts +9 -0
  130. package/dist/slider/index.js +8 -0
  131. package/dist/slider/index.parts.d.ts +6 -0
  132. package/dist/slider/index.parts.js +6 -0
  133. package/dist/slider/label/slider-label.svelte +44 -0
  134. package/dist/slider/label/slider-label.svelte.d.ts +4 -0
  135. package/dist/slider/output/slider-output.svelte +46 -0
  136. package/dist/slider/output/slider-output.svelte.d.ts +4 -0
  137. package/dist/slider/root/context.d.ts +106 -0
  138. package/dist/slider/root/context.js +15 -0
  139. package/dist/slider/root/slider-root.svelte +545 -0
  140. package/dist/slider/root/slider-root.svelte.d.ts +4 -0
  141. package/dist/slider/root/slider-utils.d.ts +57 -0
  142. package/dist/slider/root/slider-utils.js +88 -0
  143. package/dist/slider/thumb/slider-thumb.svelte +276 -0
  144. package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
  145. package/dist/slider/track/slider-track.svelte +60 -0
  146. package/dist/slider/track/slider-track.svelte.d.ts +4 -0
  147. package/dist/slider/types.d.ts +144 -0
  148. package/dist/slider/types.js +1 -0
  149. package/dist/toast/README.md +75 -0
  150. package/dist/toast/action/toast-action.svelte +42 -0
  151. package/dist/toast/action/toast-action.svelte.d.ts +4 -0
  152. package/dist/toast/close/toast-close.svelte +41 -0
  153. package/dist/toast/close/toast-close.svelte.d.ts +4 -0
  154. package/dist/toast/content/toast-content.svelte +24 -0
  155. package/dist/toast/content/toast-content.svelte.d.ts +4 -0
  156. package/dist/toast/description/toast-description.svelte +41 -0
  157. package/dist/toast/description/toast-description.svelte.d.ts +4 -0
  158. package/dist/toast/index.d.ts +34 -0
  159. package/dist/toast/index.js +15 -0
  160. package/dist/toast/index.parts.d.ts +9 -0
  161. package/dist/toast/index.parts.js +9 -0
  162. package/dist/toast/positioner/toast-positioner.svelte +75 -0
  163. package/dist/toast/positioner/toast-positioner.svelte.d.ts +4 -0
  164. package/dist/toast/provider/context.d.ts +36 -0
  165. package/dist/toast/provider/context.js +22 -0
  166. package/dist/toast/provider/toast-manager.svelte.d.ts +113 -0
  167. package/dist/toast/provider/toast-manager.svelte.js +210 -0
  168. package/dist/toast/provider/toast-provider.svelte +98 -0
  169. package/dist/toast/provider/toast-provider.svelte.d.ts +4 -0
  170. package/dist/toast/root/context.d.ts +18 -0
  171. package/dist/toast/root/context.js +15 -0
  172. package/dist/toast/root/toast-root.svelte +296 -0
  173. package/dist/toast/root/toast-root.svelte.d.ts +4 -0
  174. package/dist/toast/title/toast-title.svelte +38 -0
  175. package/dist/toast/title/toast-title.svelte.d.ts +4 -0
  176. package/dist/toast/types.d.ts +100 -0
  177. package/dist/toast/types.js +1 -0
  178. package/dist/toast/viewport/toast-viewport.svelte +389 -0
  179. package/dist/toast/viewport/toast-viewport.svelte.d.ts +4 -0
  180. package/dist/tooltip/README.md +53 -0
  181. package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
  182. package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
  183. package/dist/tooltip/content/tooltip-content.svelte +148 -0
  184. package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
  185. package/dist/tooltip/index.d.ts +8 -0
  186. package/dist/tooltip/index.js +7 -0
  187. package/dist/tooltip/index.parts.d.ts +5 -0
  188. package/dist/tooltip/index.parts.js +5 -0
  189. package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
  190. package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
  191. package/dist/tooltip/root/context.d.ts +46 -0
  192. package/dist/tooltip/root/context.js +22 -0
  193. package/dist/tooltip/root/safe-polygon.d.ts +26 -0
  194. package/dist/tooltip/root/safe-polygon.js +66 -0
  195. package/dist/tooltip/root/tooltip-group.d.ts +26 -0
  196. package/dist/tooltip/root/tooltip-group.js +41 -0
  197. package/dist/tooltip/root/tooltip-root.svelte +454 -0
  198. package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
  199. package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
  200. package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
  201. package/dist/tooltip/types.d.ts +105 -0
  202. package/dist/tooltip/types.js +1 -0
  203. package/package.json +41 -1
@@ -0,0 +1,68 @@
1
+ <script lang="ts" module>
2
+ export const SELECT_ITEM_CONTEXT_KEY = Symbol.for('select-item');
3
+
4
+ export type SelectItemContext = {
5
+ id: string | number;
6
+ };
7
+ </script>
8
+
9
+ <script lang="ts">
10
+ import { setContext, untrack } from 'svelte';
11
+ import ListBoxItem from '../../listbox/item/listbox-item.svelte';
12
+ import { getSelectItemDomId, useSelectContext } from '../root/context';
13
+ import type { ComponentProps } from 'svelte';
14
+
15
+ type SelectItemProps = Omit<
16
+ ComponentProps<typeof ListBoxItem>,
17
+ | 'customId'
18
+ | 'disableFocusHandling'
19
+ | 'isFocusedOverride'
20
+ | 'isFocusVisibleOverride'
21
+ | 'onItemSelect'
22
+ | 'onResolvedTextValue'
23
+ | 'onItemHoverStart'
24
+ | 'scrollOnFocus'
25
+ | 'isParentDisabled'
26
+ | 'pressed'
27
+ >;
28
+
29
+ /**
30
+ * Select.Item — one option of the list.
31
+ *
32
+ * It is `ListBox.Item` with an id that is unique across selects, and it reports its text to
33
+ * the root, thus the trigger can show the text of the selection after the popover closes and
34
+ * the option leaves the DOM.
35
+ */
36
+ let { id, textValue, ...props }: SelectItemProps = $props();
37
+
38
+ const ctx = useSelectContext('Select.Item');
39
+
40
+ setContext<SelectItemContext>(SELECT_ITEM_CONTEXT_KEY, {
41
+ get id() {
42
+ return id;
43
+ }
44
+ });
45
+
46
+ const domId = $derived(getSelectItemDomId(ctx.instanceId, id));
47
+
48
+ $effect(() => {
49
+ const key = id;
50
+ const text = textValue;
51
+ if (text) untrack(() => ctx.registerItemLabel(key, text));
52
+ });
53
+
54
+ function handleResolvedTextValue(label: string) {
55
+ ctx.registerItemLabel(id, label);
56
+ }
57
+ </script>
58
+
59
+ <ListBoxItem
60
+ {...props}
61
+ {id}
62
+ {textValue}
63
+ customId={domId}
64
+ scrollOnFocus={true}
65
+ isParentDisabled={ctx.isDisabled}
66
+ onResolvedTextValue={handleResolvedTextValue}
67
+ data-select-item="true"
68
+ />
@@ -0,0 +1,10 @@
1
+ export declare const SELECT_ITEM_CONTEXT_KEY: unique symbol;
2
+ export type SelectItemContext = {
3
+ id: string | number;
4
+ };
5
+ import ListBoxItem from '../../listbox/item/listbox-item.svelte';
6
+ import type { ComponentProps } from 'svelte';
7
+ type SelectItemProps = Omit<ComponentProps<typeof ListBoxItem>, 'customId' | 'disableFocusHandling' | 'isFocusedOverride' | 'isFocusVisibleOverride' | 'onItemSelect' | 'onResolvedTextValue' | 'onItemHoverStart' | 'scrollOnFocus' | 'isParentDisabled' | 'pressed'>;
8
+ declare const SelectItem: import("svelte").Component<SelectItemProps, {}, "">;
9
+ type SelectItem = ReturnType<typeof SelectItem>;
10
+ export default SelectItem;
@@ -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;