@barqjs/aria 0.0.0-stage → 0.2.0-next.0
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 +293 -2
- package/package.json +347 -4
- package/src/breadcrumbs.tsx +296 -0
- package/src/button.tsx +342 -0
- package/src/calendar.tsx +1389 -0
- package/src/checkbox.tsx +570 -0
- package/src/collections.ts +976 -0
- package/src/color.ts +562 -0
- package/src/colorpicker.tsx +1478 -0
- package/src/combobox.tsx +2481 -0
- package/src/command.tsx +1184 -0
- package/src/date.ts +652 -0
- package/src/datefield.tsx +951 -0
- package/src/datepicker.tsx +556 -0
- package/src/dialog.tsx +890 -0
- package/src/disclosure.tsx +659 -0
- package/src/dom.ts +706 -0
- package/src/drawer.ts +674 -0
- package/src/focus.ts +1370 -0
- package/src/form.tsx +94 -0
- package/src/gridlist.tsx +563 -0
- package/src/i18n.ts +823 -0
- package/src/index.ts +1270 -0
- package/src/interactions/description.ts +73 -0
- package/src/interactions/flags.ts +35 -0
- package/src/interactions/focus-events.ts +218 -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 +105 -0
- package/src/interactions/listeners.ts +78 -0
- package/src/interactions/long-press.ts +160 -0
- package/src/interactions/modality.ts +416 -0
- package/src/interactions/move.ts +257 -0
- package/src/interactions/open-link.ts +193 -0
- package/src/interactions/press.ts +898 -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 +128 -0
- package/src/link.tsx +381 -0
- package/src/listbox.tsx +721 -0
- package/src/live.ts +204 -0
- package/src/menu.tsx +2290 -0
- package/src/menubar.tsx +575 -0
- package/src/navigation.ts +735 -0
- package/src/numberfield.tsx +838 -0
- package/src/otp.ts +430 -0
- package/src/overlays.ts +1247 -0
- package/src/platform.ts +74 -0
- package/src/presence.ts +164 -0
- package/src/questionnaire.tsx +1712 -0
- package/src/radio.tsx +567 -0
- package/src/register-dom.ts +12 -0
- package/src/scroller.ts +1165 -0
- package/src/select.tsx +1665 -0
- package/src/selection.ts +1415 -0
- package/src/slider.tsx +1042 -0
- package/src/splitter.ts +1152 -0
- package/src/static-collection.ts +211 -0
- package/src/switch.tsx +186 -0
- package/src/table.tsx +0 -0
- package/src/tabs.tsx +1018 -0
- package/src/tag.tsx +452 -0
- package/src/textfield.tsx +417 -0
- package/src/toast.ts +658 -0
- package/src/toggle-input.tsx +48 -0
- package/src/toggle.ts +321 -0
- package/src/togglegroup.ts +365 -0
- package/src/toolbar.tsx +179 -0
- package/src/tooltip.tsx +657 -0
- package/src/utils.ts +758 -0
- package/src/validation.ts +447 -0
- package/src/virtualizer.tsx +674 -0
package/src/tag.tsx
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tag group: removable labels, keywords or filters.
|
|
3
|
+
*
|
|
4
|
+
* A grid, not a list, for the same reason a grid list is: a tag holds a remove
|
|
5
|
+
* button, and an `option` may not contain anything interactive. So each tag is
|
|
6
|
+
* a row with one cell, the arrows move between them HORIZONTALLY, and Delete
|
|
7
|
+
* or Backspace removes.
|
|
8
|
+
*
|
|
9
|
+
* Two things only a tag group needs:
|
|
10
|
+
*
|
|
11
|
+
* - **Removing the last tag focuses the group.** Otherwise focus falls to the
|
|
12
|
+
* body and a keyboard user is thrown back to the top of the page by an
|
|
13
|
+
* action they took deliberately.
|
|
14
|
+
* - **The group is a live region while it has focus, and silent otherwise.**
|
|
15
|
+
* A tag disappearing under your hands is worth announcing; a filter panel
|
|
16
|
+
* updating five groups on the other side of the page is not, and
|
|
17
|
+
* `aria-relevant="additions"` keeps the removals from being read twice —
|
|
18
|
+
* once by the button and once by the region.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
type Accessor,
|
|
23
|
+
type Child,
|
|
24
|
+
For,
|
|
25
|
+
createMemo,
|
|
26
|
+
createContext,
|
|
27
|
+
createEffect,
|
|
28
|
+
getContext,
|
|
29
|
+
getOwner,
|
|
30
|
+
type Incoming,
|
|
31
|
+
install,
|
|
32
|
+
provide,
|
|
33
|
+
untrack,
|
|
34
|
+
} from "@barqjs/core";
|
|
35
|
+
import { isServer } from "@barqjs/web";
|
|
36
|
+
import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
|
|
37
|
+
import { button } from "./button.tsx";
|
|
38
|
+
import type { ItemAccessors, Key, ListStateOptions, Node, SelectionMode } from "./collections.ts";
|
|
39
|
+
import { listState, type ListState } from "./collections.ts";
|
|
40
|
+
import { focusRing } from "./focus.ts";
|
|
41
|
+
import { useLocale } from "./i18n.ts";
|
|
42
|
+
import { focusWithin } from "./interactions/focus-events.ts";
|
|
43
|
+
import { hover } from "./interactions/hover.ts";
|
|
44
|
+
import type { ElementRef } from "./interactions/press.ts";
|
|
45
|
+
import { field, type FieldOptions } from "./label.ts";
|
|
46
|
+
import {
|
|
47
|
+
ListKeyboardDelegate,
|
|
48
|
+
selectableItem,
|
|
49
|
+
selectableList,
|
|
50
|
+
type KeyboardDelegate,
|
|
51
|
+
} from "./selection.ts";
|
|
52
|
+
import {
|
|
53
|
+
access,
|
|
54
|
+
type DOMProps,
|
|
55
|
+
filterDOMProps,
|
|
56
|
+
fromProps,
|
|
57
|
+
id,
|
|
58
|
+
type MaybeAccessor,
|
|
59
|
+
mergeProps,
|
|
60
|
+
type StyleProps,
|
|
61
|
+
styleProps,
|
|
62
|
+
} from "./utils.ts";
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// The group
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
export interface TagGroupOptions extends FieldOptions {
|
|
69
|
+
ref: ElementRef;
|
|
70
|
+
keyboardDelegate?: KeyboardDelegate;
|
|
71
|
+
disallowEmptySelection?: MaybeAccessor<boolean | undefined>;
|
|
72
|
+
escapeKeyBehavior?: MaybeAccessor<"clearSelection" | "none" | undefined>;
|
|
73
|
+
onRemove?: (keys: Set<Key>) => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface TagGroupResult {
|
|
77
|
+
gridProps: DOMProps;
|
|
78
|
+
labelProps: DOMProps;
|
|
79
|
+
descriptionProps: DOMProps;
|
|
80
|
+
errorMessageProps: DOMProps;
|
|
81
|
+
baseId: Accessor<string>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function tagGroup(options: TagGroupOptions, state: ListState<unknown>): TagGroupResult {
|
|
85
|
+
const baseId = id();
|
|
86
|
+
const locale = useLocale();
|
|
87
|
+
|
|
88
|
+
const delegate =
|
|
89
|
+
options.keyboardDelegate ??
|
|
90
|
+
new ListKeyboardDelegate({
|
|
91
|
+
collection: state.collection,
|
|
92
|
+
ref: options.ref,
|
|
93
|
+
// Tags flow across, so the arrows that move between them are the
|
|
94
|
+
// horizontal ones.
|
|
95
|
+
orientation: "horizontal",
|
|
96
|
+
direction: () => locale().direction,
|
|
97
|
+
disabledKeys: state.disabledKeys,
|
|
98
|
+
disabledBehavior: () => state.selectionManager().disabledBehavior,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const { labelProps, fieldProps, descriptionProps, errorMessageProps } = field({
|
|
102
|
+
...options,
|
|
103
|
+
labelElementType: "span",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const { listProps } = selectableList({
|
|
107
|
+
...options,
|
|
108
|
+
ref: options.ref,
|
|
109
|
+
selectionManager: state.selectionManager,
|
|
110
|
+
collection: state.collection,
|
|
111
|
+
disabledKeys: state.disabledKeys,
|
|
112
|
+
keyboardDelegate: delegate,
|
|
113
|
+
shouldFocusWrap: true,
|
|
114
|
+
linkBehavior: "override",
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const { focusWithinProps, isFocusWithin } = focusWithin({});
|
|
118
|
+
|
|
119
|
+
if (!isServer) {
|
|
120
|
+
// Removing the LAST tag leaves nowhere inside to stand.
|
|
121
|
+
let previous = state.collection().size;
|
|
122
|
+
createEffect(
|
|
123
|
+
() => [state.collection().size, access(options.ref) as HTMLElement | null] as const,
|
|
124
|
+
([size, element]) => {
|
|
125
|
+
if (previous > 0 && size === 0 && untrack(isFocusWithin) && element !== null)
|
|
126
|
+
element.focus();
|
|
127
|
+
previous = size;
|
|
128
|
+
},
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const isEmpty = (): boolean => state.collection().size === 0;
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
baseId,
|
|
136
|
+
labelProps,
|
|
137
|
+
descriptionProps,
|
|
138
|
+
errorMessageProps,
|
|
139
|
+
gridProps: mergeProps(
|
|
140
|
+
filterDOMProps(options, { labelable: true }),
|
|
141
|
+
listProps,
|
|
142
|
+
fieldProps,
|
|
143
|
+
focusWithinProps,
|
|
144
|
+
{
|
|
145
|
+
// An empty group is a group: `role="grid"` with no rows is a grid a
|
|
146
|
+
// screen reader reports as broken.
|
|
147
|
+
role: () => (isEmpty() ? "group" : "grid"),
|
|
148
|
+
id: baseId,
|
|
149
|
+
"aria-atomic": false,
|
|
150
|
+
"aria-relevant": "additions",
|
|
151
|
+
// Only while the user is IN it. A filter panel rebuilding five groups
|
|
152
|
+
// elsewhere on the page is not something to read out.
|
|
153
|
+
"aria-live": () => (isFocusWithin() ? "polite" : "off"),
|
|
154
|
+
},
|
|
155
|
+
),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** The id a tag renders under, derived from the key so anything can name it. */
|
|
160
|
+
export function tagIdFor(baseId: string, key: Key): string {
|
|
161
|
+
return `${baseId}-tag-${String(key)}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------------------
|
|
165
|
+
// A tag
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
|
|
168
|
+
export interface TagOptions {
|
|
169
|
+
key: Key;
|
|
170
|
+
ref: ElementRef;
|
|
171
|
+
baseId: MaybeAccessor<string>;
|
|
172
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
173
|
+
onRemove?: (keys: Set<Key>) => void;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface TagResult {
|
|
177
|
+
rowProps: DOMProps;
|
|
178
|
+
gridCellProps: DOMProps;
|
|
179
|
+
/** Options for {@link button}, not props for an element. */
|
|
180
|
+
removeButtonProps: DOMProps;
|
|
181
|
+
allowsRemoving: Accessor<boolean>;
|
|
182
|
+
isSelected: Accessor<boolean>;
|
|
183
|
+
isFocused: Accessor<boolean>;
|
|
184
|
+
isPressed: Accessor<boolean>;
|
|
185
|
+
isDisabled: Accessor<boolean>;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function tag(options: TagOptions, state: ListState<unknown>): TagResult {
|
|
189
|
+
const buttonId = id();
|
|
190
|
+
const rowId = (): string => tagIdFor(access(options.baseId), options.key);
|
|
191
|
+
const node = (): Node<unknown> | null => state.collection().getItem(options.key);
|
|
192
|
+
|
|
193
|
+
const item = selectableItem({
|
|
194
|
+
key: options.key,
|
|
195
|
+
ref: options.ref,
|
|
196
|
+
id: rowId,
|
|
197
|
+
selectionManager: state.selectionManager,
|
|
198
|
+
isDisabled: options.isDisabled,
|
|
199
|
+
linkBehavior: "override",
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
const allowsRemoving = (): boolean => options.onRemove !== undefined;
|
|
203
|
+
|
|
204
|
+
const remove = (): void => {
|
|
205
|
+
if (item.isDisabled()) return;
|
|
206
|
+
// Removing one of SEVERAL selected tags removes them all: the selection is
|
|
207
|
+
// what the user pointed at, and taking one out of it would be a surprise.
|
|
208
|
+
const manager = state.selectionManager();
|
|
209
|
+
if (manager.isSelected(options.key)) {
|
|
210
|
+
options.onRemove?.(new Set(manager.selectedKeys));
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
options.onRemove?.(new Set([options.key]));
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
const onKeyDown = (event: KeyboardEvent): void => {
|
|
217
|
+
if (!allowsRemoving() || item.isDisabled()) return;
|
|
218
|
+
if (event.key !== "Delete" && event.key !== "Backspace") return;
|
|
219
|
+
event.preventDefault();
|
|
220
|
+
remove();
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
allowsRemoving,
|
|
225
|
+
isSelected: item.isSelected,
|
|
226
|
+
isFocused: item.isFocused,
|
|
227
|
+
isPressed: item.isPressed,
|
|
228
|
+
isDisabled: item.isDisabled,
|
|
229
|
+
gridCellProps: { role: "gridcell" },
|
|
230
|
+
rowProps: mergeProps(item.itemProps, {
|
|
231
|
+
role: "row",
|
|
232
|
+
id: rowId,
|
|
233
|
+
onKeyDown,
|
|
234
|
+
"aria-label": () => node()?.["aria-label"] ?? node()?.textValue ?? undefined,
|
|
235
|
+
"aria-selected": () =>
|
|
236
|
+
state.selectionManager().canSelectItem(options.key) ? item.isSelected() : undefined,
|
|
237
|
+
"aria-disabled": () => item.isDisabled() || undefined,
|
|
238
|
+
}),
|
|
239
|
+
removeButtonProps: {
|
|
240
|
+
id: buttonId,
|
|
241
|
+
// Named by itself AND by the tag, so it is announced as "Remove,
|
|
242
|
+
// Barcelona" rather than as one of a row of identical Remove buttons.
|
|
243
|
+
"aria-label": "Remove",
|
|
244
|
+
"aria-labelledby": () => `${buttonId()} ${rowId()}`,
|
|
245
|
+
isDisabled: item.isDisabled,
|
|
246
|
+
excludeFromTabOrder: true,
|
|
247
|
+
onPress: remove,
|
|
248
|
+
},
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Components
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
interface TagGroupContextValue {
|
|
257
|
+
state: ListState<unknown>;
|
|
258
|
+
baseId: Accessor<string>;
|
|
259
|
+
onRemove: Accessor<((keys: Set<Key>) => void) | undefined>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const TagGroupContext = createContext<TagGroupContextValue | null>(null);
|
|
263
|
+
const TagNodeContext = createContext<Node<unknown> | null>(null);
|
|
264
|
+
|
|
265
|
+
export function useTagGroup(): TagGroupContextValue {
|
|
266
|
+
const value = getContext(TagGroupContext);
|
|
267
|
+
if (value === null || value === undefined) {
|
|
268
|
+
throw new Error("A Tag must be rendered inside a TagGroup.");
|
|
269
|
+
}
|
|
270
|
+
return value;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** The collection node the tag being built is for. */
|
|
274
|
+
export function useTagNode(): Node<unknown> {
|
|
275
|
+
const node = getContext(TagNodeContext);
|
|
276
|
+
if (node === null || node === undefined) {
|
|
277
|
+
throw new Error("A Tag must be rendered inside a TagGroup's item callback.");
|
|
278
|
+
}
|
|
279
|
+
return node;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function TagGroupProvider(props: Incoming<{ value: TagGroupContextValue; children?: Child }>) {
|
|
283
|
+
return provide(
|
|
284
|
+
TagGroupContext,
|
|
285
|
+
() => props.value(),
|
|
286
|
+
() => props.children as unknown,
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface TagGroupComponentProps<T> extends StyleProps, ItemAccessors<T> {
|
|
291
|
+
/** The tags, in order. */
|
|
292
|
+
items: Iterable<T>;
|
|
293
|
+
/** How one tag renders. Return a `<Tag>`. */
|
|
294
|
+
children: (item: T) => Child;
|
|
295
|
+
label?: Child;
|
|
296
|
+
description?: Child;
|
|
297
|
+
errorMessage?: Child;
|
|
298
|
+
/** @default "none" */
|
|
299
|
+
selectionMode?: SelectionMode;
|
|
300
|
+
selectedKeys?: "all" | Iterable<Key>;
|
|
301
|
+
defaultSelectedKeys?: "all" | Iterable<Key>;
|
|
302
|
+
disabledKeys?: Iterable<Key>;
|
|
303
|
+
"aria-label"?: string;
|
|
304
|
+
"aria-labelledby"?: string;
|
|
305
|
+
ref?: RefTarget<HTMLDivElement>;
|
|
306
|
+
onSelectionChange?: (keys: "all" | Set<Key>) => void;
|
|
307
|
+
/** Without it the tags have no remove button and cannot be deleted. */
|
|
308
|
+
onRemove?: (keys: Set<Key>) => void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* ```tsx
|
|
313
|
+
* <TagGroup label="Filters" items={filters()} onRemove={(keys) => drop(keys)}>
|
|
314
|
+
* {(filter) => <Tag>{filter.name}</Tag>}
|
|
315
|
+
* </TagGroup>
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
export function TagGroup<T>(props: Incoming<TagGroupComponentProps<T>>) {
|
|
319
|
+
const domRef = makeRef<HTMLDivElement>();
|
|
320
|
+
const options = fromProps(props as unknown as Incoming<Record<string, unknown>>);
|
|
321
|
+
|
|
322
|
+
const state = listState<T>({
|
|
323
|
+
...(options as ListStateOptions<T>),
|
|
324
|
+
onSelectionChange: (keys) => props.onSelectionChange?.()?.(keys),
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const { gridProps, labelProps, descriptionProps, errorMessageProps, baseId } = tagGroup(
|
|
328
|
+
{
|
|
329
|
+
...(options as unknown as TagGroupOptions),
|
|
330
|
+
ref: domRef,
|
|
331
|
+
onRemove: props.onRemove?.() === undefined ? undefined : (keys) => props.onRemove?.()?.(keys),
|
|
332
|
+
},
|
|
333
|
+
state,
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const value: TagGroupContextValue = {
|
|
337
|
+
state: state,
|
|
338
|
+
baseId,
|
|
339
|
+
onRemove: () => props.onRemove?.(),
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const elementProps = mergeProps(
|
|
343
|
+
gridProps,
|
|
344
|
+
filterDOMProps(fromProps(props), { global: true }),
|
|
345
|
+
styleProps(props),
|
|
346
|
+
{
|
|
347
|
+
"data-empty": () => state.collection().size === 0,
|
|
348
|
+
"data-testid": () => props["data-testid"]?.(),
|
|
349
|
+
},
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
const render = props.children;
|
|
353
|
+
|
|
354
|
+
return (
|
|
355
|
+
<TagGroupProvider value={value}>
|
|
356
|
+
<span {...labelProps}>{props.label}</span>
|
|
357
|
+
<div {...elementProps} ref={mergeRefs(domRef.set, props.ref?.())}>
|
|
358
|
+
<For each={() => [...state.collection()]}>
|
|
359
|
+
{(node: Node<T>) => {
|
|
360
|
+
const rowOwner = getOwner();
|
|
361
|
+
if (rowOwner !== null) install(rowOwner, TagNodeContext, () => node as Node<unknown>);
|
|
362
|
+
return render(node.value as T);
|
|
363
|
+
}}
|
|
364
|
+
</For>
|
|
365
|
+
</div>
|
|
366
|
+
<span {...descriptionProps}>{props.description}</span>
|
|
367
|
+
<span {...errorMessageProps}>{props.errorMessage}</span>
|
|
368
|
+
</TagGroupProvider>
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface TagComponentProps extends StyleProps {
|
|
373
|
+
children?: Child;
|
|
374
|
+
"aria-label"?: string;
|
|
375
|
+
ref?: RefTarget<HTMLDivElement>;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* One tag, with a remove button when the group takes removals.
|
|
380
|
+
*
|
|
381
|
+
* The button is out of the Tab order: the tag itself is the stop, and Delete
|
|
382
|
+
* on it does the same thing. A second stop per tag would double the length of
|
|
383
|
+
* every filter bar.
|
|
384
|
+
*/
|
|
385
|
+
export function Tag(props: Incoming<TagComponentProps>) {
|
|
386
|
+
const domRef = makeRef<HTMLDivElement>();
|
|
387
|
+
const buttonRef = makeRef<HTMLButtonElement>();
|
|
388
|
+
const group = useTagGroup();
|
|
389
|
+
const node = useTagNode();
|
|
390
|
+
|
|
391
|
+
const {
|
|
392
|
+
rowProps,
|
|
393
|
+
gridCellProps,
|
|
394
|
+
removeButtonProps,
|
|
395
|
+
allowsRemoving,
|
|
396
|
+
isSelected,
|
|
397
|
+
isFocused,
|
|
398
|
+
isPressed,
|
|
399
|
+
isDisabled,
|
|
400
|
+
} = tag(
|
|
401
|
+
{
|
|
402
|
+
key: node.key,
|
|
403
|
+
ref: domRef,
|
|
404
|
+
baseId: group.baseId,
|
|
405
|
+
isDisabled: () => node.props?.isDisabled === true,
|
|
406
|
+
onRemove: group.onRemove() === undefined ? undefined : (keys) => group.onRemove()?.(keys),
|
|
407
|
+
},
|
|
408
|
+
group.state,
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
const { buttonProps } = button(removeButtonProps, buttonRef);
|
|
412
|
+
const { hoverProps, isHovered } = hover({ isDisabled });
|
|
413
|
+
const { focusProps, isFocusVisible } = focusRing();
|
|
414
|
+
|
|
415
|
+
const elementProps = mergeProps(
|
|
416
|
+
rowProps,
|
|
417
|
+
hoverProps,
|
|
418
|
+
focusProps,
|
|
419
|
+
filterDOMProps(fromProps(props), { global: true }),
|
|
420
|
+
styleProps(props),
|
|
421
|
+
{
|
|
422
|
+
"aria-label": () => props["aria-label"]?.(),
|
|
423
|
+
"data-selected": isSelected,
|
|
424
|
+
"data-focused": isFocused,
|
|
425
|
+
"data-focus-visible": isFocusVisible,
|
|
426
|
+
"data-pressed": isPressed,
|
|
427
|
+
"data-hovered": isHovered,
|
|
428
|
+
"data-disabled": isDisabled,
|
|
429
|
+
"data-removable": allowsRemoving,
|
|
430
|
+
"data-testid": () => props["data-testid"]?.(),
|
|
431
|
+
},
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
const removeProps = createMemo(() =>
|
|
435
|
+
mergeProps(buttonProps, { id: removeButtonProps.id, type: "button" }),
|
|
436
|
+
);
|
|
437
|
+
|
|
438
|
+
return (
|
|
439
|
+
<div {...elementProps} ref={mergeRefs(domRef.set, props.ref?.())}>
|
|
440
|
+
<div {...gridCellProps}>
|
|
441
|
+
{props.children}
|
|
442
|
+
{() =>
|
|
443
|
+
allowsRemoving() ? (
|
|
444
|
+
<button {...removeProps()} ref={buttonRef.set}>
|
|
445
|
+
<span aria-hidden="true">×</span>
|
|
446
|
+
</button>
|
|
447
|
+
) : null
|
|
448
|
+
}
|
|
449
|
+
</div>
|
|
450
|
+
</div>
|
|
451
|
+
);
|
|
452
|
+
}
|