@human-kit/ui 1.0.0-beta.0 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/FOCUS_STATE_CONTRACT.md +1 -0
- package/dist/accordion/root/accordion-root.svelte +15 -3
- package/dist/accordion/root/context.svelte.js +4 -4
- package/dist/accordion/types.d.ts +9 -2
- package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +6 -0
- package/dist/calendar/root/context.svelte.js +8 -2
- package/dist/checkbox/root/checkbox-root.svelte +28 -11
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +13 -0
- package/dist/clock/root/create-time-selection-state.svelte.d.ts +5 -0
- package/dist/clock/root/create-time-selection-state.svelte.js +113 -10
- package/dist/clock/root/wheel-options.d.ts +7 -3
- package/dist/clock/root/wheel-options.js +7 -15
- package/dist/clock/wheel-column/clock-wheel-column.svelte +10 -2
- package/dist/clock/wheel-column/clock-wheel-column.svelte.d.ts +2 -1
- package/dist/collapsible/root/collapsible-root.svelte +9 -4
- package/dist/collapsible/types.d.ts +9 -0
- package/dist/combobox/input/combobox-input.svelte +12 -1
- package/dist/combobox/list/combobox-listbox.svelte +93 -1
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +20 -0
- package/dist/combobox/root/combobox.svelte +118 -45
- package/dist/combobox/root/combobox.svelte.d.ts +11 -0
- package/dist/combobox/root/context.d.ts +12 -0
- package/dist/combobox/status/README.md +2 -2
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte +14 -2
- package/dist/combobox/tag-remove/combobox-tag-remove.svelte.d.ts +7 -0
- package/dist/combobox/tags/combobox-tags.svelte +5 -2
- package/dist/combobox/tags/combobox-tags.svelte.d.ts +2 -0
- package/dist/combobox/trigger/combobox-trigger.svelte +4 -1
- package/dist/datepicker/README.md +3 -2
- package/dist/datepicker/root/date-picker-root.svelte +38 -2
- package/dist/datepicker/root/date-picker-root.svelte.d.ts +2 -0
- package/dist/datepicker/root/draft-evaluation.d.ts +7 -0
- package/dist/datepicker/root/draft-evaluation.js +2 -2
- package/dist/daterangepicker/root/date-range-picker-root.svelte +19 -1
- package/dist/daterangepicker/root/date-range-picker-root.svelte.d.ts +2 -0
- package/dist/dialog/README.md +9 -1
- package/dist/dialog/close/dialog-close.svelte +57 -0
- package/dist/dialog/close/dialog-close.svelte.d.ts +19 -0
- package/dist/dialog/content/dialog-content.svelte +2 -0
- package/dist/dialog/description/dialog-description.svelte +46 -0
- package/dist/dialog/description/dialog-description.svelte.d.ts +20 -0
- package/dist/dialog/index.d.ts +9 -0
- package/dist/dialog/index.js +3 -0
- package/dist/dialog/index.parts.d.ts +3 -0
- package/dist/dialog/index.parts.js +3 -0
- package/dist/dialog/root/context.d.ts +8 -0
- package/dist/dialog/root/dialog-root.svelte +58 -16
- package/dist/dialog/root/dialog-root.svelte.d.ts +10 -3
- package/dist/dialog/root/dialog-stack.d.ts +6 -22
- package/dist/dialog/root/dialog-stack.js +4 -33
- package/dist/dialog/title/dialog-title.svelte +43 -0
- package/dist/dialog/title/dialog-title.svelte.d.ts +21 -0
- package/dist/drawer/README.md +111 -0
- package/dist/drawer/body/drawer-body.svelte +47 -0
- package/dist/drawer/body/drawer-body.svelte.d.ts +32 -0
- package/dist/drawer/close/drawer-close.svelte +52 -0
- package/dist/drawer/close/drawer-close.svelte.d.ts +20 -0
- package/dist/drawer/content/drawer-content.svelte +597 -0
- package/dist/drawer/content/drawer-content.svelte.d.ts +28 -0
- package/dist/drawer/description/drawer-description.svelte +40 -0
- package/dist/drawer/description/drawer-description.svelte.d.ts +20 -0
- package/dist/drawer/indent/drawer-indent-background.svelte +36 -0
- package/dist/drawer/indent/drawer-indent-background.svelte.d.ts +17 -0
- package/dist/drawer/indent/drawer-indent.svelte +59 -0
- package/dist/drawer/indent/drawer-indent.svelte.d.ts +32 -0
- package/dist/drawer/index.d.ts +49 -0
- package/dist/drawer/index.js +25 -0
- package/dist/drawer/index.parts.d.ts +14 -0
- package/dist/drawer/index.parts.js +15 -0
- package/dist/drawer/overlay/drawer-overlay.svelte +67 -0
- package/dist/drawer/overlay/drawer-overlay.svelte.d.ts +12 -0
- package/dist/drawer/portal/drawer-portal.svelte +57 -0
- package/dist/drawer/portal/drawer-portal.svelte.d.ts +13 -0
- package/dist/drawer/root/context.d.ts +81 -0
- package/dist/drawer/root/context.js +20 -0
- package/dist/drawer/root/drawer-root.svelte +333 -0
- package/dist/drawer/root/drawer-root.svelte.d.ts +77 -0
- package/dist/drawer/root/drawer-stack.svelte.d.ts +73 -0
- package/dist/drawer/root/drawer-stack.svelte.js +113 -0
- package/dist/drawer/root/handle.svelte.d.ts +39 -0
- package/dist/drawer/root/handle.svelte.js +64 -0
- package/dist/drawer/root/keyboard-context.d.ts +13 -0
- package/dist/drawer/root/keyboard-context.js +8 -0
- package/dist/drawer/root/presence-context.d.ts +22 -0
- package/dist/drawer/root/presence-context.js +8 -0
- package/dist/drawer/root/snap-points.d.ts +68 -0
- package/dist/drawer/root/snap-points.js +120 -0
- package/dist/drawer/root/starting-style.svelte.d.ts +18 -0
- package/dist/drawer/root/starting-style.svelte.js +38 -0
- package/dist/drawer/root/types.d.ts +36 -0
- package/dist/drawer/root/types.js +1 -0
- package/dist/drawer/root/viewport-context.d.ts +2 -0
- package/dist/drawer/root/viewport-context.js +16 -0
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte +143 -0
- package/dist/drawer/swipe-area/drawer-swipe-area.svelte.d.ts +22 -0
- package/dist/drawer/title/drawer-title.svelte +37 -0
- package/dist/drawer/title/drawer-title.svelte.d.ts +21 -0
- package/dist/drawer/trigger/drawer-trigger.svelte +90 -0
- package/dist/drawer/trigger/drawer-trigger.svelte.d.ts +41 -0
- package/dist/drawer/viewport/drawer-viewport.svelte +69 -0
- package/dist/drawer/viewport/drawer-viewport.svelte.d.ts +15 -0
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte +88 -0
- package/dist/drawer/virtual-keyboard/drawer-virtual-keyboard-provider.svelte.d.ts +29 -0
- package/dist/hooks/use-virtual-focus.svelte.d.ts +9 -0
- package/dist/hooks/use-virtual-focus.svelte.js +7 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/listbox/item/listbox-item.svelte +8 -1
- package/dist/listbox/root/context.d.ts +30 -0
- package/dist/listbox/root/context.js +10 -0
- package/dist/listbox/root/listbox.svelte +291 -8
- package/dist/listbox/root/listbox.svelte.d.ts +35 -2
- package/dist/menu/content/menu-content.svelte +3 -1
- package/dist/menu/overlay/menu-overlay.svelte +1 -1
- package/dist/numberfield/root/number-field-root.svelte +2 -1
- package/dist/popover/content/popover-content.svelte +1 -1
- package/dist/popover/overlay/popover-overlay.svelte +1 -1
- package/dist/popover/root/popover-root.svelte +23 -11
- package/dist/popover/root/popover-root.svelte.d.ts +10 -2
- package/dist/primitives/floating.d.ts +7 -0
- package/dist/primitives/floating.js +6 -2
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/keyboard-navigation.js +3 -1
- package/dist/primitives/layer-stack.d.ts +29 -0
- package/dist/primitives/layer-stack.js +35 -0
- package/dist/primitives/list-virtualizer.d.ts +75 -0
- package/dist/primitives/list-virtualizer.js +59 -0
- package/dist/primitives/scroll-lock.d.ts +23 -3
- package/dist/primitives/scroll-lock.js +122 -9
- package/dist/primitives/swipe-gesture.d.ts +126 -0
- package/dist/primitives/swipe-gesture.js +351 -0
- package/dist/primitives/text.d.ts +8 -0
- package/dist/primitives/text.js +13 -0
- package/dist/switch/root/switch-root.svelte +23 -9
- package/dist/switch/root/switch-root.svelte.d.ts +9 -2
- package/dist/table/body/table-body.svelte +84 -9
- package/dist/table/cell/table-cell.svelte +1 -3
- package/dist/table/column/table-column.svelte +5 -1
- package/dist/table/column-resizer/table-column-resizer.svelte +1 -5
- package/dist/table/interactive-cell/table-interactive-cell.svelte +1 -3
- package/dist/table/root/context.svelte.js +99 -49
- package/dist/table/row/table-row.svelte +7 -7
- package/dist/table/sort-trigger/table-sort-trigger.svelte +5 -1
- package/dist/table/types.d.ts +6 -0
- package/dist/tabs/root/tabs-root.svelte +20 -6
- package/dist/tabs/types.d.ts +9 -0
- package/dist/timepicker/root/time-picker-root.svelte +11 -0
- package/dist/timepicker/root/time-picker-root.svelte.d.ts +2 -0
- package/dist/toggle-group/root/context.svelte.js +11 -4
- package/dist/toggle-group/root/toggle-group-root.svelte +19 -4
- package/dist/toggle-group/types.d.ts +9 -0
- package/dist/tree/root/context.svelte.js +6 -0
- package/dist/tree/root/tree-root.svelte +22 -8
- package/dist/tree/types.d.ts +13 -0
- package/package.json +227 -224
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends object = object">
|
|
2
2
|
import type { ComponentProps, Snippet } from 'svelte';
|
|
3
|
+
import { dev } from '../../internal/environment';
|
|
3
4
|
import { useComboBoxContext } from '../root/context';
|
|
4
5
|
import { ListBoxRoot as ListBox, type ListBoxContext } from '../../listbox';
|
|
5
6
|
|
|
@@ -26,12 +27,25 @@
|
|
|
26
27
|
items?: Iterable<T>;
|
|
27
28
|
/** Content of the listbox. Receives item in dynamic mode. */
|
|
28
29
|
children?: Snippet<[T]> | Snippet;
|
|
30
|
+
/**
|
|
31
|
+
* Renders only the options near the viewport. See `ListBox`'s own `virtualizer` for
|
|
32
|
+
* the constraints (uniform row height, the list is the scroller).
|
|
33
|
+
*
|
|
34
|
+
* With no `items` of its own it virtualizes the ComboBox's, already filtered: the
|
|
35
|
+
* per-item filtering an unvirtualized list relies on cannot work when most items were
|
|
36
|
+
* never rendered.
|
|
37
|
+
*/
|
|
38
|
+
virtualizer?: { rowHeight?: number; overscan?: number };
|
|
39
|
+
/** Rows rendered above the options, inside the listbox (e.g. a "Create …" action). */
|
|
40
|
+
header?: Snippet;
|
|
29
41
|
};
|
|
30
42
|
|
|
31
43
|
let {
|
|
32
44
|
'aria-label': ariaLabel = 'Options',
|
|
33
45
|
children,
|
|
34
46
|
items,
|
|
47
|
+
virtualizer,
|
|
48
|
+
header,
|
|
35
49
|
...props
|
|
36
50
|
}: ComboBoxListBoxProps = $props();
|
|
37
51
|
|
|
@@ -40,6 +54,82 @@
|
|
|
40
54
|
let listboxElement: HTMLElement | undefined = $state();
|
|
41
55
|
const listboxSelection = $derived(Array.from(ctx.selectedValue));
|
|
42
56
|
|
|
57
|
+
// Virtualizing means slicing, and only the ComboBox knows which items survived the filter
|
|
58
|
+
// and in what order — so a virtualized list always renders *its* items, not a copy passed
|
|
59
|
+
// down here. Anything else would filter with a predicate applied to rows that were never
|
|
60
|
+
// rendered.
|
|
61
|
+
const virtualItems = $derived(virtualizer ? (ctx.filteredItems as T[]) : undefined);
|
|
62
|
+
|
|
63
|
+
// The root navigates by DOM order unless told otherwise; only a virtualized list needs
|
|
64
|
+
// the item array instead, and saying so here keeps every other list — including one with
|
|
65
|
+
// an action row in its header — navigating exactly as before.
|
|
66
|
+
$effect(() => {
|
|
67
|
+
ctx.setVirtualized(Boolean(virtualizer));
|
|
68
|
+
return () => ctx.setVirtualized(false);
|
|
69
|
+
});
|
|
70
|
+
const renderedItems = $derived(virtualItems ?? items);
|
|
71
|
+
|
|
72
|
+
if (dev) {
|
|
73
|
+
$effect(() => {
|
|
74
|
+
if (virtualizer && ctx.items === undefined) {
|
|
75
|
+
console.warn(
|
|
76
|
+
'[ComboBox.List]: `virtualizer` needs the list on the ComboBox itself — ' +
|
|
77
|
+
'<ComboBox.Root items={...}> — since filtering and navigation are resolved ' +
|
|
78
|
+
'there. Without it nothing is rendered.'
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Whether the list has been open since the last time this ran, to tell "the list just
|
|
85
|
+
// opened on its selection" from "the user is walking it with the arrows". Not `$state`:
|
|
86
|
+
// both are read and written inside the effect below and nothing renders from them.
|
|
87
|
+
let wasOpen = false;
|
|
88
|
+
// Latched until the *selected* row is the one being scrolled to. Opening moves the focus
|
|
89
|
+
// more than once — it lands on the first row before it lands on the selection — so a flag
|
|
90
|
+
// consumed by the first scroll spent the centring on row zero and left the selection
|
|
91
|
+
// pinned to the bottom edge.
|
|
92
|
+
let openPendingScroll = false;
|
|
93
|
+
|
|
94
|
+
// Keyboard focus lives on the ComboBox's input (aria-activedescendant), so moving it can
|
|
95
|
+
// land on a row the window hasn't rendered. Ask the listbox for that index before the
|
|
96
|
+
// input points at it — otherwise `aria-activedescendant` names an element that isn't
|
|
97
|
+
// there and nothing scrolls.
|
|
98
|
+
$effect(() => {
|
|
99
|
+
const focusedId = ctx.focusedItemId;
|
|
100
|
+
|
|
101
|
+
if (ctx.isOpen && !wasOpen) {
|
|
102
|
+
openPendingScroll = true;
|
|
103
|
+
}
|
|
104
|
+
wasOpen = ctx.isOpen;
|
|
105
|
+
|
|
106
|
+
if (!virtualItems || focusedId === null || !listboxCtx) return;
|
|
107
|
+
|
|
108
|
+
// Over the filtered list, not `ctx.itemIds`: that one is built from item *registration*,
|
|
109
|
+
// so in a virtualized list it only knows the rows that happen to be mounted.
|
|
110
|
+
const index = ctx.filteredItemIds.indexOf(focusedId);
|
|
111
|
+
|
|
112
|
+
if (index >= 0) {
|
|
113
|
+
// Centred when opening lands on the selection: the user has to *find* it, and a row
|
|
114
|
+
// flush against an edge reads as the end of the list. Everything else is nearest, so
|
|
115
|
+
// the arrows move the list as little as possible.
|
|
116
|
+
const [selectedId] = ctx.selectedValue;
|
|
117
|
+
const isSelectedRow = selectedId !== undefined && focusedId === selectedId;
|
|
118
|
+
const centre = openPendingScroll && isSelectedRow;
|
|
119
|
+
|
|
120
|
+
// The latch is released by the scroll *landing*, not by asking for it: the first
|
|
121
|
+
// attempts happen while the list is still sizing itself and get clamped away, and
|
|
122
|
+
// giving up on them left the selection wherever a later "nearest" put it.
|
|
123
|
+
void listboxCtx
|
|
124
|
+
.scrollIndexIntoView(index, { align: centre ? 'center' : 'nearest' })
|
|
125
|
+
.then((applied) => {
|
|
126
|
+
if (centre && applied) {
|
|
127
|
+
openPendingScroll = false;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
43
133
|
// Wire listbox context to combobox context when available
|
|
44
134
|
$effect(() => {
|
|
45
135
|
if (listboxCtx) {
|
|
@@ -86,7 +176,9 @@
|
|
|
86
176
|
bind:context={listboxCtx}
|
|
87
177
|
bind:element={listboxElement}
|
|
88
178
|
id={`combobox-listbox-${ctx.instanceId}`}
|
|
89
|
-
{
|
|
179
|
+
items={renderedItems}
|
|
180
|
+
{virtualizer}
|
|
181
|
+
{header}
|
|
90
182
|
{children}
|
|
91
183
|
selectionMode={ctx.selectionMode}
|
|
92
184
|
value={listboxSelection}
|
|
@@ -9,7 +9,9 @@ declare function $$render<T extends object = object>(): {
|
|
|
9
9
|
selectionMode?: "single" | "multiple";
|
|
10
10
|
value?: Iterable<string | number>;
|
|
11
11
|
defaultValue?: Iterable<string | number>;
|
|
12
|
+
controlledValue?: boolean;
|
|
12
13
|
children?: Snippet<[]> | Snippet<[object]> | undefined;
|
|
14
|
+
header?: Snippet;
|
|
13
15
|
class?: string;
|
|
14
16
|
id?: string;
|
|
15
17
|
'aria-label'?: string;
|
|
@@ -17,6 +19,10 @@ declare function $$render<T extends object = object>(): {
|
|
|
17
19
|
disableFocusHandling?: boolean;
|
|
18
20
|
loop?: boolean;
|
|
19
21
|
typeahead?: boolean;
|
|
22
|
+
virtualizer?: {
|
|
23
|
+
rowHeight?: number;
|
|
24
|
+
overscan?: number;
|
|
25
|
+
} | undefined;
|
|
20
26
|
} & {
|
|
21
27
|
context?: ListBoxContext;
|
|
22
28
|
element?: HTMLElement;
|
|
@@ -25,6 +31,20 @@ declare function $$render<T extends object = object>(): {
|
|
|
25
31
|
items?: Iterable<T>;
|
|
26
32
|
/** Content of the listbox. Receives item in dynamic mode. */
|
|
27
33
|
children?: Snippet<[T]> | Snippet;
|
|
34
|
+
/**
|
|
35
|
+
* Renders only the options near the viewport. See `ListBox`'s own `virtualizer` for
|
|
36
|
+
* the constraints (uniform row height, the list is the scroller).
|
|
37
|
+
*
|
|
38
|
+
* With no `items` of its own it virtualizes the ComboBox's, already filtered: the
|
|
39
|
+
* per-item filtering an unvirtualized list relies on cannot work when most items were
|
|
40
|
+
* never rendered.
|
|
41
|
+
*/
|
|
42
|
+
virtualizer?: {
|
|
43
|
+
rowHeight?: number;
|
|
44
|
+
overscan?: number;
|
|
45
|
+
};
|
|
46
|
+
/** Rows rendered above the options, inside the listbox (e.g. a "Create …" action). */
|
|
47
|
+
header?: Snippet;
|
|
28
48
|
};
|
|
29
49
|
exports: {};
|
|
30
50
|
bindings: "";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { untrack, type Snippet } from 'svelte';
|
|
3
3
|
import { SvelteMap, SvelteSet } from 'svelte/reactivity';
|
|
4
4
|
import { dev } from '../../internal/environment';
|
|
5
|
+
import { foldForSearch } from '../../primitives/text';
|
|
5
6
|
import {
|
|
6
7
|
setComboBoxContext,
|
|
7
8
|
type ComboBoxContext,
|
|
@@ -25,15 +26,26 @@
|
|
|
25
26
|
/** Selected value(s). Single value for single mode, array for multiple mode. Can be bound with bind:value */
|
|
26
27
|
value?: string | number | null | (string | number)[];
|
|
27
28
|
defaultValue?: string | number | null | (string | number)[];
|
|
29
|
+
/**
|
|
30
|
+
* Opt into fully controlled selection: the component stops writing back to `value`
|
|
31
|
+
* and only reports through `onChange`, so the parent can reject a change by not
|
|
32
|
+
* flowing the new value back down. Off by default, because `bind:value` — the
|
|
33
|
+
* common case — needs the write-back to work at all.
|
|
34
|
+
*/
|
|
35
|
+
controlledValue?: boolean;
|
|
28
36
|
/** Current input value. Can be bound with bind:inputValue */
|
|
29
37
|
inputValue?: string;
|
|
30
38
|
defaultInputValue?: string;
|
|
39
|
+
/** Opt into fully controlled input text. See `controlledValue`. */
|
|
40
|
+
controlledInputValue?: boolean;
|
|
31
41
|
selectionBehavior?: 'toggle' | 'replace';
|
|
32
42
|
selectionMode?: 'single' | 'multiple';
|
|
33
43
|
/** Whether to close popover after selection. Default: true for single, false for multiple */
|
|
34
44
|
closeOnSelect?: boolean;
|
|
35
45
|
/** Whether the popover is open. Can be bound with bind:open */
|
|
36
46
|
open?: boolean;
|
|
47
|
+
/** Opt into fully controlled open state. See `controlledValue`. */
|
|
48
|
+
controlledOpen?: boolean;
|
|
37
49
|
/** How the popover opens: 'focus' | 'input' | 'press'. Default: 'press' */
|
|
38
50
|
trigger?: 'focus' | 'input' | 'press';
|
|
39
51
|
/** Function used to filter items locally. Set to null to disable local filtering. */
|
|
@@ -62,12 +74,15 @@
|
|
|
62
74
|
readonly = false,
|
|
63
75
|
value = $bindable(),
|
|
64
76
|
defaultValue,
|
|
77
|
+
controlledValue = false,
|
|
65
78
|
inputValue = $bindable(),
|
|
66
79
|
defaultInputValue = '',
|
|
80
|
+
controlledInputValue = false,
|
|
67
81
|
selectionBehavior,
|
|
68
82
|
selectionMode = 'single',
|
|
69
83
|
closeOnSelect,
|
|
70
84
|
open: openProp = $bindable(),
|
|
85
|
+
controlledOpen = false,
|
|
71
86
|
trigger = 'press',
|
|
72
87
|
filter = defaultComboBoxFilter,
|
|
73
88
|
filterActionItems = true,
|
|
@@ -81,8 +96,16 @@
|
|
|
81
96
|
'aria-labelledby': ariaLabelledby
|
|
82
97
|
}: ComboBoxProps<T> = $props();
|
|
83
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Substring match, blind to case *and* to accents: typing `tulua` finds `TULUÁ` and
|
|
101
|
+
* `medellin` finds `MEDELLÍN`.
|
|
102
|
+
*
|
|
103
|
+
* Folding the diacritics is not a nicety in a language that has them — a list of Colombian
|
|
104
|
+
* municipalities is unusable when the user has to reproduce every accent to find a row,
|
|
105
|
+
* and nobody types them into a search box.
|
|
106
|
+
*/
|
|
84
107
|
function defaultComboBoxFilter(textValue: string, inputValue: string) {
|
|
85
|
-
return textValue
|
|
108
|
+
return foldForSearch(textValue).includes(foldForSearch(inputValue.trim()));
|
|
86
109
|
}
|
|
87
110
|
|
|
88
111
|
const instanceId = untrack(() => rootId) ?? generatedInstanceId;
|
|
@@ -101,11 +124,21 @@
|
|
|
101
124
|
let listboxRef: HTMLElement | null = $state(null);
|
|
102
125
|
|
|
103
126
|
let isOpenInternal = $state(false);
|
|
104
|
-
|
|
105
|
-
//
|
|
127
|
+
// Set by ComboBox.List when it virtualizes. Only then is the DOM an incomplete picture of
|
|
128
|
+
// the list, so only then does navigation switch to the item array.
|
|
129
|
+
let isListVirtualized = $state(false);
|
|
130
|
+
|
|
131
|
+
// Use virtual focus hook for navigation.
|
|
132
|
+
//
|
|
133
|
+
// `orderedIds` matters for a virtualized list: without it the hook reads the order off
|
|
134
|
+
// the DOM, and a virtualized listbox only has the rows near the viewport mounted — so
|
|
135
|
+
// End would land on the last *rendered* option and ArrowDown would stop at the edge of
|
|
136
|
+
// the window. When `items` is given, the array is the authority on order and length,
|
|
137
|
+
// mounted or not.
|
|
106
138
|
const navigation = useVirtualFocus({
|
|
107
139
|
instanceId,
|
|
108
|
-
containerRef: () => listboxRef
|
|
140
|
+
containerRef: () => listboxRef,
|
|
141
|
+
orderedIds: () => (isListVirtualized && items ? filteredItemIds : undefined)
|
|
109
142
|
});
|
|
110
143
|
|
|
111
144
|
// Persistent label of the selected item (for restore on blur/escape)
|
|
@@ -233,26 +266,63 @@
|
|
|
233
266
|
let inputValueInternal = $state(getInitialInputValue());
|
|
234
267
|
let selectedInternal = $state<Set<string | number>>((() => parseSelection(defaultValue))());
|
|
235
268
|
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
const
|
|
269
|
+
// Controlled-ness is opt-in per prop, not inferred from the prop being defined:
|
|
270
|
+
// `bind:value` and `value={...}` are indistinguishable at runtime. These used to be
|
|
271
|
+
// inferred, and every write below ignored the result anyway — so a controlled parent
|
|
272
|
+
// could not reject anything; the combobox moved regardless of what `onChange` decided.
|
|
273
|
+
const isOpenControlled = $derived(controlledOpen);
|
|
274
|
+
const isInputControlled = $derived(controlledInputValue);
|
|
275
|
+
const isSelectionControlled = $derived(controlledValue);
|
|
276
|
+
|
|
277
|
+
// The prop wins whenever it is supplied — that covers both `bind:` and a plain
|
|
278
|
+
// value — and the internal state only carries the fully uncontrolled case.
|
|
279
|
+
const currentIsOpen = $derived(
|
|
280
|
+
isOpenControlled ? Boolean(openProp) : (openProp ?? isOpenInternal)
|
|
281
|
+
);
|
|
282
|
+
const currentInputValue = $derived(
|
|
283
|
+
isInputControlled ? inputValue! : (inputValue ?? inputValueInternal)
|
|
284
|
+
);
|
|
243
285
|
const currentSelection = $derived(
|
|
244
|
-
isSelectionControlled ? parseSelection(value) : selectedInternal
|
|
286
|
+
isSelectionControlled || value !== undefined ? parseSelection(value) : selectedInternal
|
|
245
287
|
);
|
|
246
288
|
|
|
247
289
|
// Input value used for filtering - empty when shouldFilter is false
|
|
248
290
|
const filterValue = $derived(shouldFilter ? currentInputValue : '');
|
|
249
291
|
|
|
292
|
+
/**
|
|
293
|
+
* The items that pass the local filter, in order.
|
|
294
|
+
*
|
|
295
|
+
* Filtering normally happens per item (each `ComboBox.Item` hides itself), which cannot
|
|
296
|
+
* work when the list is virtualized: an item that was never rendered can neither hide nor
|
|
297
|
+
* count itself. Resolving it here — the same predicate, applied to the array — gives the
|
|
298
|
+
* listbox something to slice and the navigation something to walk.
|
|
299
|
+
*/
|
|
300
|
+
const filteredItems = $derived.by(() => {
|
|
301
|
+
if (!items) return [];
|
|
302
|
+
|
|
303
|
+
const search = filterValue.trim();
|
|
304
|
+
if (!search || filter === null) return items;
|
|
305
|
+
|
|
306
|
+
return items.filter((item) => {
|
|
307
|
+
const textValue = getInternalItemTextValue(item);
|
|
308
|
+
return textValue === undefined ? true : filter(textValue, filterValue);
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
const filteredItemIds = $derived(
|
|
313
|
+
filteredItems
|
|
314
|
+
.map((item) => getInternalItemValue(item))
|
|
315
|
+
.filter((id): id is string | number => id !== undefined)
|
|
316
|
+
);
|
|
317
|
+
|
|
250
318
|
function setIsOpen(open: boolean) {
|
|
251
319
|
// No-op guard: prevents duplicate onOpenChange notifications when close
|
|
252
320
|
// is requested twice (e.g. Escape closing and then blur handling).
|
|
253
321
|
if (open === currentIsOpen) return;
|
|
254
|
-
|
|
255
|
-
|
|
322
|
+
if (!isOpenControlled) {
|
|
323
|
+
isOpenInternal = open;
|
|
324
|
+
openProp = open; // Update bindable prop
|
|
325
|
+
}
|
|
256
326
|
onOpenChange?.(open);
|
|
257
327
|
// Reset focus and pending when closing
|
|
258
328
|
if (!open) {
|
|
@@ -264,8 +334,10 @@
|
|
|
264
334
|
function setInputValueHandler(val: string) {
|
|
265
335
|
// Clear tag virtual focus when typing
|
|
266
336
|
focusedTagId = null;
|
|
267
|
-
|
|
268
|
-
|
|
337
|
+
if (!isInputControlled) {
|
|
338
|
+
inputValueInternal = val;
|
|
339
|
+
inputValue = val; // Update bindable prop
|
|
340
|
+
}
|
|
269
341
|
onInputChange?.(val); // Notify parent of input change
|
|
270
342
|
// Reset focus when filter changes (user typing)
|
|
271
343
|
navigation.setFocused(null);
|
|
@@ -279,21 +351,20 @@
|
|
|
279
351
|
// In multiple mode, selections are managed via tags, not input
|
|
280
352
|
if (selectionMode === 'single' && val.trim() === '' && currentSelection.size > 0) {
|
|
281
353
|
const emptySelection = new Set<string | number>();
|
|
282
|
-
|
|
283
|
-
if (isSelectionControlled) {
|
|
284
|
-
onChange?.(toExternalValue(emptySelection));
|
|
285
|
-
} else {
|
|
354
|
+
if (!isSelectionControlled) {
|
|
286
355
|
selectedInternal = emptySelection;
|
|
287
|
-
|
|
356
|
+
value = toExternalValue(emptySelection);
|
|
288
357
|
}
|
|
289
|
-
|
|
358
|
+
onChange?.(toExternalValue(emptySelection));
|
|
290
359
|
selectedLabel = '';
|
|
291
360
|
}
|
|
292
361
|
}
|
|
293
362
|
|
|
294
363
|
function syncInputValue(val: string, options?: { notifyInputChange?: boolean }) {
|
|
295
|
-
|
|
296
|
-
|
|
364
|
+
if (!isInputControlled) {
|
|
365
|
+
inputValueInternal = val;
|
|
366
|
+
inputValue = val;
|
|
367
|
+
}
|
|
297
368
|
|
|
298
369
|
if (options?.notifyInputChange ?? true) {
|
|
299
370
|
onInputChange?.(val);
|
|
@@ -381,15 +452,12 @@
|
|
|
381
452
|
}
|
|
382
453
|
}
|
|
383
454
|
|
|
384
|
-
|
|
385
|
-
if (isSelectionControlled) {
|
|
386
|
-
onChange?.(toExternalValue(newSelection));
|
|
387
|
-
} else {
|
|
455
|
+
if (!isSelectionControlled) {
|
|
388
456
|
selectedInternal = newSelection;
|
|
389
|
-
|
|
457
|
+
// Update bindable value
|
|
458
|
+
value = toExternalValue(newSelection);
|
|
390
459
|
}
|
|
391
|
-
|
|
392
|
-
value = toExternalValue(newSelection);
|
|
460
|
+
onChange?.(toExternalValue(newSelection));
|
|
393
461
|
}
|
|
394
462
|
|
|
395
463
|
function removeItem(id: string | number) {
|
|
@@ -403,14 +471,11 @@
|
|
|
403
471
|
// Remove from persistent labels
|
|
404
472
|
selectedLabels.delete(id);
|
|
405
473
|
|
|
406
|
-
|
|
407
|
-
if (isSelectionControlled) {
|
|
408
|
-
onChange?.(toExternalValue(newSelection));
|
|
409
|
-
} else {
|
|
474
|
+
if (!isSelectionControlled) {
|
|
410
475
|
selectedInternal = newSelection;
|
|
411
|
-
|
|
476
|
+
value = toExternalValue(newSelection);
|
|
412
477
|
}
|
|
413
|
-
|
|
478
|
+
onChange?.(toExternalValue(newSelection));
|
|
414
479
|
|
|
415
480
|
// Clear selectedLabel if we removed the last item
|
|
416
481
|
if (newSelection.size === 0) {
|
|
@@ -421,19 +486,18 @@
|
|
|
421
486
|
function clearSelection() {
|
|
422
487
|
const emptySelection = new Set<string | number>();
|
|
423
488
|
|
|
424
|
-
|
|
425
|
-
if (isSelectionControlled) {
|
|
426
|
-
onChange?.(toExternalValue(emptySelection));
|
|
427
|
-
} else {
|
|
489
|
+
if (!isSelectionControlled) {
|
|
428
490
|
selectedInternal = emptySelection;
|
|
429
|
-
|
|
491
|
+
value = toExternalValue(emptySelection);
|
|
430
492
|
}
|
|
431
|
-
|
|
493
|
+
onChange?.(toExternalValue(emptySelection));
|
|
432
494
|
selectedLabel = '';
|
|
433
495
|
|
|
434
496
|
// Also clear the input
|
|
435
|
-
|
|
436
|
-
|
|
497
|
+
if (!isInputControlled) {
|
|
498
|
+
inputValueInternal = '';
|
|
499
|
+
inputValue = '';
|
|
500
|
+
}
|
|
437
501
|
onInputChange?.('');
|
|
438
502
|
}
|
|
439
503
|
|
|
@@ -907,6 +971,15 @@
|
|
|
907
971
|
get items() {
|
|
908
972
|
return items;
|
|
909
973
|
},
|
|
974
|
+
get filteredItems() {
|
|
975
|
+
return filteredItems;
|
|
976
|
+
},
|
|
977
|
+
get filteredItemIds() {
|
|
978
|
+
return filteredItemIds;
|
|
979
|
+
},
|
|
980
|
+
setVirtualized: (virtualized) => {
|
|
981
|
+
isListVirtualized = virtualized;
|
|
982
|
+
},
|
|
910
983
|
setInputRef: (el) => {
|
|
911
984
|
inputRef = el;
|
|
912
985
|
},
|
|
@@ -9,15 +9,26 @@ type ComboBoxProps<T> = {
|
|
|
9
9
|
/** Selected value(s). Single value for single mode, array for multiple mode. Can be bound with bind:value */
|
|
10
10
|
value?: string | number | null | (string | number)[];
|
|
11
11
|
defaultValue?: string | number | null | (string | number)[];
|
|
12
|
+
/**
|
|
13
|
+
* Opt into fully controlled selection: the component stops writing back to `value`
|
|
14
|
+
* and only reports through `onChange`, so the parent can reject a change by not
|
|
15
|
+
* flowing the new value back down. Off by default, because `bind:value` — the
|
|
16
|
+
* common case — needs the write-back to work at all.
|
|
17
|
+
*/
|
|
18
|
+
controlledValue?: boolean;
|
|
12
19
|
/** Current input value. Can be bound with bind:inputValue */
|
|
13
20
|
inputValue?: string;
|
|
14
21
|
defaultInputValue?: string;
|
|
22
|
+
/** Opt into fully controlled input text. See `controlledValue`. */
|
|
23
|
+
controlledInputValue?: boolean;
|
|
15
24
|
selectionBehavior?: 'toggle' | 'replace';
|
|
16
25
|
selectionMode?: 'single' | 'multiple';
|
|
17
26
|
/** Whether to close popover after selection. Default: true for single, false for multiple */
|
|
18
27
|
closeOnSelect?: boolean;
|
|
19
28
|
/** Whether the popover is open. Can be bound with bind:open */
|
|
20
29
|
open?: boolean;
|
|
30
|
+
/** Opt into fully controlled open state. See `controlledValue`. */
|
|
31
|
+
controlledOpen?: boolean;
|
|
21
32
|
/** How the popover opens: 'focus' | 'input' | 'press'. Default: 'press' */
|
|
22
33
|
trigger?: 'focus' | 'input' | 'press';
|
|
23
34
|
/** Function used to filter items locally. Set to null to disable local filtering. */
|
|
@@ -71,6 +71,18 @@ export type ComboBoxContext<T extends object = object> = {
|
|
|
71
71
|
listboxRef: HTMLElement | null;
|
|
72
72
|
/** Optional: Array of items for dynamic rendering */
|
|
73
73
|
items?: T[];
|
|
74
|
+
/**
|
|
75
|
+
* `items` narrowed by the local filter, in order. Empty when the ComboBox was given no
|
|
76
|
+
* `items` (a list written as static children filters itself, item by item).
|
|
77
|
+
*/
|
|
78
|
+
filteredItems: T[];
|
|
79
|
+
/** The ids of {@link filteredItems}, in the same order — the list navigation walks. */
|
|
80
|
+
filteredItemIds: (string | number)[];
|
|
81
|
+
/**
|
|
82
|
+
* Told by ComboBox.List whether it renders only a window of the options. Navigation reads
|
|
83
|
+
* the DOM order otherwise, which is the same thing only while every option is mounted.
|
|
84
|
+
*/
|
|
85
|
+
setVirtualized: (virtualized: boolean) => void;
|
|
74
86
|
/** Set the input ref */
|
|
75
87
|
setInputRef: (el: HTMLElement | null) => void;
|
|
76
88
|
/** Set the trigger ref (wrapper) */
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
Name: `ComboBox.Status`
|
|
8
8
|
Description: Visually-hidden `aria-live="polite"` region that announces the number of results visible in the popover as the filter changes.
|
|
9
9
|
|
|
10
|
-
| Prop | Type | Default | Description
|
|
11
|
-
| --------------- | --------------------------- | ----------- |
|
|
10
|
+
| Prop | Type | Default | Description |
|
|
11
|
+
| --------------- | --------------------------- | ----------- | ------------------------------------------------------------------------------------------ |
|
|
12
12
|
| `formatMessage` | `(count: number) => string` | `undefined` | Builds the announced message from the visible item count. Defaults to a localized message. |
|
|
13
13
|
|
|
14
14
|
## Notes
|
|
@@ -13,9 +13,21 @@
|
|
|
13
13
|
/** Content of the button (defaults to X icon) */
|
|
14
14
|
children?: Snippet;
|
|
15
15
|
class?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Accessible name of the button. Defaults to `Remove <tag label>`; override it to
|
|
18
|
+
* translate the verb, or to name the tag by something other than its combobox
|
|
19
|
+
* label (which falls back to the raw value when the selection was set
|
|
20
|
+
* programmatically and the option never rendered).
|
|
21
|
+
*/
|
|
22
|
+
'aria-label'?: string;
|
|
16
23
|
} & Omit<HTMLButtonAttributes, 'class' | 'children' | 'type' | 'onclick' | 'aria-label'>;
|
|
17
24
|
|
|
18
|
-
let {
|
|
25
|
+
let {
|
|
26
|
+
children,
|
|
27
|
+
class: className,
|
|
28
|
+
'aria-label': ariaLabel,
|
|
29
|
+
...restProps
|
|
30
|
+
}: ComboBoxTagRemoveProps = $props();
|
|
19
31
|
|
|
20
32
|
const maybeTagCtx = getContext<TagContext | undefined>(TAG_CONTEXT_KEY);
|
|
21
33
|
|
|
@@ -37,7 +49,7 @@
|
|
|
37
49
|
<ButtonRoot
|
|
38
50
|
type="button"
|
|
39
51
|
onclick={handleClick}
|
|
40
|
-
aria-label={`Remove ${tagCtx.label}`}
|
|
52
|
+
aria-label={ariaLabel ?? `Remove ${tagCtx.label}`}
|
|
41
53
|
tabindex={-1}
|
|
42
54
|
class={className}
|
|
43
55
|
{...restProps}
|
|
@@ -8,6 +8,13 @@ type ComboBoxTagRemoveProps = {
|
|
|
8
8
|
/** Content of the button (defaults to X icon) */
|
|
9
9
|
children?: Snippet;
|
|
10
10
|
class?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Accessible name of the button. Defaults to `Remove <tag label>`; override it to
|
|
13
|
+
* translate the verb, or to name the tag by something other than its combobox
|
|
14
|
+
* label (which falls back to the raw value when the selection was set
|
|
15
|
+
* programmatically and the option never rendered).
|
|
16
|
+
*/
|
|
17
|
+
'aria-label'?: string;
|
|
11
18
|
} & Omit<HTMLButtonAttributes, 'class' | 'children' | 'type' | 'onclick' | 'aria-label'>;
|
|
12
19
|
declare const ComboboxTagRemove: import("svelte").Component<ComboBoxTagRemoveProps, {}, "">;
|
|
13
20
|
type ComboboxTagRemove = ReturnType<typeof ComboboxTagRemove>;
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
*/
|
|
41
41
|
reserve?: number;
|
|
42
42
|
class?: string;
|
|
43
|
+
/** Accessible name of the tag row. Defaults to `Selected values`. */
|
|
44
|
+
'aria-label'?: string;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
// Renamed locally: the snippet we hand to `OverflowRow` must itself be named
|
|
@@ -49,7 +51,8 @@
|
|
|
49
51
|
children: renderTag,
|
|
50
52
|
overflow,
|
|
51
53
|
reserve = 0,
|
|
52
|
-
class: className = ''
|
|
54
|
+
class: className = '',
|
|
55
|
+
'aria-label': ariaLabel = 'Selected values'
|
|
53
56
|
}: ComboBoxTagsProps = $props();
|
|
54
57
|
|
|
55
58
|
const ctx = useComboBoxContext();
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
{reserve}
|
|
74
77
|
class={cn(className)}
|
|
75
78
|
role="list"
|
|
76
|
-
aria-label=
|
|
79
|
+
aria-label={ariaLabel}
|
|
77
80
|
>
|
|
78
81
|
{#snippet children({ item: selected })}
|
|
79
82
|
<TagContextProvider
|
|
@@ -34,6 +34,8 @@ type ComboBoxTagsProps = {
|
|
|
34
34
|
*/
|
|
35
35
|
reserve?: number;
|
|
36
36
|
class?: string;
|
|
37
|
+
/** Accessible name of the tag row. Defaults to `Selected values`. */
|
|
38
|
+
'aria-label'?: string;
|
|
37
39
|
};
|
|
38
40
|
declare const ComboboxTags: import("svelte").Component<ComboBoxTagsProps, {}, "">;
|
|
39
41
|
type ComboboxTags = ReturnType<typeof ComboboxTags>;
|
|
@@ -21,7 +21,10 @@
|
|
|
21
21
|
const ctx = useComboBoxContext();
|
|
22
22
|
const isTriggerDisabled = $derived(ctx.isDisabled || ctx.isReadOnly || ctx.isPending);
|
|
23
23
|
const defaultAriaLabel = $derived(
|
|
24
|
-
resolveLocalizedString(
|
|
24
|
+
resolveLocalizedString(
|
|
25
|
+
$localeStore,
|
|
26
|
+
ctx.isOpen ? 'combobox.hideOptions' : 'combobox.showOptions'
|
|
27
|
+
)
|
|
25
28
|
);
|
|
26
29
|
|
|
27
30
|
// Whether the popover was open when the current pointer press started. The
|
|
@@ -81,12 +81,13 @@
|
|
|
81
81
|
|
|
82
82
|
- Locale is read from `LocaleProvider` when available.
|
|
83
83
|
- Segment accessible names are resolved automatically from the active locale.
|
|
84
|
-
- During segment editing, the committed value is set to `null` when the draft
|
|
84
|
+
- During segment editing, the committed value is set to `null` only when the draft spells no date at all — empty, incomplete, or impossible (31/02). A complete date that `minValue`/`maxValue`/`isDateUnavailable` reject is still committed; see the UX decision below.
|
|
85
85
|
- Current MVP focuses on date-only values.
|
|
86
86
|
|
|
87
87
|
## UX Decisions
|
|
88
88
|
|
|
89
|
-
- **No Date Auto-Correction:** When users manually type dates out of the configured bounds (`minValue`/`maxValue`) or dates that are unavailable, the DatePicker **does not auto-correct** the typed value
|
|
89
|
+
- **No Date Auto-Correction:** When users manually type dates out of the configured bounds (`minValue`/`maxValue`) or dates that are unavailable, the DatePicker **does not auto-correct** the typed value, and does not snap it back. It exposes `aria-invalid="true"` and `data-invalid` on the input, so the user sees what they typed and that it is refused. Auto-correcting input without explicit user consent is an inaccessible anti-pattern.
|
|
90
|
+
- **A Rejected Date Is Still Committed:** the typed date is published through `onChange`/`value` even when the bounds refuse it. Publishing `null` instead would leave the input showing a date the consumer reads as an empty field — which is how a form ends up printing "required" underneath a filled-in control. Rejection travels as an invalid state, not as absence, so the layer that owns the rule (a form schema, usually) is the one that phrases the error. Typing bypasses the bounds this way; the Calendar does not — a disabled day is never selectable by pointer or keyboard.
|
|
90
91
|
- **Navigable Disabled Dates:** When using the Calendar, disabled dates remain focusable via keyboard navigation. This ensures ARIA Grid spatial navigation parity so that screen readers can consistently announce all calendar cells and report them as "disabled", rather than skipping over them and disorienting the user.
|
|
91
92
|
|
|
92
93
|
## Focus behavior decisions
|