@barqjs/aria 0.0.0-stage → 0.2.0-next.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/LICENSE +21 -0
- package/README.md +304 -2
- package/package.json +437 -4
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +297 -0
- package/src/button.tsx +468 -0
- package/src/calendar.tsx +2316 -0
- package/src/checkbox.tsx +732 -0
- package/src/collections.ts +1059 -0
- package/src/color.ts +2119 -0
- package/src/colorpicker.tsx +2023 -0
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +3003 -0
- package/src/command.tsx +1203 -0
- package/src/date.ts +674 -0
- package/src/datefield.tsx +2066 -0
- package/src/datepicker.tsx +907 -0
- package/src/dialog.tsx +1077 -0
- package/src/disclosure.tsx +711 -0
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +703 -0
- package/src/drag-and-drop.tsx +669 -0
- package/src/drawer.ts +674 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/focus.ts +1370 -0
- package/src/form.tsx +94 -0
- package/src/gridlist.tsx +1354 -0
- package/src/group.tsx +146 -0
- package/src/i18n.ts +823 -0
- package/src/index.ts +1672 -0
- package/src/interactions/description.ts +73 -0
- package/src/interactions/flags.ts +35 -0
- package/src/interactions/focus-events.ts +226 -0
- package/src/interactions/focusable.ts +86 -0
- package/src/interactions/hover.ts +213 -0
- package/src/interactions/interact-outside.ts +123 -0
- package/src/interactions/keyboard.ts +298 -0
- package/src/interactions/listeners.ts +78 -0
- package/src/interactions/long-press.ts +160 -0
- package/src/interactions/modality.ts +428 -0
- package/src/interactions/move.ts +257 -0
- package/src/interactions/open-link.ts +226 -0
- package/src/interactions/press.ts +915 -0
- package/src/interactions/prevent-focus.ts +102 -0
- package/src/interactions/scroll-wheel.ts +43 -0
- package/src/interactions/text-selection.ts +77 -0
- package/src/interactions.ts +81 -0
- package/src/label.ts +140 -0
- package/src/link.tsx +477 -0
- package/src/listbox.tsx +1247 -0
- package/src/live.ts +208 -0
- package/src/menu.tsx +2383 -0
- package/src/menubar.tsx +579 -0
- package/src/navigation-tree.tsx +357 -0
- package/src/navigation.ts +735 -0
- package/src/numberfield.tsx +942 -0
- package/src/otp.ts +430 -0
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +1549 -0
- package/src/platform.ts +75 -0
- package/src/presence.ts +164 -0
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +1717 -0
- package/src/radio.tsx +641 -0
- package/src/register-dom.ts +12 -0
- package/src/scroller.ts +1165 -0
- package/src/select.tsx +1745 -0
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +1472 -0
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +1137 -0
- package/src/splitter.ts +1152 -0
- package/src/static-collection.ts +211 -0
- package/src/switch.tsx +212 -0
- package/src/table.tsx +2218 -0
- package/src/tabs.tsx +1127 -0
- package/src/tag.tsx +637 -0
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +483 -0
- package/src/toast-components.tsx +589 -0
- package/src/toast.ts +658 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +86 -0
- package/src/toggle.ts +384 -0
- package/src/togglegroup.ts +365 -0
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +184 -0
- package/src/tooltip.tsx +674 -0
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +787 -0
- package/src/validation.ts +504 -0
- package/src/virtualizer.tsx +837 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of toggle buttons that is one control.
|
|
3
|
+
*
|
|
4
|
+
* Two halves, and they are separable on purpose.
|
|
5
|
+
*
|
|
6
|
+
* - **What is pressed.** `single` keeps at most one and `multiple` any number.
|
|
7
|
+
* A single group is NOT a radio group: pressing the pressed item releases it,
|
|
8
|
+
* which a radio cannot do, so the items stay `aria-pressed` buttons rather
|
|
9
|
+
* than becoming `role="radio"` and promising a choice that cannot be undone.
|
|
10
|
+
* - **Where Tab lands.** One item is in the tab order and the arrows move among
|
|
11
|
+
* the rest, the bargain a toolbar makes. The stop is the item focus was last
|
|
12
|
+
* on; before that, the first pressed item, so Tab returns to what is chosen;
|
|
13
|
+
* before that, the first one that is not disabled.
|
|
14
|
+
*
|
|
15
|
+
* Inside a toolbar the group gives that up. The toolbar is already one tab
|
|
16
|
+
* stop with arrows of its own, and two handlers on one key would move focus
|
|
17
|
+
* twice or trap it in the group.
|
|
18
|
+
*
|
|
19
|
+
* The order the arrows walk is the DOCUMENT's, read when a key arrives. The
|
|
20
|
+
* order items registered in is only the answer until the elements exist, which
|
|
21
|
+
* is what a server render and the first paint need.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { type Accessor, createSignal, createEffect } from "@barqjs/core";
|
|
25
|
+
import { isServer } from "@barqjs/web";
|
|
26
|
+
import { tryCleanup } from "@barqjs/primitives/utils";
|
|
27
|
+
import { contains, focusWithoutScrolling, targetElement } from "./dom.ts";
|
|
28
|
+
import { type ReadingDirection, useDirection } from "./i18n.ts";
|
|
29
|
+
import type { ElementRef } from "./interactions/press.ts";
|
|
30
|
+
import type { Orientation } from "./selection.ts";
|
|
31
|
+
import {
|
|
32
|
+
access,
|
|
33
|
+
controllable,
|
|
34
|
+
type DOMProps,
|
|
35
|
+
filterDOMProps,
|
|
36
|
+
type MaybeAccessor,
|
|
37
|
+
mergeProps,
|
|
38
|
+
} from "./utils.ts";
|
|
39
|
+
|
|
40
|
+
export type ToggleGroupSelectionMode = "single" | "multiple";
|
|
41
|
+
|
|
42
|
+
export interface ToggleGroupStateOptions {
|
|
43
|
+
/** @default "single" */
|
|
44
|
+
selectionMode?: MaybeAccessor<ToggleGroupSelectionMode | undefined>;
|
|
45
|
+
selectedKeys?: MaybeAccessor<readonly string[] | undefined>;
|
|
46
|
+
defaultSelectedKeys?: MaybeAccessor<readonly string[] | undefined>;
|
|
47
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* One tab stop for the whole group. Off, every item is a stop of its own and
|
|
50
|
+
* the arrows are left alone, which is what a group inside a toolbar wants:
|
|
51
|
+
* the toolbar is already roving.
|
|
52
|
+
*
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
rovingFocus?: MaybeAccessor<boolean | undefined>;
|
|
56
|
+
onSelectionChange?: (keys: string[]) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ToggleGroupItemRecord {
|
|
60
|
+
element: Accessor<Element | null>;
|
|
61
|
+
isDisabled: Accessor<boolean>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ToggleGroupState {
|
|
65
|
+
selectionMode: Accessor<ToggleGroupSelectionMode>;
|
|
66
|
+
selectedKeys: Accessor<readonly string[]>;
|
|
67
|
+
isSelected(key: string): boolean;
|
|
68
|
+
setSelected(key: string, isSelected: boolean): void;
|
|
69
|
+
toggle(key: string): void;
|
|
70
|
+
isDisabled: Accessor<boolean>;
|
|
71
|
+
isRoving: Accessor<boolean>;
|
|
72
|
+
/** Told by the group's element whether something outside it is roving already. */
|
|
73
|
+
setYielding(isYielding: boolean): void;
|
|
74
|
+
/** The one item in the tab order, or `null` when none can be. */
|
|
75
|
+
tabStop: Accessor<string | null>;
|
|
76
|
+
setFocusedKey(key: string | null): void;
|
|
77
|
+
/** Adds an item, and returns what removes it. */
|
|
78
|
+
register(key: string, record: ToggleGroupItemRecord): () => void;
|
|
79
|
+
/** The key whose element holds `target`, if one does. */
|
|
80
|
+
keyOf(target: Element | null): string | null;
|
|
81
|
+
/** Every item that can take focus, in document order. */
|
|
82
|
+
focusableItems(): HTMLElement[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function inDocumentOrder(a: Element, b: Element): number {
|
|
86
|
+
const position = a.compareDocumentPosition(b);
|
|
87
|
+
if ((position & Node.DOCUMENT_POSITION_FOLLOWING) !== 0) return -1;
|
|
88
|
+
if ((position & Node.DOCUMENT_POSITION_PRECEDING) !== 0) return 1;
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function toggleGroupState(options: ToggleGroupStateOptions = {}): ToggleGroupState {
|
|
93
|
+
const selectionMode = (): ToggleGroupSelectionMode => access(options.selectionMode) ?? "single";
|
|
94
|
+
const isDisabled = (): boolean => access(options.isDisabled) === true;
|
|
95
|
+
const [isYielding, setYielding] = createSignal(false);
|
|
96
|
+
const isRoving = (): boolean => access(options.rovingFocus) !== false && !isYielding();
|
|
97
|
+
|
|
98
|
+
const [selectedKeys, setSelectedKeys] = controllable<readonly string[]>(
|
|
99
|
+
() => access(options.selectedKeys),
|
|
100
|
+
() => access(options.defaultSelectedKeys) ?? [],
|
|
101
|
+
(keys) => options.onSelectionChange?.([...keys]),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const records = new Map<string, ToggleGroupItemRecord>();
|
|
105
|
+
// Kept beside the signal that announces it: a write is staged until the next
|
|
106
|
+
// flush, and a server render reads the order as each item is built.
|
|
107
|
+
//
|
|
108
|
+
// `ownedWrite`: an item registers from its own component body, which is the
|
|
109
|
+
// only place it knows its value.
|
|
110
|
+
let keys: readonly string[] = [];
|
|
111
|
+
const [version, bump] = createSignal(0, { equals: false, ownedWrite: true });
|
|
112
|
+
const order = (): readonly string[] => {
|
|
113
|
+
version();
|
|
114
|
+
return keys;
|
|
115
|
+
};
|
|
116
|
+
const setOrder = (next: readonly string[]): void => {
|
|
117
|
+
keys = next;
|
|
118
|
+
bump(0);
|
|
119
|
+
};
|
|
120
|
+
const [focusedKey, setFocusedKey] = createSignal<string | null>(null);
|
|
121
|
+
|
|
122
|
+
const usable = (key: string): boolean => records.get(key)?.isDisabled() !== true;
|
|
123
|
+
|
|
124
|
+
if (!isServer) {
|
|
125
|
+
createEffect(
|
|
126
|
+
() => {
|
|
127
|
+
const current = order();
|
|
128
|
+
return { current, elements: current.map((key) => records.get(key)?.element() ?? null) };
|
|
129
|
+
},
|
|
130
|
+
({ current, elements }) => {
|
|
131
|
+
const placed: { key: string; element: Element }[] = [];
|
|
132
|
+
for (const [index, key] of current.entries()) {
|
|
133
|
+
const element = elements[index] ?? null;
|
|
134
|
+
// Not all built yet, or not in one tree yet: the registration order
|
|
135
|
+
// stands until they are, and each ref landing runs this again.
|
|
136
|
+
if (element === null || !element.isConnected) return;
|
|
137
|
+
placed.push({ key, element });
|
|
138
|
+
}
|
|
139
|
+
const sorted = placed
|
|
140
|
+
.toSorted((a, b) => inDocumentOrder(a.element, b.element))
|
|
141
|
+
.map((each) => each.key);
|
|
142
|
+
if (sorted.some((key, index) => key !== current[index])) setOrder(sorted);
|
|
143
|
+
},
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const setSelected = (key: string, next: boolean): void => {
|
|
148
|
+
if (isDisabled()) return;
|
|
149
|
+
const held = selectedKeys();
|
|
150
|
+
const has = held.includes(key);
|
|
151
|
+
if (has === next) return;
|
|
152
|
+
if (!next) setSelectedKeys(held.filter((each) => each !== key));
|
|
153
|
+
else if (selectionMode() === "multiple") setSelectedKeys([...held, key]);
|
|
154
|
+
else setSelectedKeys([key]);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
selectionMode,
|
|
159
|
+
selectedKeys,
|
|
160
|
+
isSelected: (key) => selectedKeys().includes(key),
|
|
161
|
+
setSelected,
|
|
162
|
+
toggle: (key) => setSelected(key, !selectedKeys().includes(key)),
|
|
163
|
+
isDisabled,
|
|
164
|
+
isRoving,
|
|
165
|
+
setYielding,
|
|
166
|
+
tabStop() {
|
|
167
|
+
const current = order();
|
|
168
|
+
if (isDisabled()) return null;
|
|
169
|
+
const focused = focusedKey();
|
|
170
|
+
if (focused !== null && current.includes(focused) && usable(focused)) return focused;
|
|
171
|
+
const selected = selectedKeys();
|
|
172
|
+
return (
|
|
173
|
+
current.find((key) => selected.includes(key) && usable(key)) ??
|
|
174
|
+
current.find((key) => usable(key)) ??
|
|
175
|
+
null
|
|
176
|
+
);
|
|
177
|
+
},
|
|
178
|
+
setFocusedKey,
|
|
179
|
+
register(key, record) {
|
|
180
|
+
records.set(key, record);
|
|
181
|
+
if (!keys.includes(key)) setOrder([...keys, key]);
|
|
182
|
+
return () => {
|
|
183
|
+
if (records.get(key) !== record) return;
|
|
184
|
+
records.delete(key);
|
|
185
|
+
setOrder(keys.filter((each) => each !== key));
|
|
186
|
+
};
|
|
187
|
+
},
|
|
188
|
+
keyOf(target) {
|
|
189
|
+
if (target === null) return null;
|
|
190
|
+
for (const [key, record] of records) {
|
|
191
|
+
if (contains(record.element(), target)) return key;
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
},
|
|
195
|
+
focusableItems() {
|
|
196
|
+
const elements: HTMLElement[] = [];
|
|
197
|
+
for (const [key, record] of records) {
|
|
198
|
+
const element = record.element();
|
|
199
|
+
if (element instanceof HTMLElement && usable(key) && !isDisabled()) elements.push(element);
|
|
200
|
+
}
|
|
201
|
+
return elements.toSorted(inDocumentOrder);
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface ToggleGroupOptions {
|
|
207
|
+
/** The group's element. With it, a group inside a toolbar leaves the arrows to the toolbar. */
|
|
208
|
+
ref?: ElementRef;
|
|
209
|
+
/**
|
|
210
|
+
* Which arrows move focus. Unset, all four do: a group that has not said
|
|
211
|
+
* which way it runs should not make the user guess.
|
|
212
|
+
*/
|
|
213
|
+
orientation?: MaybeAccessor<Orientation | undefined>;
|
|
214
|
+
/** Overrides the direction in scope, which is what flips left and right. */
|
|
215
|
+
direction?: MaybeAccessor<ReadingDirection | undefined>;
|
|
216
|
+
/** Whether focus goes round from the last item to the first. @default true */
|
|
217
|
+
loop?: MaybeAccessor<boolean | undefined>;
|
|
218
|
+
"aria-label"?: MaybeAccessor<string | undefined>;
|
|
219
|
+
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
220
|
+
"aria-describedby"?: MaybeAccessor<string | undefined>;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface ToggleGroupResult {
|
|
224
|
+
groupProps: DOMProps;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
type Intent = "first" | "last" | "previous" | "next";
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The group's element: its role, its name, and the keys that move focus.
|
|
231
|
+
*
|
|
232
|
+
* ```tsx
|
|
233
|
+
* const state = toggleGroupState({ selectionMode: "multiple" });
|
|
234
|
+
* const { groupProps } = toggleGroup({ "aria-label": "Formatting" }, state);
|
|
235
|
+
* <div {...groupProps}>…</div>
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
export function toggleGroup(
|
|
239
|
+
options: ToggleGroupOptions,
|
|
240
|
+
state: ToggleGroupState,
|
|
241
|
+
): ToggleGroupResult {
|
|
242
|
+
const scoped = useDirection();
|
|
243
|
+
const direction = (): ReadingDirection => access(options.direction) ?? scoped();
|
|
244
|
+
|
|
245
|
+
if (!isServer && options.ref !== undefined) {
|
|
246
|
+
const { ref } = options;
|
|
247
|
+
createEffect(
|
|
248
|
+
() => access(ref),
|
|
249
|
+
(element) => {
|
|
250
|
+
const outer = element?.parentElement?.closest('[role="toolbar"]');
|
|
251
|
+
state.setYielding(outer !== null && outer !== undefined);
|
|
252
|
+
},
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const intentOf = (key: string): Intent | null => {
|
|
257
|
+
if (key === "Home") return "first";
|
|
258
|
+
if (key === "End") return "last";
|
|
259
|
+
const orientation = access(options.orientation);
|
|
260
|
+
if (orientation !== "horizontal") {
|
|
261
|
+
if (key === "ArrowUp") return "previous";
|
|
262
|
+
if (key === "ArrowDown") return "next";
|
|
263
|
+
}
|
|
264
|
+
if (orientation !== "vertical") {
|
|
265
|
+
// Left and right follow the WRITING direction; up and down never do.
|
|
266
|
+
const back = direction() === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
267
|
+
const on = direction() === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
268
|
+
if (key === back) return "previous";
|
|
269
|
+
if (key === on) return "next";
|
|
270
|
+
}
|
|
271
|
+
return null;
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
275
|
+
if (!state.isRoving()) return;
|
|
276
|
+
// With a modifier these are the browser's or the page's: Alt+Left is back.
|
|
277
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return;
|
|
278
|
+
// A key from something an item CONTAINS or opened is not the group's.
|
|
279
|
+
const from = state.keyOf(targetElement(event));
|
|
280
|
+
if (from === null) return;
|
|
281
|
+
const intent = intentOf(event.key);
|
|
282
|
+
if (intent === null) return;
|
|
283
|
+
|
|
284
|
+
const items = state.focusableItems();
|
|
285
|
+
if (items.length === 0) return;
|
|
286
|
+
const at = items.findIndex((each) => contains(each, targetElement(event)));
|
|
287
|
+
const wrap = access(options.loop) !== false;
|
|
288
|
+
const last = items.length - 1;
|
|
289
|
+
|
|
290
|
+
let to: number;
|
|
291
|
+
if (intent === "first") to = 0;
|
|
292
|
+
else if (intent === "last") to = last;
|
|
293
|
+
else if (intent === "next") to = at >= last ? (wrap ? 0 : last) : at + 1;
|
|
294
|
+
else to = at <= 0 ? (wrap ? last : 0) : at - 1;
|
|
295
|
+
|
|
296
|
+
// An outer toolbar must not move focus a second time for one key.
|
|
297
|
+
event.stopPropagation();
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
const target = items[to];
|
|
300
|
+
if (target !== undefined && to !== at) focusWithoutScrolling(target);
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const onFocusIn = (event: FocusEvent): void => {
|
|
304
|
+
const key = state.keyOf(targetElement(event));
|
|
305
|
+
if (key !== null) state.setFocusedKey(key);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
return {
|
|
309
|
+
groupProps: mergeProps(filterDOMProps(options, { labelable: true }), {
|
|
310
|
+
role: "group",
|
|
311
|
+
dir: () => access(options.direction),
|
|
312
|
+
"aria-disabled": () => state.isDisabled() || undefined,
|
|
313
|
+
onKeyDown,
|
|
314
|
+
onFocusIn,
|
|
315
|
+
}),
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
export interface ToggleGroupItemOptions {
|
|
320
|
+
/** What this item contributes to the group's value. */
|
|
321
|
+
value: MaybeAccessor<string>;
|
|
322
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
323
|
+
ref: ElementRef;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface ToggleGroupItemResult {
|
|
327
|
+
/** For a `toggleButton` or a `<ToggleButton>`: its state belongs to the group. */
|
|
328
|
+
isSelected: Accessor<boolean>;
|
|
329
|
+
isDisabled: Accessor<boolean>;
|
|
330
|
+
excludeFromTabOrder: Accessor<boolean>;
|
|
331
|
+
onChange(isSelected: boolean): void;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* One item's half: what a toggle button has to be told to belong to a group.
|
|
336
|
+
*
|
|
337
|
+
* ```tsx
|
|
338
|
+
* const domRef = ref<HTMLButtonElement>();
|
|
339
|
+
* const item = toggleGroupItem({ value: "bold", ref: domRef }, state);
|
|
340
|
+
* <ToggleButton {...item} ref={domRef.set}>Bold</ToggleButton>
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
export function toggleGroupItem(
|
|
344
|
+
options: ToggleGroupItemOptions,
|
|
345
|
+
state: ToggleGroupState,
|
|
346
|
+
): ToggleGroupItemResult {
|
|
347
|
+
const value = (): string => access(options.value);
|
|
348
|
+
const isDisabled = (): boolean => state.isDisabled() || access(options.isDisabled) === true;
|
|
349
|
+
|
|
350
|
+
// While the component is built rather than in an effect: a server render
|
|
351
|
+
// runs no effects, and its markup has to name the tab stop too.
|
|
352
|
+
tryCleanup(
|
|
353
|
+
state.register(value(), {
|
|
354
|
+
element: () => access(options.ref) ?? null,
|
|
355
|
+
isDisabled: () => access(options.isDisabled) === true,
|
|
356
|
+
}),
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
return {
|
|
360
|
+
isSelected: () => state.isSelected(value()),
|
|
361
|
+
isDisabled,
|
|
362
|
+
excludeFromTabOrder: () => state.isRoving() && state.tabStop() !== value(),
|
|
363
|
+
onChange: (next) => state.setSelected(value(), next),
|
|
364
|
+
};
|
|
365
|
+
}
|