@human-kit/ui 1.0.0-beta.6 → 1.0.0-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FOCUS_STATE_CONTRACT.md +15 -4
- package/dist/FOCUS_STATE_REVIEW_TEMPLATE.md +8 -8
- package/dist/autocomplete/item/autocomplete-item.svelte +10 -0
- package/dist/avatar/README.md +52 -0
- package/dist/avatar/count/avatar-count.svelte +56 -0
- package/dist/avatar/count/avatar-count.svelte.d.ts +4 -0
- package/dist/avatar/fallback/avatar-fallback.svelte +67 -0
- package/dist/avatar/fallback/avatar-fallback.svelte.d.ts +4 -0
- package/dist/avatar/group/avatar-group.svelte +65 -0
- package/dist/avatar/group/avatar-group.svelte.d.ts +4 -0
- package/dist/avatar/group/context.d.ts +15 -0
- package/dist/avatar/group/context.js +15 -0
- package/dist/avatar/image/avatar-image.svelte +104 -0
- package/dist/avatar/image/avatar-image.svelte.d.ts +4 -0
- package/dist/avatar/index.d.ts +22 -0
- package/dist/avatar/index.js +10 -0
- package/dist/avatar/index.parts.d.ts +5 -0
- package/dist/avatar/index.parts.js +5 -0
- package/dist/avatar/root/avatar-root.svelte +79 -0
- package/dist/avatar/root/avatar-root.svelte.d.ts +4 -0
- package/dist/avatar/root/context.d.ts +14 -0
- package/dist/avatar/root/context.js +15 -0
- package/dist/avatar/types.d.ts +84 -0
- package/dist/avatar/types.js +1 -0
- package/dist/breadcrumbs/README.md +65 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte +62 -0
- package/dist/breadcrumbs/ellipsis/breadcrumbs-ellipsis.svelte.d.ts +4 -0
- package/dist/breadcrumbs/index.d.ts +23 -0
- package/dist/breadcrumbs/index.js +10 -0
- package/dist/breadcrumbs/index.parts.d.ts +6 -0
- package/dist/breadcrumbs/index.parts.js +6 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte +42 -0
- package/dist/breadcrumbs/item/breadcrumbs-item.svelte.d.ts +4 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte +47 -0
- package/dist/breadcrumbs/link/breadcrumbs-link.svelte.d.ts +4 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte +31 -0
- package/dist/breadcrumbs/list/breadcrumbs-list.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte +112 -0
- package/dist/breadcrumbs/root/breadcrumbs-root.svelte.d.ts +4 -0
- package/dist/breadcrumbs/root/context.d.ts +19 -0
- package/dist/breadcrumbs/root/context.js +15 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte +35 -0
- package/dist/breadcrumbs/separator/breadcrumbs-separator.svelte.d.ts +4 -0
- package/dist/breadcrumbs/types.d.ts +80 -0
- package/dist/breadcrumbs/types.js +1 -0
- package/dist/button/root/button-root.svelte +9 -0
- package/dist/calendar/body-cell/calendar-body-cell.svelte +7 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte +1 -0
- package/dist/checkbox/indicator/checkbox-indicator.svelte.d.ts +1 -0
- package/dist/checkbox/root/checkbox-root.svelte +106 -30
- package/dist/checkbox/root/checkbox-root.svelte.d.ts +5 -0
- package/dist/checkbox-group/README.md +95 -0
- package/dist/checkbox-group/index.d.ts +15 -0
- package/dist/checkbox-group/index.js +6 -0
- package/dist/checkbox-group/index.parts.d.ts +4 -0
- package/dist/checkbox-group/index.parts.js +7 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte +36 -0
- package/dist/checkbox-group/label/checkbox-group-label.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte +118 -0
- package/dist/checkbox-group/root/checkbox-group-root.svelte.d.ts +4 -0
- package/dist/checkbox-group/root/context.svelte.d.ts +52 -0
- package/dist/checkbox-group/root/context.svelte.js +251 -0
- package/dist/checkbox-group/types.d.ts +57 -0
- package/dist/checkbox-group/types.js +1 -0
- package/dist/combobox/popover/combobox-popover.svelte +4 -56
- package/dist/dialog/root/dialog-root.svelte +15 -2
- package/dist/drawer/root/drawer-root.svelte +15 -2
- package/dist/index.d.ts +18 -0
- package/dist/index.js +17 -0
- package/dist/internal/localized-strings.d.ts +48 -0
- package/dist/internal/localized-strings.js +48 -0
- package/dist/internal/number-precision.d.ts +9 -0
- package/dist/internal/number-precision.js +27 -0
- package/dist/menu/root/focus-state.d.ts +2 -2
- package/dist/menu/root/focus-state.js +8 -32
- package/dist/menu/root/menu-state.svelte.js +5 -1
- package/dist/numberfield/root/number-utils.js +1 -20
- package/dist/popover/root/focus-state.d.ts +2 -2
- package/dist/popover/root/focus-state.js +7 -34
- package/dist/primitives/contain-wheel.d.ts +9 -0
- package/dist/primitives/contain-wheel.js +41 -0
- package/dist/primitives/floating.d.ts +6 -0
- package/dist/primitives/floating.js +26 -5
- package/dist/primitives/focus-visible.svelte.d.ts +14 -0
- package/dist/primitives/focus-visible.svelte.js +19 -0
- package/dist/primitives/index.d.ts +1 -0
- package/dist/primitives/index.js +1 -0
- package/dist/primitives/input-modality.d.ts +7 -0
- package/dist/primitives/input-modality.js +32 -5
- package/dist/primitives/keyboard-navigation.d.ts +6 -0
- package/dist/primitives/keyboard-navigation.js +2 -1
- package/dist/primitives/trigger-focus-state.d.ts +29 -0
- package/dist/primitives/trigger-focus-state.js +57 -0
- package/dist/progress/README.md +54 -0
- package/dist/progress/index.d.ts +21 -0
- package/dist/progress/index.js +9 -0
- package/dist/progress/index.parts.d.ts +5 -0
- package/dist/progress/index.parts.js +5 -0
- package/dist/progress/indicator/progress-indicator.svelte +37 -0
- package/dist/progress/indicator/progress-indicator.svelte.d.ts +4 -0
- package/dist/progress/label/progress-label.svelte +34 -0
- package/dist/progress/label/progress-label.svelte.d.ts +4 -0
- package/dist/progress/root/context.d.ts +26 -0
- package/dist/progress/root/context.js +15 -0
- package/dist/progress/root/progress-root.svelte +136 -0
- package/dist/progress/root/progress-root.svelte.d.ts +4 -0
- package/dist/progress/root/progress-utils.d.ts +12 -0
- package/dist/progress/root/progress-utils.js +41 -0
- package/dist/progress/track/progress-track.svelte +27 -0
- package/dist/progress/track/progress-track.svelte.d.ts +4 -0
- package/dist/progress/types.d.ts +81 -0
- package/dist/progress/types.js +1 -0
- package/dist/progress/value/progress-value.svelte +36 -0
- package/dist/progress/value/progress-value.svelte.d.ts +4 -0
- package/dist/radio-group/README.md +103 -0
- package/dist/radio-group/index.d.ts +18 -0
- package/dist/radio-group/index.js +9 -0
- package/dist/radio-group/index.parts.d.ts +4 -0
- package/dist/radio-group/index.parts.js +4 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte +43 -0
- package/dist/radio-group/indicator/radio-group-indicator.svelte.d.ts +12 -0
- package/dist/radio-group/item/context.d.ts +18 -0
- package/dist/radio-group/item/context.js +15 -0
- package/dist/radio-group/item/radio-group-item.svelte +377 -0
- package/dist/radio-group/item/radio-group-item.svelte.d.ts +35 -0
- package/dist/radio-group/label/radio-group-label.svelte +37 -0
- package/dist/radio-group/label/radio-group-label.svelte.d.ts +4 -0
- package/dist/radio-group/root/context.svelte.d.ts +57 -0
- package/dist/radio-group/root/context.svelte.js +284 -0
- package/dist/radio-group/root/radio-group-root.svelte +193 -0
- package/dist/radio-group/root/radio-group-root.svelte.d.ts +4 -0
- package/dist/radio-group/types.d.ts +50 -0
- package/dist/radio-group/types.js +1 -0
- package/dist/select/README.md +129 -0
- package/dist/select/index.d.ts +30 -0
- package/dist/select/index.js +16 -0
- package/dist/select/index.parts.d.ts +8 -0
- package/dist/select/index.parts.js +9 -0
- package/dist/select/item/select-item.svelte +68 -0
- package/dist/select/item/select-item.svelte.d.ts +10 -0
- package/dist/select/item-indicator/select-item-indicator.svelte +55 -0
- package/dist/select/item-indicator/select-item-indicator.svelte.d.ts +4 -0
- package/dist/select/label/select-label.svelte +46 -0
- package/dist/select/label/select-label.svelte.d.ts +4 -0
- package/dist/select/list/select-list.svelte +241 -0
- package/dist/select/list/select-list.svelte.d.ts +62 -0
- package/dist/select/popover/select-popover.svelte +80 -0
- package/dist/select/popover/select-popover.svelte.d.ts +9 -0
- package/dist/select/root/context.d.ts +106 -0
- package/dist/select/root/context.js +22 -0
- package/dist/select/root/select-root.svelte +544 -0
- package/dist/select/root/select-root.svelte.d.ts +25 -0
- package/dist/select/trigger/select-trigger.svelte +192 -0
- package/dist/select/trigger/select-trigger.svelte.d.ts +4 -0
- package/dist/select/types.d.ts +133 -0
- package/dist/select/types.js +1 -0
- package/dist/select/value/select-value.svelte +61 -0
- package/dist/select/value/select-value.svelte.d.ts +4 -0
- package/dist/separator/README.md +35 -0
- package/dist/separator/index.d.ts +7 -0
- package/dist/separator/index.js +3 -0
- package/dist/separator/separator.svelte +254 -0
- package/dist/separator/separator.svelte.d.ts +45 -0
- package/dist/separator/types.d.ts +1 -0
- package/dist/separator/types.js +1 -0
- package/dist/slider/README.md +61 -0
- package/dist/slider/fill/slider-fill.svelte +40 -0
- package/dist/slider/fill/slider-fill.svelte.d.ts +4 -0
- package/dist/slider/index.d.ts +9 -0
- package/dist/slider/index.js +8 -0
- package/dist/slider/index.parts.d.ts +6 -0
- package/dist/slider/index.parts.js +6 -0
- package/dist/slider/label/slider-label.svelte +44 -0
- package/dist/slider/label/slider-label.svelte.d.ts +4 -0
- package/dist/slider/output/slider-output.svelte +46 -0
- package/dist/slider/output/slider-output.svelte.d.ts +4 -0
- package/dist/slider/root/context.d.ts +106 -0
- package/dist/slider/root/context.js +15 -0
- package/dist/slider/root/slider-root.svelte +545 -0
- package/dist/slider/root/slider-root.svelte.d.ts +4 -0
- package/dist/slider/root/slider-utils.d.ts +57 -0
- package/dist/slider/root/slider-utils.js +88 -0
- package/dist/slider/thumb/slider-thumb.svelte +276 -0
- package/dist/slider/thumb/slider-thumb.svelte.d.ts +4 -0
- package/dist/slider/track/slider-track.svelte +60 -0
- package/dist/slider/track/slider-track.svelte.d.ts +4 -0
- package/dist/slider/types.d.ts +144 -0
- package/dist/slider/types.js +1 -0
- package/dist/switch/root/switch-root.svelte +9 -0
- package/dist/table/column-header-cell/table-column-header-cell.svelte +24 -0
- package/dist/table/root/table-root.svelte +29 -6
- package/dist/timepicker/input/time-picker-input.svelte +12 -4
- package/dist/timepicker/input/time-picker-input.svelte.d.ts +12 -4
- package/dist/toggle/root/toggle-root.svelte +28 -0
- package/dist/toggle/root/toggle-root.svelte.d.ts +19 -0
- package/dist/toggle-group/README.md +6 -4
- package/dist/toggle-group/index.d.ts +2 -0
- package/dist/toggle-group/index.parts.d.ts +1 -0
- package/dist/toggle-group/index.parts.js +4 -0
- package/dist/tooltip/README.md +53 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte +36 -0
- package/dist/tooltip/arrow/tooltip-arrow.svelte.d.ts +4 -0
- package/dist/tooltip/content/tooltip-content.svelte +148 -0
- package/dist/tooltip/content/tooltip-content.svelte.d.ts +4 -0
- package/dist/tooltip/index.d.ts +8 -0
- package/dist/tooltip/index.js +7 -0
- package/dist/tooltip/index.parts.d.ts +5 -0
- package/dist/tooltip/index.parts.js +5 -0
- package/dist/tooltip/provider/tooltip-provider.svelte +36 -0
- package/dist/tooltip/provider/tooltip-provider.svelte.d.ts +4 -0
- package/dist/tooltip/root/context.d.ts +46 -0
- package/dist/tooltip/root/context.js +22 -0
- package/dist/tooltip/root/safe-polygon.d.ts +26 -0
- package/dist/tooltip/root/safe-polygon.js +66 -0
- package/dist/tooltip/root/tooltip-group.d.ts +26 -0
- package/dist/tooltip/root/tooltip-group.js +41 -0
- package/dist/tooltip/root/tooltip-root.svelte +454 -0
- package/dist/tooltip/root/tooltip-root.svelte.d.ts +4 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte +52 -0
- package/dist/tooltip/trigger/tooltip-trigger.svelte.d.ts +4 -0
- package/dist/tooltip/types.d.ts +105 -0
- package/dist/tooltip/types.js +1 -0
- package/package.json +46 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { getContext, setContext, untrack } from 'svelte';
|
|
2
|
+
import { SvelteMap } from 'svelte/reactivity';
|
|
3
|
+
import { asCommand } from '../../internal/as-command.js';
|
|
4
|
+
const RADIO_GROUP_CONTEXT_KEY = Symbol('radio-group');
|
|
5
|
+
export function createRadioGroupContext(options) {
|
|
6
|
+
let name = $state(options.name);
|
|
7
|
+
let form = $state(options.form);
|
|
8
|
+
let isDisabled = $state(options.isDisabled ?? false);
|
|
9
|
+
let isReadOnly = $state(options.isReadOnly ?? false);
|
|
10
|
+
let isRequired = $state(options.isRequired ?? false);
|
|
11
|
+
let orientation = $state(options.orientation ?? 'vertical');
|
|
12
|
+
let labelIds = $state([]);
|
|
13
|
+
let selectedValue = $state(options.initialValue ?? null);
|
|
14
|
+
let focusedValue = $state(null);
|
|
15
|
+
let focusVisible = $state(false);
|
|
16
|
+
// Whether the selected radio left the tree. It parts the two ways a selected value can have
|
|
17
|
+
// no registration: on the server, and on the first client render, the radios register one by
|
|
18
|
+
// one, so the selected one is simply not there yet and must keep the tab stop. Once it has
|
|
19
|
+
// been removed, the group has to give the tab stop to somebody else, or Tab skips it.
|
|
20
|
+
let selectionDetached = $state(false);
|
|
21
|
+
const radios = new SvelteMap();
|
|
22
|
+
const radioOrder = $state([]);
|
|
23
|
+
function getOrderedValues() {
|
|
24
|
+
const connected = [];
|
|
25
|
+
const detachedValues = [];
|
|
26
|
+
for (const value of radioOrder) {
|
|
27
|
+
const element = radios.get(value)?.element;
|
|
28
|
+
if (element?.isConnected) {
|
|
29
|
+
connected.push({ value, element });
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
detachedValues.push(value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
connected.sort((left, right) => left.element.compareDocumentPosition(right.element) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
36
|
+
? -1
|
|
37
|
+
: 1);
|
|
38
|
+
return [...connected.map((entry) => entry.value), ...detachedValues];
|
|
39
|
+
}
|
|
40
|
+
function getEnabledValues() {
|
|
41
|
+
return getOrderedValues().filter((value) => radios.has(value) && !isRadioDisabled(value));
|
|
42
|
+
}
|
|
43
|
+
function getFirstEnabledValue() {
|
|
44
|
+
return getEnabledValues()[0] ?? null;
|
|
45
|
+
}
|
|
46
|
+
function getLastEnabledValue() {
|
|
47
|
+
const enabledValues = getEnabledValues();
|
|
48
|
+
return enabledValues[enabledValues.length - 1] ?? null;
|
|
49
|
+
}
|
|
50
|
+
function getNextEnabledValue(current, direction) {
|
|
51
|
+
const enabledValues = getEnabledValues();
|
|
52
|
+
if (enabledValues.length === 0)
|
|
53
|
+
return null;
|
|
54
|
+
if (current === null) {
|
|
55
|
+
return direction === 1 ? enabledValues[0] : enabledValues[enabledValues.length - 1];
|
|
56
|
+
}
|
|
57
|
+
const currentIndex = enabledValues.indexOf(current);
|
|
58
|
+
if (currentIndex < 0) {
|
|
59
|
+
return direction === 1 ? enabledValues[0] : enabledValues[enabledValues.length - 1];
|
|
60
|
+
}
|
|
61
|
+
// Wraps at both ends, which the APG asks for by name.
|
|
62
|
+
return (enabledValues[(currentIndex + direction + enabledValues.length) % enabledValues.length] ??
|
|
63
|
+
null);
|
|
64
|
+
}
|
|
65
|
+
// The single tab stop of the group. The APG puts it on the checked radio, and on the first
|
|
66
|
+
// enabled one while nothing is checked, so that Tab enters the group where the user left it.
|
|
67
|
+
function getTabStopValue() {
|
|
68
|
+
if (selectedValue !== null && !isRadioDisabled(selectedValue) && !selectionDetached) {
|
|
69
|
+
return selectedValue;
|
|
70
|
+
}
|
|
71
|
+
if (focusedValue !== null && !isRadioDisabled(focusedValue))
|
|
72
|
+
return focusedValue;
|
|
73
|
+
return getFirstEnabledValue();
|
|
74
|
+
}
|
|
75
|
+
function setSelection(next, changeOptions) {
|
|
76
|
+
if (selectedValue === next)
|
|
77
|
+
return false;
|
|
78
|
+
selectedValue = next;
|
|
79
|
+
selectionDetached = next !== null && !radios.has(next) && radioOrder.length > 0;
|
|
80
|
+
if (changeOptions?.notify !== false && next !== null) {
|
|
81
|
+
options.onValueChange?.(next);
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
function registerRadio(value, registerOptions) {
|
|
86
|
+
const existingRadio = radios.get(value);
|
|
87
|
+
if (existingRadio !== undefined &&
|
|
88
|
+
existingRadio.owner !== undefined &&
|
|
89
|
+
registerOptions.owner !== undefined &&
|
|
90
|
+
existingRadio.owner !== registerOptions.owner) {
|
|
91
|
+
throw new Error('RadioGroup.Item values must be unique within a RadioGroup.Root.');
|
|
92
|
+
}
|
|
93
|
+
radios.set(value, {
|
|
94
|
+
value,
|
|
95
|
+
isDisabled: Boolean(registerOptions.isDisabled),
|
|
96
|
+
element: registerOptions.element,
|
|
97
|
+
owner: registerOptions.owner
|
|
98
|
+
});
|
|
99
|
+
if (existingRadio === undefined) {
|
|
100
|
+
radioOrder.push(value);
|
|
101
|
+
}
|
|
102
|
+
if (selectedValue === value) {
|
|
103
|
+
selectionDetached = false;
|
|
104
|
+
}
|
|
105
|
+
if (focusedValue !== null && focusedValue === value && isRadioDisabled(value)) {
|
|
106
|
+
focusedValue = null;
|
|
107
|
+
focusVisible = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function unregisterRadio(value) {
|
|
111
|
+
if (!radios.has(value))
|
|
112
|
+
return;
|
|
113
|
+
radios.delete(value);
|
|
114
|
+
const index = radioOrder.indexOf(value);
|
|
115
|
+
if (index >= 0) {
|
|
116
|
+
radioOrder.splice(index, 1);
|
|
117
|
+
}
|
|
118
|
+
if (focusedValue === value) {
|
|
119
|
+
focusedValue = null;
|
|
120
|
+
}
|
|
121
|
+
if (selectedValue === value) {
|
|
122
|
+
selectionDetached = true;
|
|
123
|
+
}
|
|
124
|
+
// The selection survives on purpose, live or not. A radio that leaves the tree takes its
|
|
125
|
+
// hidden input with it, so the form stops submitting that answer, which is what a native
|
|
126
|
+
// radio group does. Clearing the value on top of that would rewrite the state of a parent
|
|
127
|
+
// that still holds it, and the answer would be lost for good if the radio came back.
|
|
128
|
+
}
|
|
129
|
+
function setName(nextName) {
|
|
130
|
+
if (name === nextName)
|
|
131
|
+
return;
|
|
132
|
+
name = nextName;
|
|
133
|
+
}
|
|
134
|
+
function setForm(nextForm) {
|
|
135
|
+
if (form === nextForm)
|
|
136
|
+
return;
|
|
137
|
+
form = nextForm;
|
|
138
|
+
}
|
|
139
|
+
function setDisabled(disabled) {
|
|
140
|
+
if (isDisabled === disabled)
|
|
141
|
+
return;
|
|
142
|
+
isDisabled = disabled;
|
|
143
|
+
if (isDisabled) {
|
|
144
|
+
focusedValue = null;
|
|
145
|
+
focusVisible = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function setReadOnly(readonly) {
|
|
149
|
+
if (isReadOnly === readonly)
|
|
150
|
+
return;
|
|
151
|
+
isReadOnly = readonly;
|
|
152
|
+
}
|
|
153
|
+
function setRequired(required) {
|
|
154
|
+
if (isRequired === required)
|
|
155
|
+
return;
|
|
156
|
+
isRequired = required;
|
|
157
|
+
}
|
|
158
|
+
function setOrientation(nextOrientation) {
|
|
159
|
+
if (orientation === nextOrientation)
|
|
160
|
+
return;
|
|
161
|
+
orientation = nextOrientation;
|
|
162
|
+
}
|
|
163
|
+
function setSelectedValue(value) {
|
|
164
|
+
setSelection(value ?? null, { notify: false });
|
|
165
|
+
}
|
|
166
|
+
// There is no unselecting: a radio group answers a question, and the platform gives the user
|
|
167
|
+
// no way to take the answer back. Thus this only ever sets.
|
|
168
|
+
function selectValue(value) {
|
|
169
|
+
if (isRadioDisabled(value) || isReadOnly)
|
|
170
|
+
return false;
|
|
171
|
+
return setSelection(value);
|
|
172
|
+
}
|
|
173
|
+
function setFocusedValue(value) {
|
|
174
|
+
if (focusedValue === value)
|
|
175
|
+
return;
|
|
176
|
+
focusedValue = value;
|
|
177
|
+
}
|
|
178
|
+
function focusValue(value) {
|
|
179
|
+
if (isRadioDisabled(value))
|
|
180
|
+
return;
|
|
181
|
+
setFocusedValue(value);
|
|
182
|
+
radios.get(value)?.element?.focus();
|
|
183
|
+
}
|
|
184
|
+
function setFocusVisible(visible) {
|
|
185
|
+
if (focusVisible === visible)
|
|
186
|
+
return;
|
|
187
|
+
focusVisible = visible;
|
|
188
|
+
}
|
|
189
|
+
function isSelected(value) {
|
|
190
|
+
return selectedValue === value;
|
|
191
|
+
}
|
|
192
|
+
function isFocused(value) {
|
|
193
|
+
return focusedValue === value;
|
|
194
|
+
}
|
|
195
|
+
function isFocusVisible(value) {
|
|
196
|
+
return focusVisible && isFocused(value);
|
|
197
|
+
}
|
|
198
|
+
function isRadioDisabled(value) {
|
|
199
|
+
return isDisabled || Boolean(radios.get(value)?.isDisabled);
|
|
200
|
+
}
|
|
201
|
+
function isRegisteredElement(element) {
|
|
202
|
+
return radioOrder.some((value) => radios.get(value)?.element === element);
|
|
203
|
+
}
|
|
204
|
+
function getTabIndex(value) {
|
|
205
|
+
if (isRadioDisabled(value))
|
|
206
|
+
return -1;
|
|
207
|
+
return getTabStopValue() === value ? 0 : -1;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
get name() {
|
|
211
|
+
return name;
|
|
212
|
+
},
|
|
213
|
+
get form() {
|
|
214
|
+
return form;
|
|
215
|
+
},
|
|
216
|
+
get isDisabled() {
|
|
217
|
+
return isDisabled;
|
|
218
|
+
},
|
|
219
|
+
get isReadOnly() {
|
|
220
|
+
return isReadOnly;
|
|
221
|
+
},
|
|
222
|
+
get isRequired() {
|
|
223
|
+
return isRequired;
|
|
224
|
+
},
|
|
225
|
+
get labelledBy() {
|
|
226
|
+
return labelIds.length > 0 ? labelIds.join(' ') : undefined;
|
|
227
|
+
},
|
|
228
|
+
get orientation() {
|
|
229
|
+
return orientation;
|
|
230
|
+
},
|
|
231
|
+
get selectedValue() {
|
|
232
|
+
return selectedValue;
|
|
233
|
+
},
|
|
234
|
+
get focusedValue() {
|
|
235
|
+
return focusedValue;
|
|
236
|
+
},
|
|
237
|
+
registerRadio: asCommand(registerRadio),
|
|
238
|
+
unregisterRadio: asCommand(unregisterRadio),
|
|
239
|
+
setName: asCommand(setName),
|
|
240
|
+
setForm: asCommand(setForm),
|
|
241
|
+
setDisabled: asCommand(setDisabled),
|
|
242
|
+
setReadOnly: asCommand(setReadOnly),
|
|
243
|
+
setRequired: asCommand(setRequired),
|
|
244
|
+
setOrientation: asCommand(setOrientation),
|
|
245
|
+
setSelectedValue: asCommand(setSelectedValue),
|
|
246
|
+
selectValue: asCommand(selectValue),
|
|
247
|
+
setFocusedValue: asCommand(setFocusedValue),
|
|
248
|
+
focusValue: asCommand(focusValue),
|
|
249
|
+
setFocusVisible: asCommand(setFocusVisible),
|
|
250
|
+
// `untrack` because the caller registers from an effect: reading `labelIds` here would
|
|
251
|
+
// make that effect depend on what it writes, and the pair would run without end.
|
|
252
|
+
registerLabel(id) {
|
|
253
|
+
untrack(() => {
|
|
254
|
+
labelIds = [...labelIds, id];
|
|
255
|
+
});
|
|
256
|
+
return () => untrack(() => {
|
|
257
|
+
labelIds = labelIds.filter((candidate) => candidate !== id);
|
|
258
|
+
});
|
|
259
|
+
},
|
|
260
|
+
isSelected,
|
|
261
|
+
isFocused,
|
|
262
|
+
isFocusVisible,
|
|
263
|
+
isRadioDisabled,
|
|
264
|
+
isRegisteredElement,
|
|
265
|
+
getTabIndex,
|
|
266
|
+
getEnabledValues,
|
|
267
|
+
getNextEnabledValue,
|
|
268
|
+
getFirstEnabledValue,
|
|
269
|
+
getLastEnabledValue
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
export function setRadioGroupContext(context) {
|
|
273
|
+
return setContext(RADIO_GROUP_CONTEXT_KEY, context);
|
|
274
|
+
}
|
|
275
|
+
export function getRadioGroupContext() {
|
|
276
|
+
return getContext(RADIO_GROUP_CONTEXT_KEY);
|
|
277
|
+
}
|
|
278
|
+
export function useRadioGroupContext() {
|
|
279
|
+
const context = getRadioGroupContext();
|
|
280
|
+
if (!context) {
|
|
281
|
+
throw new Error('RadioGroup.Item must be used within RadioGroup.Root.');
|
|
282
|
+
}
|
|
283
|
+
return context;
|
|
284
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import type { RadioGroupRootProps } from '../types.js';
|
|
4
|
+
import { createRadioGroupContext, setRadioGroupContext } from './context.svelte';
|
|
5
|
+
import { trackInteractionModality } from '../../primitives/input-modality';
|
|
6
|
+
import { isRtl } from '../../internal/rtl';
|
|
7
|
+
|
|
8
|
+
type RadioGroupKeyboardEvent = KeyboardEvent & {
|
|
9
|
+
currentTarget: EventTarget & HTMLDivElement;
|
|
10
|
+
};
|
|
11
|
+
type RadioGroupMouseEvent = MouseEvent & {
|
|
12
|
+
currentTarget: EventTarget & HTMLDivElement;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const generatedId = $props.id();
|
|
16
|
+
|
|
17
|
+
let {
|
|
18
|
+
id,
|
|
19
|
+
value = $bindable(),
|
|
20
|
+
defaultValue,
|
|
21
|
+
onChange,
|
|
22
|
+
name,
|
|
23
|
+
form,
|
|
24
|
+
disabled: disabledProp = false,
|
|
25
|
+
readonly: readOnlyProp = false,
|
|
26
|
+
required: requiredProp = false,
|
|
27
|
+
orientation = 'vertical',
|
|
28
|
+
children,
|
|
29
|
+
class: className = '',
|
|
30
|
+
element = $bindable<HTMLDivElement | null>(null),
|
|
31
|
+
context = $bindable(),
|
|
32
|
+
onkeydown: onKeyDownExternal,
|
|
33
|
+
onmousedown: onMouseDownExternal,
|
|
34
|
+
'aria-labelledby': ariaLabelledBy,
|
|
35
|
+
...restProps
|
|
36
|
+
}: RadioGroupRootProps = $props();
|
|
37
|
+
|
|
38
|
+
const instanceId = untrack(() => id) ?? generatedId;
|
|
39
|
+
|
|
40
|
+
let rootRef: HTMLDivElement | null = $state(null);
|
|
41
|
+
|
|
42
|
+
const radioGroup = setRadioGroupContext(
|
|
43
|
+
createRadioGroupContext({
|
|
44
|
+
// `value` seeds the initial selection whenever it is supplied, bound or not.
|
|
45
|
+
initialValue: untrack(() => value) ?? untrack(() => defaultValue),
|
|
46
|
+
name: (() => name)(),
|
|
47
|
+
form: (() => form)(),
|
|
48
|
+
isDisabled: (() => disabledProp)(),
|
|
49
|
+
isReadOnly: (() => readOnlyProp)(),
|
|
50
|
+
isRequired: (() => requiredProp)(),
|
|
51
|
+
orientation: (() => orientation)(),
|
|
52
|
+
onValueChange: (nextValue) => {
|
|
53
|
+
// One path for both usages: with `bind:value` this reaches the parent, and without a
|
|
54
|
+
// binding the write stays local, so nothing here has to know which one the caller chose.
|
|
55
|
+
value = nextValue;
|
|
56
|
+
onChange?.(nextValue);
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
context = radioGroup;
|
|
62
|
+
|
|
63
|
+
const disabled = $derived(radioGroup.isDisabled);
|
|
64
|
+
const readOnly = $derived(radioGroup.isReadOnly);
|
|
65
|
+
const required = $derived(radioGroup.isRequired);
|
|
66
|
+
const currentOrientation = $derived(radioGroup.orientation);
|
|
67
|
+
|
|
68
|
+
$effect(() => {
|
|
69
|
+
element = rootRef;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
$effect(() => {
|
|
73
|
+
radioGroup.setName(name);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
$effect(() => {
|
|
77
|
+
radioGroup.setForm(form);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
$effect(() => {
|
|
81
|
+
radioGroup.setDisabled(disabledProp);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
$effect(() => {
|
|
85
|
+
radioGroup.setReadOnly(readOnlyProp);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
$effect(() => {
|
|
89
|
+
radioGroup.setRequired(requiredProp);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
$effect(() => {
|
|
93
|
+
radioGroup.setOrientation(orientation);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// A parent that supplies `value` drives the selection, bound or not. Latched at init, not
|
|
97
|
+
// reactive — re-checking `value !== undefined` would switch this on the moment our own
|
|
98
|
+
// write-back defines it, and a `defaultValue`-only group would start following the echo of
|
|
99
|
+
// its own changes.
|
|
100
|
+
const adoptsValueProp = untrack(() => value !== undefined);
|
|
101
|
+
|
|
102
|
+
$effect(() => {
|
|
103
|
+
if (!adoptsValueProp) return;
|
|
104
|
+
radioGroup.setSelectedValue(value);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function getEventRadioTarget(event: KeyboardEvent | MouseEvent) {
|
|
108
|
+
const target = event.target;
|
|
109
|
+
if (!(target instanceof Element)) return target;
|
|
110
|
+
return target.closest('[data-radio-group-item="true"]') ?? target;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// The selection follows the focus, which is the rule that parts a radio group from every other
|
|
114
|
+
// group in this library: the arrows do not only move, they answer the question.
|
|
115
|
+
function moveSelection(nextValue: string | null) {
|
|
116
|
+
if (nextValue === null) return;
|
|
117
|
+
radioGroup.setFocusVisible(true);
|
|
118
|
+
radioGroup.focusValue(nextValue);
|
|
119
|
+
radioGroup.selectValue(nextValue);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function handleKeyDown(event: RadioGroupKeyboardEvent) {
|
|
123
|
+
onKeyDownExternal?.(event);
|
|
124
|
+
if (event.defaultPrevented) return;
|
|
125
|
+
|
|
126
|
+
const radioTarget = getEventRadioTarget(event);
|
|
127
|
+
if (!radioGroup.isRegisteredElement(radioTarget)) return;
|
|
128
|
+
|
|
129
|
+
trackInteractionModality(event, radioTarget as HTMLElement | null);
|
|
130
|
+
|
|
131
|
+
if (radioGroup.isDisabled) return;
|
|
132
|
+
|
|
133
|
+
const currentValue = radioGroup.focusedValue ?? radioGroup.selectedValue;
|
|
134
|
+
// In horizontal orientation the arrows are physical: under RTL the visual "next" radio is
|
|
135
|
+
// the previous one in DOM order (APG). Both axes work in either orientation, which is what
|
|
136
|
+
// the APG describes and what a native radio group does.
|
|
137
|
+
const rtl = isRtl(event.currentTarget);
|
|
138
|
+
const nextKeys = ['ArrowDown', rtl ? 'ArrowLeft' : 'ArrowRight'];
|
|
139
|
+
const previousKeys = ['ArrowUp', rtl ? 'ArrowRight' : 'ArrowLeft'];
|
|
140
|
+
|
|
141
|
+
if (nextKeys.includes(event.key)) {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
moveSelection(radioGroup.getNextEnabledValue(currentValue, 1));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (previousKeys.includes(event.key)) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
moveSelection(radioGroup.getNextEnabledValue(currentValue, -1));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (event.key === 'Home') {
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
moveSelection(radioGroup.getFirstEnabledValue());
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (event.key === 'End') {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
moveSelection(radioGroup.getLastEnabledValue());
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function handleMouseDown(event: RadioGroupMouseEvent) {
|
|
166
|
+
const radioTarget = getEventRadioTarget(event);
|
|
167
|
+
trackInteractionModality(event, radioTarget as HTMLElement | null);
|
|
168
|
+
radioGroup.setFocusVisible(false);
|
|
169
|
+
onMouseDownExternal?.(event);
|
|
170
|
+
}
|
|
171
|
+
</script>
|
|
172
|
+
|
|
173
|
+
<div
|
|
174
|
+
{...restProps}
|
|
175
|
+
bind:this={rootRef}
|
|
176
|
+
id={instanceId}
|
|
177
|
+
role="radiogroup"
|
|
178
|
+
aria-labelledby={ariaLabelledBy ?? radioGroup.labelledBy}
|
|
179
|
+
aria-orientation={currentOrientation}
|
|
180
|
+
aria-required={required || undefined}
|
|
181
|
+
aria-disabled={disabled || undefined}
|
|
182
|
+
aria-readonly={readOnly || undefined}
|
|
183
|
+
class={className}
|
|
184
|
+
data-radio-group-root="true"
|
|
185
|
+
data-orientation={currentOrientation}
|
|
186
|
+
data-disabled={disabled || undefined}
|
|
187
|
+
data-readonly={readOnly || undefined}
|
|
188
|
+
data-required={required || undefined}
|
|
189
|
+
onkeydown={handleKeyDown}
|
|
190
|
+
onmousedown={handleMouseDown}
|
|
191
|
+
>
|
|
192
|
+
{@render children?.()}
|
|
193
|
+
</div>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { RadioGroupContext, RadioGroupOrientation, RadioGroupValue } from './root/context.svelte.js';
|
|
4
|
+
export type { RadioGroupContext, RadioGroupOrientation, RadioGroupValue } from './root/context.svelte.js';
|
|
5
|
+
export type RadioGroupRootProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role' | 'aria-orientation'> & {
|
|
6
|
+
/**
|
|
7
|
+
* The selected value. When you give this prop, it is the source of truth, with `bind:value` or
|
|
8
|
+
* without it. The component writes each change here and reports it through `onChange`.
|
|
9
|
+
*
|
|
10
|
+
* Without a binding, that write stays local. Thus a parent that hears `onChange` and refuses the
|
|
11
|
+
* change — it sends no new `value` down — sees the group move. The group then goes back to the
|
|
12
|
+
* value of the parent at the next render.
|
|
13
|
+
*/
|
|
14
|
+
value?: RadioGroupValue | null;
|
|
15
|
+
/** The selected value at the start, for when you give no `value`. */
|
|
16
|
+
defaultValue?: RadioGroupValue | null;
|
|
17
|
+
/** The component calls it when the user selects a radio. */
|
|
18
|
+
onChange?: (value: RadioGroupValue) => void;
|
|
19
|
+
/** The `name` of the hidden input of every radio in the group, for form submission. */
|
|
20
|
+
name?: string;
|
|
21
|
+
/** The id of the form of the hidden inputs. */
|
|
22
|
+
form?: string;
|
|
23
|
+
/** Disables each radio in the group. */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** Shows the value of the group, and refuses each change from the user. */
|
|
26
|
+
readonly?: boolean;
|
|
27
|
+
/** Marks the group with `aria-required`, and marks each hidden input as required. */
|
|
28
|
+
required?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The orientation of the layout. It sets `aria-orientation` and `data-orientation`, and it
|
|
31
|
+
* chooses the arrow keys that move the focus.
|
|
32
|
+
*/
|
|
33
|
+
orientation?: RadioGroupOrientation;
|
|
34
|
+
/** The radios of the group. */
|
|
35
|
+
children?: Snippet;
|
|
36
|
+
class?: string;
|
|
37
|
+
/** The id of the group element. The component makes one when you give none. */
|
|
38
|
+
id?: string;
|
|
39
|
+
/** The group element. Use `bind:element` to read it. */
|
|
40
|
+
element?: HTMLDivElement | null;
|
|
41
|
+
/** The state of the group. Use `bind:context` to read the selection from outside. */
|
|
42
|
+
context?: RadioGroupContext;
|
|
43
|
+
};
|
|
44
|
+
export type RadioGroupLabelProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'class' | 'id'> & {
|
|
45
|
+
/** The name of the group. */
|
|
46
|
+
children?: Snippet;
|
|
47
|
+
class?: string;
|
|
48
|
+
/** The id of the label element. The component makes one when you give none. */
|
|
49
|
+
id?: string;
|
|
50
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Select
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`Select` is a form field with one value from a list of options. The user opens the list from a
|
|
6
|
+
button, and the list is a `ListBox` in a popover. It has the keyboard of the WAI-ARIA select-only
|
|
7
|
+
combobox and a native control for the form. The field and its value have one name in the
|
|
8
|
+
accessibility tree.
|
|
9
|
+
|
|
10
|
+
## Anatomy
|
|
11
|
+
|
|
12
|
+
- `Select.Root`
|
|
13
|
+
- `Select.Label`
|
|
14
|
+
- `Select.Trigger`
|
|
15
|
+
- `Select.Value`
|
|
16
|
+
- `Select.Popover`
|
|
17
|
+
- `Select.List`
|
|
18
|
+
- `Select.Item`
|
|
19
|
+
- `Select.ItemIndicator`
|
|
20
|
+
|
|
21
|
+
```svelte
|
|
22
|
+
<Select.Root name="fruit" defaultValue="apple">
|
|
23
|
+
<Select.Label>Fruit</Select.Label>
|
|
24
|
+
<Select.Trigger>
|
|
25
|
+
<Select.Value />
|
|
26
|
+
</Select.Trigger>
|
|
27
|
+
<Select.Popover>
|
|
28
|
+
<Select.List>
|
|
29
|
+
<Select.Item id="apple">Apple <Select.ItemIndicator /></Select.Item>
|
|
30
|
+
<Select.Item id="banana">Banana <Select.ItemIndicator /></Select.Item>
|
|
31
|
+
</Select.List>
|
|
32
|
+
</Select.Popover>
|
|
33
|
+
</Select.Root>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage guidelines
|
|
37
|
+
|
|
38
|
+
- Use `bind:value` to hand the root your state. Use `value` with `onChange` and `controlledValue`
|
|
39
|
+
to hold the state yourself and refuse a change.
|
|
40
|
+
- Give `items` to `Select.Root` when the field starts with a value. The options are not in the DOM
|
|
41
|
+
while the popover is closed, thus the trigger reads the text of the value from `items`. Without
|
|
42
|
+
it, the trigger shows the key until the popover opens one time.
|
|
43
|
+
- Give the root a `name` to send the value with a form. The root makes a native `<select>` that
|
|
44
|
+
the form reads, and that the browser autofill writes to.
|
|
45
|
+
- Set `selectionMode="multiple"` for more than one value. The popover then stays open after a
|
|
46
|
+
selection, and `value` is an array.
|
|
47
|
+
- Put `Select.Value` inside `Select.Trigger`. The trigger then shows the selection, and the value
|
|
48
|
+
is part of the accessible name of the field.
|
|
49
|
+
|
|
50
|
+
## API reference
|
|
51
|
+
|
|
52
|
+
`Select.Root` supports:
|
|
53
|
+
|
|
54
|
+
- `value?: SelectKey | null | SelectKey[]`
|
|
55
|
+
- `defaultValue?: SelectKey | null | SelectKey[]`
|
|
56
|
+
- `controlledValue?: boolean`
|
|
57
|
+
- `onChange?: (value) => void`
|
|
58
|
+
- `open?: boolean`, `defaultOpen?: boolean`, `controlledOpen?: boolean`
|
|
59
|
+
- `onOpenChange?: (open, details) => void`
|
|
60
|
+
- `selectionMode?: 'single' | 'multiple'`
|
|
61
|
+
- `closeOnSelect?: boolean`
|
|
62
|
+
- `disabledKeys?: Iterable<SelectKey>`
|
|
63
|
+
- `loop?: boolean`
|
|
64
|
+
- `disabled?`, `readonly?`, `required?`, `invalid?: boolean`
|
|
65
|
+
- `name?`, `form?`, `autocomplete?: string`
|
|
66
|
+
- `items?: T[]`
|
|
67
|
+
- `placeholder?: string`
|
|
68
|
+
- `aria-label?`, `aria-labelledby?`, `aria-describedby?: string`
|
|
69
|
+
- `context?: SelectContext`, `element?: HTMLDivElement`
|
|
70
|
+
- `...restProps: HTMLAttributes<HTMLDivElement>`
|
|
71
|
+
|
|
72
|
+
`Select.Trigger` is a `Button.Root` with `role="combobox"`. Its `children` snippet receives
|
|
73
|
+
`{ open, placeholder, disabled }`.
|
|
74
|
+
|
|
75
|
+
`Select.Value` shows the text of the selection, or the placeholder. Its `children` snippet
|
|
76
|
+
receives `{ value, label, placeholder }`.
|
|
77
|
+
|
|
78
|
+
`Select.Popover` takes the props of `Popover.Content`. `Select.List` takes the props of
|
|
79
|
+
`ListBox.Root`, and `Select.Item` the props of `ListBox.Item`. `Select.ItemIndicator` supports
|
|
80
|
+
`forceMount`.
|
|
81
|
+
|
|
82
|
+
## Accessibility
|
|
83
|
+
|
|
84
|
+
- `Select.Trigger` is a native `<button>` with `role="combobox"`, `aria-haspopup="listbox"`,
|
|
85
|
+
`aria-expanded`, and `aria-controls` while the list is open. This is what a native select is in
|
|
86
|
+
the accessibility tree.
|
|
87
|
+
- The name of the trigger is `Select.Label` and `Select.Value`, in that order: a screen reader
|
|
88
|
+
announces "Fruit, Apple, combo box". An `aria-labelledby` on the root replaces the label, and an
|
|
89
|
+
`aria-label` on the root is read in its place.
|
|
90
|
+
- `Select.Label` is a native `<label for>` the trigger. A click on it moves the focus to the
|
|
91
|
+
trigger. It does not open the list, the same as the label of a native select.
|
|
92
|
+
- `Select.List` has `role="listbox"` with `aria-labelledby` the trigger, and each option has
|
|
93
|
+
`aria-selected`. The list gets the DOM focus when the popover opens, on the selected option.
|
|
94
|
+
- `aria-required`, `aria-readonly` and `aria-invalid` are on the combobox, which supports all
|
|
95
|
+
three.
|
|
96
|
+
- The popover is not a dialog: it has `role="presentation"`, and the listbox is what assistive
|
|
97
|
+
technology lands on.
|
|
98
|
+
- On the closed trigger: `ArrowDown`, `Enter`, `Space` and `Alt+ArrowDown` open the list on the
|
|
99
|
+
selection. `ArrowUp` opens it on the selection, or on the last option. `Home` and `End` open
|
|
100
|
+
it on the first and on the last option. A printable character opens it on the first option
|
|
101
|
+
that starts with that character.
|
|
102
|
+
- In the open list: the arrows move the focus, `Home` and `End` jump to the bounds, `PageUp` and
|
|
103
|
+
`PageDown` move ten options, typed characters search. `Enter`, `Space` and `Alt+ArrowUp` select the
|
|
104
|
+
option and close the list. `Escape` closes it without a change. `Tab` closes it and moves the
|
|
105
|
+
focus past the trigger.
|
|
106
|
+
- The focus returns to the trigger after `Escape`, after a selection, and after a close by code.
|
|
107
|
+
After an outside press, a scroll or a `Tab`, it stays where the user put it. An outside press
|
|
108
|
+
on nothing focusable is the exception: the focus goes back to the trigger, thus the keyboard
|
|
109
|
+
can open the list again.
|
|
110
|
+
- The native control is out of the tab order and hidden from assistive technology. A form that
|
|
111
|
+
reports the validity of a `required` select focuses that control, and the root moves the focus
|
|
112
|
+
to the trigger.
|
|
113
|
+
|
|
114
|
+
## Notes
|
|
115
|
+
|
|
116
|
+
- The focus state follows `FOCUS_STATE_CONTRACT.md`. The root shows `data-focus-within` and
|
|
117
|
+
`data-focus-visible` for the trigger and the list together, and the trigger shows `data-focused`
|
|
118
|
+
and `data-focus-visible` from `Button.Root`.
|
|
119
|
+
- A second press on the selected option changes nothing, and the popover closes, the same as a
|
|
120
|
+
native select. In the multiple mode a press toggles.
|
|
121
|
+
- `onOpenChange` receives the reason of each change: `trigger-press`, `item-select`, `escape-key`,
|
|
122
|
+
`outside-press`, `focus-out`, `scroll` or `imperative-action`. A press on the trigger reports
|
|
123
|
+
`trigger-press` for the open and for the close. `details.cancel()` refuses it.
|
|
124
|
+
- The ids of `Select.Label` and `Select.Value` reach the trigger through the context, and the
|
|
125
|
+
server cannot do that: `aria-labelledby` appears at hydration. Give `aria-label` on the root as
|
|
126
|
+
well when the name must be there on the first paint.
|
|
127
|
+
- `Select.Trigger` shows `data-state`, `data-placeholder`, `data-readonly`, `data-required` and
|
|
128
|
+
`data-invalid`. `Select.Value` shows `data-placeholder`. `Select.Item` shows the attributes of
|
|
129
|
+
`ListBox.Item`.
|