@human-kit/ui 1.0.0-beta.3 → 1.0.0-beta.5
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 +15 -6
- package/dist/FOCUS_STATE_CONTRACT.md +2 -0
- package/dist/autocomplete/list/autocomplete-list.svelte.d.ts +3 -1
- package/dist/button/root/button-root.svelte +19 -3
- package/dist/button/root/button-root.svelte.d.ts +10 -0
- package/dist/combobox/list/combobox-listbox.svelte.d.ts +3 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internal/environment.d.ts +11 -0
- package/dist/internal/environment.js +14 -0
- package/dist/internal/localized-strings.d.ts +80 -0
- package/dist/internal/localized-strings.js +80 -0
- package/dist/listbox/README.md +27 -1
- package/dist/listbox/item/listbox-item.svelte +11 -2
- package/dist/listbox/root/context.d.ts +25 -0
- package/dist/listbox/root/context.js +108 -1
- package/dist/listbox/root/listbox.svelte +85 -7
- package/dist/listbox/root/listbox.svelte.d.ts +13 -1
- package/dist/menu/README.md +46 -0
- package/dist/menu/content/menu-content.svelte +16 -5
- package/dist/menu/content/menu-content.svelte.d.ts +2 -1
- package/dist/menu/context-trigger/menu-context-trigger.svelte +195 -0
- package/dist/menu/context-trigger/menu-context-trigger.svelte.d.ts +36 -0
- package/dist/menu/index.d.ts +4 -1
- package/dist/menu/index.js +1 -0
- package/dist/menu/index.parts.d.ts +1 -0
- package/dist/menu/index.parts.js +1 -0
- package/dist/menu/root/context.d.ts +18 -0
- package/dist/menu/root/menu-state.svelte.js +19 -0
- package/dist/popover/content/popover-content.svelte +2 -1
- package/dist/primitives/floating.d.ts +33 -5
- package/dist/primitives/floating.js +25 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/keyboard-navigation.d.ts +23 -5
- package/dist/primitives/keyboard-navigation.js +22 -15
- package/dist/primitives/long-press.d.ts +59 -0
- package/dist/primitives/long-press.js +142 -0
- package/dist/primitives/scroll-lock.d.ts +24 -0
- package/dist/primitives/scroll-lock.js +40 -0
- package/dist/toggle-group/README.md +10 -0
- package/dist/toggle-group/root/context.svelte.d.ts +1 -1
- package/dist/toggle-group/root/context.svelte.js +20 -11
- package/dist/toggle-group/root/toggle-group-root.svelte +20 -15
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte +13 -0
- package/dist/toggle-group/root/toggle-group-teardown-order-child.svelte.d.ts +7 -0
- package/dist/toggle-group/types.d.ts +7 -8
- package/dist/transfer-list/README.md +121 -0
- package/dist/transfer-list/index.d.ts +33 -0
- package/dist/transfer-list/index.js +18 -0
- package/dist/transfer-list/index.parts.d.ts +9 -0
- package/dist/transfer-list/index.parts.js +10 -0
- package/dist/transfer-list/item/transfer-list-item.svelte +74 -0
- package/dist/transfer-list/item/transfer-list-item.svelte.d.ts +35 -0
- package/dist/transfer-list/list/transfer-list-list.svelte +162 -0
- package/dist/transfer-list/list/transfer-list-list.svelte.d.ts +56 -0
- package/dist/transfer-list/list/transfer-list-source.svelte +13 -0
- package/dist/transfer-list/list/transfer-list-source.svelte.d.ts +36 -0
- package/dist/transfer-list/list/transfer-list-target.svelte +14 -0
- package/dist/transfer-list/list/transfer-list-target.svelte.d.ts +36 -0
- package/dist/transfer-list/move/transfer-list-move-all.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-all.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-button.svelte +103 -0
- package/dist/transfer-list/move/transfer-list-move-button.svelte.d.ts +25 -0
- package/dist/transfer-list/move/transfer-list-move-down.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-down.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-selected.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-selected.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-move-up.svelte +14 -0
- package/dist/transfer-list/move/transfer-list-move-up.svelte.d.ts +10 -0
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte +83 -0
- package/dist/transfer-list/move/transfer-list-reorder-button.svelte.d.ts +21 -0
- package/dist/transfer-list/root/context.d.ts +70 -0
- package/dist/transfer-list/root/context.js +24 -0
- package/dist/transfer-list/root/transfer-list-root.svelte +342 -0
- package/dist/transfer-list/root/transfer-list-root.svelte.d.ts +65 -0
- package/dist/transfer-list/root/types.d.ts +22 -0
- package/dist/transfer-list/root/types.js +4 -0
- package/dist/transfer-list/status/transfer-list-status.svelte +70 -0
- package/dist/transfer-list/status/transfer-list-status.svelte.d.ts +15 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -45,7 +45,7 @@ Or import a single component via its subpath for the leanest bundle:
|
|
|
45
45
|
|
|
46
46
|
| Category | Components |
|
|
47
47
|
| ----------- | ----------------------------------------------------------------------------- |
|
|
48
|
-
| Overlays | `Dialog`, `Popover`, `Menu`, `Portal`
|
|
48
|
+
| Overlays | `Dialog`, `Drawer`, `Popover`, `Menu`, `Portal` |
|
|
49
49
|
| Forms | `Input`, `TextArea`, `Label`, `Checkbox`, `Switch`, `NumberField`, `Dropzone` |
|
|
50
50
|
| Selection | `ComboBox`, `Autocomplete`, `ListBox`, `Toggle`, `ToggleGroup` |
|
|
51
51
|
| Date & time | `Calendar`, `Clock`, `DatePicker`, `DateRangePicker`, `TimePicker` |
|
|
@@ -58,11 +58,20 @@ Each component is also available as a subpath export (for example
|
|
|
58
58
|
|
|
59
59
|
## Styling
|
|
60
60
|
|
|
61
|
-
Components ship
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
Components are headless: they ship no CSS and assume no framework. Each part
|
|
62
|
+
takes a `class` and exposes its state as `data-*` attributes — `data-state`,
|
|
63
|
+
`data-disabled`, `data-focus-visible`, `data-pressed` and so on — so you can
|
|
64
|
+
style it with plain CSS, Tailwind, or anything else. Every component page in the
|
|
65
|
+
docs lists its full data-attribute contract.
|
|
66
|
+
|
|
67
|
+
```svelte
|
|
68
|
+
<Button.Root class="rounded-md bg-black px-3 py-1.5 text-white data-[pressed]:opacity-80">
|
|
69
|
+
Save
|
|
70
|
+
</Button.Root>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The only runtime dependency is [`@floating-ui/dom`](https://floating-ui.com), and
|
|
74
|
+
only the components that position something against an anchor use it.
|
|
66
75
|
|
|
67
76
|
## Requirements
|
|
68
77
|
|
|
@@ -57,9 +57,11 @@ The following components implement this contract:
|
|
|
57
57
|
- **Popover** — trigger + content, restore focus on close.
|
|
58
58
|
- **Dialog** — trigger + overlay/content, nested stack support.
|
|
59
59
|
- **Drawer** — trigger + overlay/content, shares the modal layer stack with Dialog. Restore also covers the `swipe` close reason (resolves to `pointer`), and retries the trigger focus after `ariaHideOutside` lifts `inert`.
|
|
60
|
+
- **Menu** — trigger + content, restore focus on close (`menu/root/focus-state.ts`). `Menu.ContextTrigger` is the same contract on a surface instead of a button: it registers as the trigger ref, so Escape and item selection restore focus to it. It is a tab stop by default so there is something to restore focus to.
|
|
60
61
|
- **DatePicker** — segment spinbuttons, trigger, popover (calendar).
|
|
61
62
|
- **TimePicker** — segment spinbuttons, trigger, popover (scrollable columns). Follows the same contract as DatePicker.
|
|
62
63
|
- **Calendar** — grid cells with roving tabindex.
|
|
63
64
|
- **ComboBox** — input + listbox with virtual focus.
|
|
64
65
|
- **ListBox** — items with roving tabindex.
|
|
66
|
+
- **TransferList** — two ListBoxes plus move buttons. Focus is placed explicitly after every move, because the rows the user was on stop existing: it stays on the button while that button still has work, and otherwise follows the items to the destination list; a double-clicked row hands focus to whichever row took its place.
|
|
65
67
|
- **NumberField** — spinbutton input, stepper buttons, wheel, and pointer scrub area.
|
|
@@ -5,6 +5,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
5
5
|
selectionBehavior?: "toggle" | "replace";
|
|
6
6
|
emptyPlaceholder?: string | Snippet;
|
|
7
7
|
items?: Iterable<object> | undefined;
|
|
8
|
+
getItemKey?: ((item: object) => string | number) | undefined;
|
|
8
9
|
disabledKeys?: Iterable<string | number>;
|
|
9
10
|
selectionMode?: "single" | "multiple";
|
|
10
11
|
value?: Iterable<string | number>;
|
|
@@ -15,6 +16,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
15
16
|
class?: string;
|
|
16
17
|
id?: string;
|
|
17
18
|
'aria-label'?: string;
|
|
19
|
+
'aria-labelledby'?: string;
|
|
18
20
|
onChange?: ((value: Set<string | number>) => void) | undefined;
|
|
19
21
|
disableFocusHandling?: boolean;
|
|
20
22
|
loop?: boolean;
|
|
@@ -23,7 +25,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
23
25
|
rowHeight?: number;
|
|
24
26
|
overscan?: number;
|
|
25
27
|
} | undefined;
|
|
26
|
-
} & {
|
|
28
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class" | "id" | "role" | "aria-label" | "aria-labelledby" | "onchange"> & {
|
|
27
29
|
context?: ListBoxContext;
|
|
28
30
|
element?: HTMLElement;
|
|
29
31
|
}, "children" | "id" | "element" | "context" | "disableFocusHandling" | "emptyPlaceholder" | "items"> & {
|
|
@@ -27,6 +27,16 @@
|
|
|
27
27
|
pending?: boolean | null;
|
|
28
28
|
/** Disables the button natively. */
|
|
29
29
|
disabled?: boolean | null;
|
|
30
|
+
/**
|
|
31
|
+
* Keeps a disabled button in the tab order, marking it `aria-disabled` instead of
|
|
32
|
+
* using the native attribute. Activation is still blocked.
|
|
33
|
+
*
|
|
34
|
+
* For controls that are unavailable more often than not — the move buttons of a
|
|
35
|
+
* transfer list, a toolbar that reacts to a selection. Natively disabling those hides
|
|
36
|
+
* them from anyone exploring with a keyboard, and shifts the tab order underfoot as
|
|
37
|
+
* the user works. Unlike `pending`, this says "not applicable", not "busy".
|
|
38
|
+
*/
|
|
39
|
+
focusableWhenDisabled?: boolean | null;
|
|
30
40
|
/** Bindable reference to the rendered button element. */
|
|
31
41
|
element?: HTMLButtonElement | null;
|
|
32
42
|
/** Overrides the internally tracked pressed state. */
|
|
@@ -69,6 +79,7 @@
|
|
|
69
79
|
class: className = '',
|
|
70
80
|
pending: pendingProp = false,
|
|
71
81
|
disabled: disabledProp = false,
|
|
82
|
+
focusableWhenDisabled: focusableWhenDisabledProp = false,
|
|
72
83
|
element = $bindable<HTMLButtonElement | null>(null),
|
|
73
84
|
pressed: pressedOverride,
|
|
74
85
|
onclick: onClickExternal,
|
|
@@ -96,6 +107,8 @@
|
|
|
96
107
|
|
|
97
108
|
const disabled = $derived(Boolean(disabledProp));
|
|
98
109
|
const pending = $derived(Boolean(pendingProp));
|
|
110
|
+
const focusableWhenDisabled = $derived(Boolean(focusableWhenDisabledProp));
|
|
111
|
+
const nativelyDisabled = $derived(disabled && !focusableWhenDisabled);
|
|
99
112
|
|
|
100
113
|
let buttonRef: HTMLButtonElement | null = $state(null);
|
|
101
114
|
let hovered = $state(false);
|
|
@@ -341,7 +354,10 @@
|
|
|
341
354
|
trackInteractionModality(event, buttonRef);
|
|
342
355
|
}
|
|
343
356
|
|
|
344
|
-
|
|
357
|
+
// `disabled` matters here only in the focusable case: a natively disabled button never
|
|
358
|
+
// dispatches a click at all. Preventing default also stops the consumer's handler,
|
|
359
|
+
// which is what `skipExternalOnDefaultPrevented` is for.
|
|
360
|
+
if (pending || disabled) {
|
|
345
361
|
event.preventDefault();
|
|
346
362
|
clearInteractionState();
|
|
347
363
|
}
|
|
@@ -353,10 +369,10 @@
|
|
|
353
369
|
bind:this={buttonRef}
|
|
354
370
|
id={resolvedId}
|
|
355
371
|
type={renderedType}
|
|
356
|
-
{
|
|
372
|
+
disabled={nativelyDisabled}
|
|
357
373
|
aria-label={ariaLabel}
|
|
358
374
|
aria-labelledby={ariaLabelledby}
|
|
359
|
-
aria-disabled={pending ? 'true' : undefined}
|
|
375
|
+
aria-disabled={pending || (disabled && focusableWhenDisabled) ? 'true' : undefined}
|
|
360
376
|
aria-busy={pending ? 'true' : undefined}
|
|
361
377
|
data-button-root="true"
|
|
362
378
|
data-disabled={disabled || undefined}
|
|
@@ -16,6 +16,16 @@ type ButtonRootProps = Omit<HTMLButtonAttributes, 'children' | 'class' | 'disabl
|
|
|
16
16
|
pending?: boolean | null;
|
|
17
17
|
/** Disables the button natively. */
|
|
18
18
|
disabled?: boolean | null;
|
|
19
|
+
/**
|
|
20
|
+
* Keeps a disabled button in the tab order, marking it `aria-disabled` instead of
|
|
21
|
+
* using the native attribute. Activation is still blocked.
|
|
22
|
+
*
|
|
23
|
+
* For controls that are unavailable more often than not — the move buttons of a
|
|
24
|
+
* transfer list, a toolbar that reacts to a selection. Natively disabling those hides
|
|
25
|
+
* them from anyone exploring with a keyboard, and shifts the tab order underfoot as
|
|
26
|
+
* the user works. Unlike `pending`, this says "not applicable", not "busy".
|
|
27
|
+
*/
|
|
28
|
+
focusableWhenDisabled?: boolean | null;
|
|
19
29
|
/** Bindable reference to the rendered button element. */
|
|
20
30
|
element?: HTMLButtonElement | null;
|
|
21
31
|
/** Overrides the internally tracked pressed state. */
|
|
@@ -5,6 +5,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
5
5
|
selectionBehavior?: "toggle" | "replace";
|
|
6
6
|
emptyPlaceholder?: string | Snippet;
|
|
7
7
|
items?: Iterable<object> | undefined;
|
|
8
|
+
getItemKey?: ((item: object) => string | number) | undefined;
|
|
8
9
|
disabledKeys?: Iterable<string | number>;
|
|
9
10
|
selectionMode?: "single" | "multiple";
|
|
10
11
|
value?: Iterable<string | number>;
|
|
@@ -15,6 +16,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
15
16
|
class?: string;
|
|
16
17
|
id?: string;
|
|
17
18
|
'aria-label'?: string;
|
|
19
|
+
'aria-labelledby'?: string;
|
|
18
20
|
onChange?: ((value: Set<string | number>) => void) | undefined;
|
|
19
21
|
disableFocusHandling?: boolean;
|
|
20
22
|
loop?: boolean;
|
|
@@ -23,7 +25,7 @@ declare function $$render<T extends object = object>(): {
|
|
|
23
25
|
rowHeight?: number;
|
|
24
26
|
overscan?: number;
|
|
25
27
|
} | undefined;
|
|
26
|
-
} & {
|
|
28
|
+
} & Omit<import("svelte/elements").HTMLAttributes<HTMLDivElement>, "children" | "class" | "id" | "role" | "aria-label" | "aria-labelledby" | "onchange"> & {
|
|
27
29
|
context?: ListBoxContext;
|
|
28
30
|
element?: HTMLElement;
|
|
29
31
|
}, "children" | "id" | "value" | "element" | "defaultValue" | "onChange" | "selectionMode" | "context" | "selectionBehavior" | "items"> & {
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { Table } from './table/index.js';
|
|
|
20
20
|
export { Tabs } from './tabs/index.js';
|
|
21
21
|
export { Toggle } from './toggle/index.js';
|
|
22
22
|
export { ToggleGroup } from './toggle-group/index.js';
|
|
23
|
+
export { TransferList } from './transfer-list/index.js';
|
|
23
24
|
export { Tree } from './tree/index.js';
|
|
24
25
|
export { default as Input } from './input/index.js';
|
|
25
26
|
export { default as Label } from './label/index.js';
|
|
@@ -52,6 +53,7 @@ export * from './table/index.js';
|
|
|
52
53
|
export * from './tabs/index.js';
|
|
53
54
|
export * from './toggle/index.js';
|
|
54
55
|
export * from './toggle-group/index.js';
|
|
56
|
+
export * from './transfer-list/index.js';
|
|
55
57
|
export * from './tree/index.js';
|
|
56
58
|
export * from './primitives/index.js';
|
|
57
59
|
export { cn } from './utils/index.js';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { Table } from './table/index.js';
|
|
|
22
22
|
export { Tabs } from './tabs/index.js';
|
|
23
23
|
export { Toggle } from './toggle/index.js';
|
|
24
24
|
export { ToggleGroup } from './toggle-group/index.js';
|
|
25
|
+
export { TransferList } from './transfer-list/index.js';
|
|
25
26
|
export { Tree } from './tree/index.js';
|
|
26
27
|
// Simple components
|
|
27
28
|
export { default as Input } from './input/index.js';
|
|
@@ -56,6 +57,7 @@ export * from './table/index.js';
|
|
|
56
57
|
export * from './tabs/index.js';
|
|
57
58
|
export * from './toggle/index.js';
|
|
58
59
|
export * from './toggle-group/index.js';
|
|
60
|
+
export * from './transfer-list/index.js';
|
|
59
61
|
export * from './tree/index.js';
|
|
60
62
|
// Primitives
|
|
61
63
|
export * from './primitives/index.js';
|
|
@@ -1,2 +1,13 @@
|
|
|
1
1
|
export declare const browser: boolean;
|
|
2
2
|
export declare const dev: boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Whether the platform uses Cmd where the rest use Ctrl.
|
|
5
|
+
*
|
|
6
|
+
* Only for *naming* a shortcut — `aria-keyshortcuts`, a hint in the UI. Never gate behaviour
|
|
7
|
+
* on it: handlers should accept `ctrlKey || metaKey` and let either work everywhere, which is
|
|
8
|
+
* both simpler and right for a user on an Apple keyboard plugged into something else.
|
|
9
|
+
*
|
|
10
|
+
* `false` on the server, where there is no platform to read; the value is corrected on
|
|
11
|
+
* hydration, and an attribute that names a key is safe to settle a tick late.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isApplePlatform: boolean;
|
|
@@ -1,2 +1,16 @@
|
|
|
1
1
|
export const browser = typeof window !== 'undefined' && typeof document !== 'undefined';
|
|
2
2
|
export const dev = import.meta.env?.DEV ?? false;
|
|
3
|
+
/**
|
|
4
|
+
* Whether the platform uses Cmd where the rest use Ctrl.
|
|
5
|
+
*
|
|
6
|
+
* Only for *naming* a shortcut — `aria-keyshortcuts`, a hint in the UI. Never gate behaviour
|
|
7
|
+
* on it: handlers should accept `ctrlKey || metaKey` and let either work everywhere, which is
|
|
8
|
+
* both simpler and right for a user on an Apple keyboard plugged into something else.
|
|
9
|
+
*
|
|
10
|
+
* `false` on the server, where there is no platform to read; the value is corrected on
|
|
11
|
+
* hydration, and an attribute that names a key is safe to settle a tick late.
|
|
12
|
+
*/
|
|
13
|
+
export const isApplePlatform = browser &&
|
|
14
|
+
/mac|iphone|ipad|ipod/i.test(navigator.userAgentData?.platform ??
|
|
15
|
+
navigator.platform ??
|
|
16
|
+
'');
|
|
@@ -224,6 +224,86 @@ declare const LOCALIZED_STRINGS: {
|
|
|
224
224
|
readonly de: "{count} Ergebnisse verfügbar";
|
|
225
225
|
readonly it: "{count} risultati disponibili";
|
|
226
226
|
};
|
|
227
|
+
readonly 'transferList.moveSelectedTo': {
|
|
228
|
+
readonly en: "Move selected to {label}";
|
|
229
|
+
readonly es: "Mover la selección a {label}";
|
|
230
|
+
readonly pt: "Mover a seleção para {label}";
|
|
231
|
+
readonly fr: "Déplacer la sélection vers {label}";
|
|
232
|
+
readonly de: "Auswahl nach {label} verschieben";
|
|
233
|
+
readonly it: "Sposta la selezione in {label}";
|
|
234
|
+
};
|
|
235
|
+
readonly 'transferList.moveAllTo': {
|
|
236
|
+
readonly en: "Move all to {label}";
|
|
237
|
+
readonly es: "Mover todo a {label}";
|
|
238
|
+
readonly pt: "Mover tudo para {label}";
|
|
239
|
+
readonly fr: "Tout déplacer vers {label}";
|
|
240
|
+
readonly de: "Alle nach {label} verschieben";
|
|
241
|
+
readonly it: "Sposta tutto in {label}";
|
|
242
|
+
};
|
|
243
|
+
readonly 'transferList.moveUp': {
|
|
244
|
+
readonly en: "Move selected up";
|
|
245
|
+
readonly es: "Subir la selección";
|
|
246
|
+
readonly pt: "Mover a seleção para cima";
|
|
247
|
+
readonly fr: "Déplacer la sélection vers le haut";
|
|
248
|
+
readonly de: "Auswahl nach oben verschieben";
|
|
249
|
+
readonly it: "Sposta la selezione in alto";
|
|
250
|
+
};
|
|
251
|
+
readonly 'transferList.moveDown': {
|
|
252
|
+
readonly en: "Move selected down";
|
|
253
|
+
readonly es: "Bajar la selección";
|
|
254
|
+
readonly pt: "Mover a seleção para baixo";
|
|
255
|
+
readonly fr: "Déplacer la sélection vers le bas";
|
|
256
|
+
readonly de: "Auswahl nach unten verschieben";
|
|
257
|
+
readonly it: "Sposta la selezione in basso";
|
|
258
|
+
};
|
|
259
|
+
readonly 'transferList.itemMovedUp': {
|
|
260
|
+
readonly en: "1 item moved up";
|
|
261
|
+
readonly es: "1 elemento subido";
|
|
262
|
+
readonly pt: "1 item movido para cima";
|
|
263
|
+
readonly fr: "1 élément déplacé vers le haut";
|
|
264
|
+
readonly de: "1 Element nach oben verschoben";
|
|
265
|
+
readonly it: "1 elemento spostato in alto";
|
|
266
|
+
};
|
|
267
|
+
readonly 'transferList.itemsMovedUp': {
|
|
268
|
+
readonly en: "{count} items moved up";
|
|
269
|
+
readonly es: "{count} elementos subidos";
|
|
270
|
+
readonly pt: "{count} itens movidos para cima";
|
|
271
|
+
readonly fr: "{count} éléments déplacés vers le haut";
|
|
272
|
+
readonly de: "{count} Elemente nach oben verschoben";
|
|
273
|
+
readonly it: "{count} elementi spostati in alto";
|
|
274
|
+
};
|
|
275
|
+
readonly 'transferList.itemMovedDown': {
|
|
276
|
+
readonly en: "1 item moved down";
|
|
277
|
+
readonly es: "1 elemento bajado";
|
|
278
|
+
readonly pt: "1 item movido para baixo";
|
|
279
|
+
readonly fr: "1 élément déplacé vers le bas";
|
|
280
|
+
readonly de: "1 Element nach unten verschoben";
|
|
281
|
+
readonly it: "1 elemento spostato in basso";
|
|
282
|
+
};
|
|
283
|
+
readonly 'transferList.itemsMovedDown': {
|
|
284
|
+
readonly en: "{count} items moved down";
|
|
285
|
+
readonly es: "{count} elementos bajados";
|
|
286
|
+
readonly pt: "{count} itens movidos para baixo";
|
|
287
|
+
readonly fr: "{count} éléments déplacés vers le bas";
|
|
288
|
+
readonly de: "{count} Elemente nach unten verschoben";
|
|
289
|
+
readonly it: "{count} elementi spostati in basso";
|
|
290
|
+
};
|
|
291
|
+
readonly 'transferList.itemMoved': {
|
|
292
|
+
readonly en: "1 item moved to {label}";
|
|
293
|
+
readonly es: "1 elemento movido a {label}";
|
|
294
|
+
readonly pt: "1 item movido para {label}";
|
|
295
|
+
readonly fr: "1 élément déplacé vers {label}";
|
|
296
|
+
readonly de: "1 Element nach {label} verschoben";
|
|
297
|
+
readonly it: "1 elemento spostato in {label}";
|
|
298
|
+
};
|
|
299
|
+
readonly 'transferList.itemsMoved': {
|
|
300
|
+
readonly en: "{count} items moved to {label}";
|
|
301
|
+
readonly es: "{count} elementos movidos a {label}";
|
|
302
|
+
readonly pt: "{count} itens movidos para {label}";
|
|
303
|
+
readonly fr: "{count} éléments déplacés vers {label}";
|
|
304
|
+
readonly de: "{count} Elemente nach {label} verschoben";
|
|
305
|
+
readonly it: "{count} elementi spostati in {label}";
|
|
306
|
+
};
|
|
227
307
|
readonly 'segment.empty': {
|
|
228
308
|
readonly en: "Empty";
|
|
229
309
|
readonly es: "Vacío";
|
|
@@ -224,6 +224,86 @@ const LOCALIZED_STRINGS = {
|
|
|
224
224
|
de: '{count} Ergebnisse verfügbar',
|
|
225
225
|
it: '{count} risultati disponibili'
|
|
226
226
|
},
|
|
227
|
+
'transferList.moveSelectedTo': {
|
|
228
|
+
en: 'Move selected to {label}',
|
|
229
|
+
es: 'Mover la selección a {label}',
|
|
230
|
+
pt: 'Mover a seleção para {label}',
|
|
231
|
+
fr: 'Déplacer la sélection vers {label}',
|
|
232
|
+
de: 'Auswahl nach {label} verschieben',
|
|
233
|
+
it: 'Sposta la selezione in {label}'
|
|
234
|
+
},
|
|
235
|
+
'transferList.moveAllTo': {
|
|
236
|
+
en: 'Move all to {label}',
|
|
237
|
+
es: 'Mover todo a {label}',
|
|
238
|
+
pt: 'Mover tudo para {label}',
|
|
239
|
+
fr: 'Tout déplacer vers {label}',
|
|
240
|
+
de: 'Alle nach {label} verschieben',
|
|
241
|
+
it: 'Sposta tutto in {label}'
|
|
242
|
+
},
|
|
243
|
+
'transferList.moveUp': {
|
|
244
|
+
en: 'Move selected up',
|
|
245
|
+
es: 'Subir la selección',
|
|
246
|
+
pt: 'Mover a seleção para cima',
|
|
247
|
+
fr: 'Déplacer la sélection vers le haut',
|
|
248
|
+
de: 'Auswahl nach oben verschieben',
|
|
249
|
+
it: 'Sposta la selezione in alto'
|
|
250
|
+
},
|
|
251
|
+
'transferList.moveDown': {
|
|
252
|
+
en: 'Move selected down',
|
|
253
|
+
es: 'Bajar la selección',
|
|
254
|
+
pt: 'Mover a seleção para baixo',
|
|
255
|
+
fr: 'Déplacer la sélection vers le bas',
|
|
256
|
+
de: 'Auswahl nach unten verschieben',
|
|
257
|
+
it: 'Sposta la selezione in basso'
|
|
258
|
+
},
|
|
259
|
+
'transferList.itemMovedUp': {
|
|
260
|
+
en: '1 item moved up',
|
|
261
|
+
es: '1 elemento subido',
|
|
262
|
+
pt: '1 item movido para cima',
|
|
263
|
+
fr: '1 élément déplacé vers le haut',
|
|
264
|
+
de: '1 Element nach oben verschoben',
|
|
265
|
+
it: '1 elemento spostato in alto'
|
|
266
|
+
},
|
|
267
|
+
'transferList.itemsMovedUp': {
|
|
268
|
+
en: '{count} items moved up',
|
|
269
|
+
es: '{count} elementos subidos',
|
|
270
|
+
pt: '{count} itens movidos para cima',
|
|
271
|
+
fr: '{count} éléments déplacés vers le haut',
|
|
272
|
+
de: '{count} Elemente nach oben verschoben',
|
|
273
|
+
it: '{count} elementi spostati in alto'
|
|
274
|
+
},
|
|
275
|
+
'transferList.itemMovedDown': {
|
|
276
|
+
en: '1 item moved down',
|
|
277
|
+
es: '1 elemento bajado',
|
|
278
|
+
pt: '1 item movido para baixo',
|
|
279
|
+
fr: '1 élément déplacé vers le bas',
|
|
280
|
+
de: '1 Element nach unten verschoben',
|
|
281
|
+
it: '1 elemento spostato in basso'
|
|
282
|
+
},
|
|
283
|
+
'transferList.itemsMovedDown': {
|
|
284
|
+
en: '{count} items moved down',
|
|
285
|
+
es: '{count} elementos bajados',
|
|
286
|
+
pt: '{count} itens movidos para baixo',
|
|
287
|
+
fr: '{count} éléments déplacés vers le bas',
|
|
288
|
+
de: '{count} Elemente nach unten verschoben',
|
|
289
|
+
it: '{count} elementi spostati in basso'
|
|
290
|
+
},
|
|
291
|
+
'transferList.itemMoved': {
|
|
292
|
+
en: '1 item moved to {label}',
|
|
293
|
+
es: '1 elemento movido a {label}',
|
|
294
|
+
pt: '1 item movido para {label}',
|
|
295
|
+
fr: '1 élément déplacé vers {label}',
|
|
296
|
+
de: '1 Element nach {label} verschoben',
|
|
297
|
+
it: '1 elemento spostato in {label}'
|
|
298
|
+
},
|
|
299
|
+
'transferList.itemsMoved': {
|
|
300
|
+
en: '{count} items moved to {label}',
|
|
301
|
+
es: '{count} elementos movidos a {label}',
|
|
302
|
+
pt: '{count} itens movidos para {label}',
|
|
303
|
+
fr: '{count} éléments déplacés vers {label}',
|
|
304
|
+
de: '{count} Elemente nach {label} verschoben',
|
|
305
|
+
it: '{count} elementi spostati in {label}'
|
|
306
|
+
},
|
|
227
307
|
'segment.empty': {
|
|
228
308
|
en: 'Empty',
|
|
229
309
|
es: 'Vacío',
|
package/dist/listbox/README.md
CHANGED
|
@@ -10,7 +10,33 @@
|
|
|
10
10
|
- Render each option with `ListBox.Item`.
|
|
11
11
|
- Use `value` and `onChange` for controlled selection.
|
|
12
12
|
- Use `defaultValue` for uncontrolled initial selection.
|
|
13
|
-
- Provide `aria-label` when there is no visible label.
|
|
13
|
+
- Provide `aria-label` when there is no visible label, or `aria-labelledby` when there is one.
|
|
14
|
+
|
|
15
|
+
## Range selection
|
|
16
|
+
|
|
17
|
+
In `selectionMode="multiple"`, Shift selects a range and Ctrl/Cmd adds a single item:
|
|
18
|
+
|
|
19
|
+
- **Shift+click** selects everything between the anchor and the clicked option. The anchor is
|
|
20
|
+
the last option selected without modifiers.
|
|
21
|
+
- **Shift+Arrow**, **Shift+Home** and **Shift+End** extend the same range with the keyboard.
|
|
22
|
+
- A range **replaces** the selection rather than adding to it, following the APG multi-select
|
|
23
|
+
listbox pattern — that is what lets a range shrink again when you drag it back toward the
|
|
24
|
+
anchor.
|
|
25
|
+
- **Ctrl/Cmd+click** toggles one option even under `selectionBehavior="replace"`, where a
|
|
26
|
+
plain click would clear the rest.
|
|
27
|
+
- Disabled options are never included.
|
|
28
|
+
|
|
29
|
+
The range is measured over the options that exist in the DOM. In a **virtualized** list that is
|
|
30
|
+
only the rendered window, so pass `getItemKey` alongside `virtualizer` and the range is measured
|
|
31
|
+
over the whole collection instead — a range then spans rows that were never rendered, and the
|
|
32
|
+
anchor survives being scrolled away.
|
|
33
|
+
|
|
34
|
+
## Virtualized lists and assistive technology
|
|
35
|
+
|
|
36
|
+
A virtualized list holds a handful of options, so the position and count a browser computes from
|
|
37
|
+
the DOM describe the window rather than the collection — a screen reader would announce "1 of 8"
|
|
38
|
+
for a list of two thousand. `ListBox` writes `aria-setsize` and `aria-posinset` onto the rendered
|
|
39
|
+
rows with the real numbers.
|
|
14
40
|
|
|
15
41
|
## Anatomy
|
|
16
42
|
|
|
@@ -279,11 +279,17 @@
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
function handleClick() {
|
|
282
|
+
function handleClick(event: MouseEvent) {
|
|
283
283
|
if (isDisabledComputed) return;
|
|
284
284
|
|
|
285
285
|
const label = getResolvedTextValue();
|
|
286
286
|
|
|
287
|
+
// Shift+click also drags the browser's own text selection across the rows it spans,
|
|
288
|
+
// which paints the whole range blue on top of the widget's own selection styling.
|
|
289
|
+
if (event.shiftKey) {
|
|
290
|
+
window.getSelection()?.removeAllRanges();
|
|
291
|
+
}
|
|
292
|
+
|
|
287
293
|
if (!disableFocusHandling && elementRef) {
|
|
288
294
|
suppressNextFocusVisible = true;
|
|
289
295
|
isFocusVisible = false;
|
|
@@ -297,7 +303,10 @@
|
|
|
297
303
|
if (onItemSelect) {
|
|
298
304
|
onItemSelect(id, label);
|
|
299
305
|
} else {
|
|
300
|
-
listboxCtx.
|
|
306
|
+
listboxCtx.selectWithModifiers(id, {
|
|
307
|
+
shift: event.shiftKey,
|
|
308
|
+
ctrlOrMeta: event.ctrlKey || event.metaKey
|
|
309
|
+
});
|
|
301
310
|
}
|
|
302
311
|
|
|
303
312
|
if (!disableFocusHandling) {
|
|
@@ -41,6 +41,31 @@ export type ListBoxContext = {
|
|
|
41
41
|
subscribeToItemCount: (callback: (count: number) => void) => () => void;
|
|
42
42
|
/** Selects or toggles an item based on current mode and behavior. */
|
|
43
43
|
select: (id: string | number) => void;
|
|
44
|
+
/**
|
|
45
|
+
* Selects an item honouring the modifier keys that were held.
|
|
46
|
+
*
|
|
47
|
+
* `shift` extends the selection from the anchor — the last item selected without
|
|
48
|
+
* modifiers — to this one, replacing whatever was selected, which is what the APG
|
|
49
|
+
* multi-select listbox pattern does. `ctrlOrMeta` forces a toggle even when
|
|
50
|
+
* `selectionBehavior` is `'replace'`. Both are ignored in single-selection mode.
|
|
51
|
+
*/
|
|
52
|
+
selectWithModifiers: (id: string | number, modifiers?: {
|
|
53
|
+
shift?: boolean;
|
|
54
|
+
ctrlOrMeta?: boolean;
|
|
55
|
+
}) => void;
|
|
56
|
+
/** Selects every enabled item between the anchor and `id`, in list order. */
|
|
57
|
+
extendSelectionTo: (id: string | number) => void;
|
|
58
|
+
/** The item ranges are measured from, or `null` when there isn't one yet. */
|
|
59
|
+
getAnchorId: () => string | number | null;
|
|
60
|
+
/**
|
|
61
|
+
* Registers the full list of keys, in list order, for a virtualized list.
|
|
62
|
+
*
|
|
63
|
+
* Ranges are otherwise measured over the options in the DOM, which in a virtualized
|
|
64
|
+
* list is only the rendered window — a Shift range then stops at the edge of what
|
|
65
|
+
* happens to be on screen. The ListBox supplies this when it has both `items` and a
|
|
66
|
+
* `getItemKey` to read their keys with.
|
|
67
|
+
*/
|
|
68
|
+
setOrderedKeys: (read: (() => (string | number)[]) | null) => void;
|
|
44
69
|
/** Selects all enabled items (only works in multiple mode). */
|
|
45
70
|
selectAll: () => void;
|
|
46
71
|
/** Sets the selection programmatically (for controlled mode). */
|
|
@@ -11,6 +11,10 @@ export function createListBoxContext(options = {}) {
|
|
|
11
11
|
const disabledKeys = new SvelteSet(options.disabledKeys ?? []);
|
|
12
12
|
const items = new Map();
|
|
13
13
|
let selectedKeys = new Set(options.initialSelection ?? []);
|
|
14
|
+
/** Where a Shift range starts: the last item selected without modifiers. */
|
|
15
|
+
let anchorId = null;
|
|
16
|
+
/** Set by a virtualized ListBox so ranges can reach rows that were never rendered. */
|
|
17
|
+
let readOrderedKeys = null;
|
|
14
18
|
const itemCallbacks = new Map();
|
|
15
19
|
// Item count tracking with subscription
|
|
16
20
|
const itemCountCallbacks = new Set();
|
|
@@ -28,8 +32,46 @@ export function createListBoxContext(options = {}) {
|
|
|
28
32
|
function unregisterItem(id) {
|
|
29
33
|
items.delete(id);
|
|
30
34
|
itemCallbacks.delete(id);
|
|
35
|
+
// A range measured from an item that no longer exists would silently select nothing.
|
|
36
|
+
// In a virtualized list, though, unregistering is just scrolling away — the anchor is
|
|
37
|
+
// still part of the collection and has to survive, or a range made across a scroll
|
|
38
|
+
// collapses to the single option that ended it. The `anchorId` check comes first so
|
|
39
|
+
// the list order is only rebuilt for the one row that could matter.
|
|
40
|
+
if (anchorId === id && !getOrderedIds().includes(id)) {
|
|
41
|
+
anchorId = null;
|
|
42
|
+
}
|
|
31
43
|
notifyItemCountChange();
|
|
32
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Ids in list order.
|
|
47
|
+
*
|
|
48
|
+
* A virtualized list registers the whole collection up front, because only its
|
|
49
|
+
* rendered window exists in the DOM and a range measured over that stops wherever the
|
|
50
|
+
* user happened to have scrolled.
|
|
51
|
+
*
|
|
52
|
+
* Otherwise: sorted by DOM position when every item has an element on the page,
|
|
53
|
+
* because registration order and render order diverge as soon as a keyed list is
|
|
54
|
+
* reordered. Falls back to registration order rather than sorting a partial set, which
|
|
55
|
+
* would interleave measured and unmeasured items into an order that matches neither.
|
|
56
|
+
*/
|
|
57
|
+
function getOrderedIds() {
|
|
58
|
+
if (readOrderedKeys)
|
|
59
|
+
return readOrderedKeys();
|
|
60
|
+
const entries = Array.from(items.entries());
|
|
61
|
+
const positioned = entries.filter(([, meta]) => meta.element?.isConnected);
|
|
62
|
+
if (positioned.length !== entries.length) {
|
|
63
|
+
return entries.map(([id]) => id);
|
|
64
|
+
}
|
|
65
|
+
positioned.sort(([, a], [, b]) => {
|
|
66
|
+
const position = a.element.compareDocumentPosition(b.element);
|
|
67
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
68
|
+
return -1;
|
|
69
|
+
if (position & Node.DOCUMENT_POSITION_PRECEDING)
|
|
70
|
+
return 1;
|
|
71
|
+
return 0;
|
|
72
|
+
});
|
|
73
|
+
return positioned.map(([id]) => id);
|
|
74
|
+
}
|
|
33
75
|
function getItemCount() {
|
|
34
76
|
return items.size;
|
|
35
77
|
}
|
|
@@ -179,8 +221,58 @@ export function createListBoxContext(options = {}) {
|
|
|
179
221
|
function select(id) {
|
|
180
222
|
if (isDisabled(id))
|
|
181
223
|
return;
|
|
224
|
+
// Any unmodified selection re-anchors: the next Shift range is measured from here.
|
|
225
|
+
anchorId = id;
|
|
182
226
|
commitSelection(computeNextSelection(id));
|
|
183
227
|
}
|
|
228
|
+
function extendSelectionTo(id) {
|
|
229
|
+
if (getSelectionMode() !== 'multiple')
|
|
230
|
+
return;
|
|
231
|
+
const ordered = getOrderedIds();
|
|
232
|
+
const from = ordered.indexOf(anchorId ?? id);
|
|
233
|
+
const to = ordered.indexOf(id);
|
|
234
|
+
if (from === -1 || to === -1)
|
|
235
|
+
return;
|
|
236
|
+
const [start, end] = from <= to ? [from, to] : [to, from];
|
|
237
|
+
const next = new Set();
|
|
238
|
+
for (let index = start; index <= end; index += 1) {
|
|
239
|
+
const key = ordered[index];
|
|
240
|
+
if (!isDisabled(key))
|
|
241
|
+
next.add(key);
|
|
242
|
+
}
|
|
243
|
+
// The range REPLACES the selection rather than adding to it: dragging a Shift range
|
|
244
|
+
// back and forth has to shrink it again, which only works if each extension is
|
|
245
|
+
// recomputed from the anchor.
|
|
246
|
+
commitSelection(next);
|
|
247
|
+
}
|
|
248
|
+
function selectWithModifiers(id, modifiers) {
|
|
249
|
+
if (isDisabled(id))
|
|
250
|
+
return;
|
|
251
|
+
if (modifiers?.shift && getSelectionMode() === 'multiple') {
|
|
252
|
+
// First Shift press with nothing anchored yet: the item the user was on is the
|
|
253
|
+
// start of the range.
|
|
254
|
+
if (anchorId === null) {
|
|
255
|
+
anchorId = focusedId ?? id;
|
|
256
|
+
}
|
|
257
|
+
extendSelectionTo(id);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (modifiers?.ctrlOrMeta && getSelectionMode() === 'multiple') {
|
|
261
|
+
// Toggle regardless of `selectionBehavior`: with `'replace'` a plain click clears
|
|
262
|
+
// the rest, and Ctrl/Cmd+click is how you add one item without losing them.
|
|
263
|
+
anchorId = id;
|
|
264
|
+
const next = new Set(selectedKeys);
|
|
265
|
+
if (next.has(id)) {
|
|
266
|
+
next.delete(id);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
next.add(id);
|
|
270
|
+
}
|
|
271
|
+
commitSelection(next);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
select(id);
|
|
275
|
+
}
|
|
184
276
|
function selectAll() {
|
|
185
277
|
if (getSelectionMode() !== 'multiple')
|
|
186
278
|
return;
|
|
@@ -201,8 +293,17 @@ export function createListBoxContext(options = {}) {
|
|
|
201
293
|
onSelect: (id) => {
|
|
202
294
|
select(id);
|
|
203
295
|
},
|
|
204
|
-
onFocusChange: (id) => {
|
|
296
|
+
onFocusChange: (id, _element, intent) => {
|
|
205
297
|
setFocusedId(id);
|
|
298
|
+
if (!intent?.extend || id === null)
|
|
299
|
+
return;
|
|
300
|
+
// With nothing anchored, a Shift+Arrow starts its range at the item the user was
|
|
301
|
+
// standing on — which only `intent.from` still knows, since focusing the new item
|
|
302
|
+
// already moved `focusedId`.
|
|
303
|
+
if (anchorId === null) {
|
|
304
|
+
anchorId = intent.from ?? id;
|
|
305
|
+
}
|
|
306
|
+
extendSelectionTo(id);
|
|
206
307
|
},
|
|
207
308
|
// `selectAll` checks the selection mode at call time so runtime mode
|
|
208
309
|
// changes are respected.
|
|
@@ -231,6 +332,12 @@ export function createListBoxContext(options = {}) {
|
|
|
231
332
|
getItemCount,
|
|
232
333
|
subscribeToItemCount,
|
|
233
334
|
select,
|
|
335
|
+
selectWithModifiers,
|
|
336
|
+
extendSelectionTo,
|
|
337
|
+
getAnchorId: () => anchorId,
|
|
338
|
+
setOrderedKeys: (read) => {
|
|
339
|
+
readOrderedKeys = read;
|
|
340
|
+
},
|
|
234
341
|
selectAll,
|
|
235
342
|
setSelection,
|
|
236
343
|
setFocusedId,
|