@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.
Files changed (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +293 -2
  3. package/package.json +347 -4
  4. package/src/breadcrumbs.tsx +296 -0
  5. package/src/button.tsx +342 -0
  6. package/src/calendar.tsx +1389 -0
  7. package/src/checkbox.tsx +570 -0
  8. package/src/collections.ts +976 -0
  9. package/src/color.ts +562 -0
  10. package/src/colorpicker.tsx +1478 -0
  11. package/src/combobox.tsx +2481 -0
  12. package/src/command.tsx +1184 -0
  13. package/src/date.ts +652 -0
  14. package/src/datefield.tsx +951 -0
  15. package/src/datepicker.tsx +556 -0
  16. package/src/dialog.tsx +890 -0
  17. package/src/disclosure.tsx +659 -0
  18. package/src/dom.ts +706 -0
  19. package/src/drawer.ts +674 -0
  20. package/src/focus.ts +1370 -0
  21. package/src/form.tsx +94 -0
  22. package/src/gridlist.tsx +563 -0
  23. package/src/i18n.ts +823 -0
  24. package/src/index.ts +1270 -0
  25. package/src/interactions/description.ts +73 -0
  26. package/src/interactions/flags.ts +35 -0
  27. package/src/interactions/focus-events.ts +218 -0
  28. package/src/interactions/focusable.ts +86 -0
  29. package/src/interactions/hover.ts +213 -0
  30. package/src/interactions/interact-outside.ts +123 -0
  31. package/src/interactions/keyboard.ts +105 -0
  32. package/src/interactions/listeners.ts +78 -0
  33. package/src/interactions/long-press.ts +160 -0
  34. package/src/interactions/modality.ts +416 -0
  35. package/src/interactions/move.ts +257 -0
  36. package/src/interactions/open-link.ts +193 -0
  37. package/src/interactions/press.ts +898 -0
  38. package/src/interactions/prevent-focus.ts +102 -0
  39. package/src/interactions/scroll-wheel.ts +43 -0
  40. package/src/interactions/text-selection.ts +77 -0
  41. package/src/interactions.ts +81 -0
  42. package/src/label.ts +128 -0
  43. package/src/link.tsx +381 -0
  44. package/src/listbox.tsx +721 -0
  45. package/src/live.ts +204 -0
  46. package/src/menu.tsx +2290 -0
  47. package/src/menubar.tsx +575 -0
  48. package/src/navigation.ts +735 -0
  49. package/src/numberfield.tsx +838 -0
  50. package/src/otp.ts +430 -0
  51. package/src/overlays.ts +1247 -0
  52. package/src/platform.ts +74 -0
  53. package/src/presence.ts +164 -0
  54. package/src/questionnaire.tsx +1712 -0
  55. package/src/radio.tsx +567 -0
  56. package/src/register-dom.ts +12 -0
  57. package/src/scroller.ts +1165 -0
  58. package/src/select.tsx +1665 -0
  59. package/src/selection.ts +1415 -0
  60. package/src/slider.tsx +1042 -0
  61. package/src/splitter.ts +1152 -0
  62. package/src/static-collection.ts +211 -0
  63. package/src/switch.tsx +186 -0
  64. package/src/table.tsx +0 -0
  65. package/src/tabs.tsx +1018 -0
  66. package/src/tag.tsx +452 -0
  67. package/src/textfield.tsx +417 -0
  68. package/src/toast.ts +658 -0
  69. package/src/toggle-input.tsx +48 -0
  70. package/src/toggle.ts +321 -0
  71. package/src/togglegroup.ts +365 -0
  72. package/src/toolbar.tsx +179 -0
  73. package/src/tooltip.tsx +657 -0
  74. package/src/utils.ts +758 -0
  75. package/src/validation.ts +447 -0
  76. package/src/virtualizer.tsx +674 -0
package/src/radio.tsx ADDED
@@ -0,0 +1,567 @@
1
+ /**
2
+ * A radio group: one of several, mutually exclusive.
3
+ *
4
+ * The keyboard behaviour is what separates a radio group from a list of
5
+ * checkboxes, and it is not what the name suggests. The whole group is ONE Tab
6
+ * stop, and the arrow keys move between the members AND select as they go —
7
+ * there is no "focus without selecting". Tab therefore lands on the selected
8
+ * radio, or on the first one when nothing is selected.
9
+ *
10
+ * The platform gives all of that to a set of `<input type="radio">` sharing a
11
+ * `name`, which is why these are real radios. What is added is the arrow
12
+ * navigation, which the platform only provides inside a single form, and the
13
+ * roving `tabindex` that makes Tab skip the group once entered.
14
+ */
15
+
16
+ import {
17
+ type Accessor,
18
+ type Child,
19
+ type Incoming,
20
+ createContext,
21
+ createSignal,
22
+ getContext,
23
+ getOwner,
24
+ install,
25
+ } from "@barqjs/core";
26
+ import { ref as makeRef, type RefTarget } from "@barqjs/primitives/refs";
27
+ import { ownerWindow, targetElement } from "./dom.ts";
28
+ import { focusableWalker } from "./focus.ts";
29
+ import { focusRing } from "./focus.ts";
30
+ import { hover } from "./interactions/hover.ts";
31
+ import { focusable } from "./interactions/focusable.ts";
32
+ import { press, type ElementRef, type PressEvent } from "./interactions/press.ts";
33
+ import { useLocale } from "./i18n.ts";
34
+ import { field, type FieldOptions } from "./label.ts";
35
+ import { formReset, toggleElementType, type ToggleElementType } from "./toggle.ts";
36
+ import { toggleInput } from "./toggle-input.tsx";
37
+ import {
38
+ fieldValidation,
39
+ type FormValidationState,
40
+ type ValidateFunction,
41
+ type ValidationBehavior,
42
+ } from "./validation.ts";
43
+ import {
44
+ access,
45
+ callback,
46
+ controllable,
47
+ type DOMProps,
48
+ filterDOMProps,
49
+ fromProps,
50
+ id,
51
+ type MaybeAccessor,
52
+ mergeProps,
53
+ type StyleProps,
54
+ styleProps,
55
+ } from "./utils.ts";
56
+
57
+ export interface RadioGroupStateOptions {
58
+ value?: MaybeAccessor<string | null | undefined>;
59
+ defaultValue?: MaybeAccessor<string | null | undefined>;
60
+ isDisabled?: MaybeAccessor<boolean | undefined>;
61
+ isReadOnly?: MaybeAccessor<boolean | undefined>;
62
+ isRequired?: MaybeAccessor<boolean | undefined>;
63
+ isInvalid?: MaybeAccessor<boolean | undefined>;
64
+ /** What the page thinks of the choice, checked as it changes. */
65
+ validate?: ValidateFunction<string | null>;
66
+ /** @default "aria" */
67
+ validationBehavior?: MaybeAccessor<ValidationBehavior | undefined>;
68
+ /** The caller's own message, which wins over anything validation found. */
69
+ errorMessage?: MaybeAccessor<unknown>;
70
+ /** The form field name, for matching a server error to this group. */
71
+ name?: MaybeAccessor<string | undefined>;
72
+ onChange?: (value: string) => void;
73
+ }
74
+
75
+ export interface RadioGroupState {
76
+ selectedValue: Accessor<string | null>;
77
+ setSelectedValue(value: string): void;
78
+ /**
79
+ * The radio Tab last landed on.
80
+ *
81
+ * With nothing selected, Tab must enter at the first radio; once the user
82
+ * has been inside, it must return to where they were.
83
+ */
84
+ lastFocusedValue: Accessor<string | null>;
85
+ setLastFocusedValue(value: string | null): void;
86
+ defaultValue: Accessor<string | null>;
87
+ isDisabled: Accessor<boolean>;
88
+ isReadOnly: Accessor<boolean>;
89
+ isRequired: Accessor<boolean>;
90
+ isInvalid: Accessor<boolean>;
91
+ /**
92
+ * On the STATE rather than on `radioGroup`, because each radio reads it:
93
+ * an invalid group marks every button in it, and a radio has no way back to
94
+ * the hook.
95
+ */
96
+ validation: FormValidationState;
97
+ errors: Accessor<string[]>;
98
+ /** For `field`, so `aria-describedby` points at whatever is being shown. */
99
+ errorMessage: Accessor<unknown>;
100
+ }
101
+
102
+ export function radioGroupState(options: RadioGroupStateOptions): RadioGroupState {
103
+ const [value, setValue] = controllable<string | null>(
104
+ () => access(options.value),
105
+ () => access(options.defaultValue) ?? null,
106
+ (next) => options.onChange?.(next as string),
107
+ );
108
+
109
+ const [lastFocused, setLastFocused] = createSignal<string | null>(null);
110
+ const isReadOnly = (): boolean => access(options.isReadOnly) === true;
111
+ const isDisabled = (): boolean => access(options.isDisabled) === true;
112
+
113
+ const {
114
+ state: validation,
115
+ isInvalid,
116
+ errors,
117
+ errorMessage,
118
+ } = fieldValidation<string | null>({
119
+ value,
120
+ validate: options.validate,
121
+ validationBehavior: options.validationBehavior,
122
+ isInvalid: options.isInvalid,
123
+ errorMessage: options.errorMessage,
124
+ name: options.name,
125
+ });
126
+
127
+ return {
128
+ selectedValue: value,
129
+ setSelectedValue(next) {
130
+ if (isReadOnly() || isDisabled()) return;
131
+ setValue(next);
132
+ validation.commitValidation();
133
+ },
134
+ lastFocusedValue: lastFocused,
135
+ setLastFocusedValue: (next) => setLastFocused(next),
136
+ defaultValue: () => access(options.defaultValue) ?? null,
137
+ isDisabled,
138
+ isReadOnly,
139
+ isRequired: () => access(options.isRequired) === true,
140
+ isInvalid,
141
+ validation,
142
+ errors,
143
+ errorMessage,
144
+ };
145
+ }
146
+
147
+ export interface RadioGroupOptions extends FieldOptions {
148
+ name?: MaybeAccessor<string | undefined>;
149
+ /** @default "vertical" */
150
+ orientation?: MaybeAccessor<"horizontal" | "vertical" | undefined>;
151
+ isDisabled?: MaybeAccessor<boolean | undefined>;
152
+ isReadOnly?: MaybeAccessor<boolean | undefined>;
153
+ isRequired?: MaybeAccessor<boolean | undefined>;
154
+ }
155
+
156
+ export interface RadioGroupResult {
157
+ radioGroupProps: DOMProps;
158
+ labelProps: DOMProps;
159
+ descriptionProps: DOMProps;
160
+ errorMessageProps: DOMProps;
161
+ /** The shared `name`, which is what makes them one group to the platform. */
162
+ name: Accessor<string>;
163
+ }
164
+
165
+ export function radioGroup(options: RadioGroupOptions, state: RadioGroupState): RadioGroupResult {
166
+ const locale = useLocale();
167
+ const groupName = id(options.name);
168
+
169
+ const { labelProps, fieldProps, descriptionProps, errorMessageProps } = field({
170
+ ...options,
171
+ // A radiogroup is not a labelable element.
172
+ labelElementType: "span",
173
+ isInvalid: state.isInvalid,
174
+ errorMessage: state.errorMessage,
175
+ });
176
+
177
+ const orientation = (): "horizontal" | "vertical" => access(options.orientation) ?? "vertical";
178
+
179
+ const move = (direction: "next" | "previous", event: KeyboardEvent): boolean => {
180
+ const container = event.currentTarget as Element | null;
181
+ if (container === null) return false;
182
+
183
+ const from = targetElement(event) ?? undefined;
184
+ const walker = focusableWalker(container, {
185
+ from,
186
+ accept: (node) => node instanceof ownerWindow(node).HTMLInputElement && node.type === "radio",
187
+ });
188
+
189
+ let next = direction === "next" ? walker.nextNode() : walker.previousNode();
190
+ if (next === null) {
191
+ // Wrap: the group is a ring, which is what the authoring practices say.
192
+ walker.currentNode = container;
193
+ next = direction === "next" ? walker.nextNode() : walker.last();
194
+ }
195
+ if (next === null) return false;
196
+
197
+ (next as HTMLInputElement).focus();
198
+ state.setSelectedValue((next as HTMLInputElement).value);
199
+ return true;
200
+ };
201
+
202
+ const onKeyDown = (event: KeyboardEvent): void => {
203
+ const rtl = locale().direction === "rtl";
204
+ const horizontal = orientation() !== "vertical";
205
+ let handled = false;
206
+
207
+ switch (event.key) {
208
+ case "ArrowRight":
209
+ handled = move(rtl && horizontal ? "previous" : "next", event);
210
+ break;
211
+ case "ArrowLeft":
212
+ handled = move(rtl && horizontal ? "next" : "previous", event);
213
+ break;
214
+ case "ArrowDown":
215
+ handled = move("next", event);
216
+ break;
217
+ case "ArrowUp":
218
+ handled = move("previous", event);
219
+ break;
220
+ default:
221
+ return;
222
+ }
223
+
224
+ if (handled) {
225
+ event.preventDefault();
226
+ event.stopPropagation();
227
+ }
228
+ };
229
+
230
+ return {
231
+ name: groupName,
232
+ radioGroupProps: mergeProps(filterDOMProps(options, { labelable: true }), fieldProps, {
233
+ role: "radiogroup",
234
+ "aria-orientation": orientation,
235
+ "aria-invalid": () => state.isInvalid() || undefined,
236
+ "aria-readonly": () => state.isReadOnly() || undefined,
237
+ "aria-required": () => state.isRequired() || undefined,
238
+ "aria-disabled": () => state.isDisabled() || undefined,
239
+ onKeyDown,
240
+ // With nothing selected, Tab must enter at the FIRST radio again next
241
+ // time; leaving the group is when that is decided.
242
+ onFocusOut: (event: FocusEvent) => {
243
+ const container = event.currentTarget as Element | null;
244
+ const related = event.relatedTarget as Element | null;
245
+ if (container !== null && related !== null && container.contains(related)) return;
246
+ if (state.selectedValue() === null) state.setLastFocusedValue(null);
247
+ },
248
+ }),
249
+ labelProps,
250
+ descriptionProps,
251
+ errorMessageProps,
252
+ };
253
+ }
254
+
255
+ export interface RadioOptions {
256
+ value: MaybeAccessor<string>;
257
+ isDisabled?: MaybeAccessor<boolean | undefined>;
258
+ autoFocus?: MaybeAccessor<boolean | undefined>;
259
+ children?: MaybeAccessor<unknown>;
260
+ "aria-label"?: MaybeAccessor<string | undefined>;
261
+ "aria-labelledby"?: MaybeAccessor<string | undefined>;
262
+ "aria-describedby"?: MaybeAccessor<string | undefined>;
263
+ onPress?: (event: PressEvent) => void;
264
+ onFocus?: (event: FocusEvent) => void;
265
+ onBlur?: (event: FocusEvent) => void;
266
+ }
267
+
268
+ export interface RadioResult {
269
+ labelProps: DOMProps;
270
+ inputProps: DOMProps;
271
+ isSelected: Accessor<boolean>;
272
+ isPressed: Accessor<boolean>;
273
+ isDisabled: Accessor<boolean>;
274
+ }
275
+
276
+ export function radio(
277
+ options: RadioOptions,
278
+ state: RadioGroupState,
279
+ ref: ElementRef<HTMLInputElement>,
280
+ name: Accessor<string>,
281
+ ): RadioResult {
282
+ const value = (): string => access(options.value);
283
+ const isDisabled = (): boolean => access(options.isDisabled) === true || state.isDisabled();
284
+ const isSelected = (): boolean => state.selectedValue() === value();
285
+
286
+ const { pressProps, isPressed } = press({ isDisabled, onPress: options.onPress });
287
+
288
+ const [labelPressed, setLabelPressed] = createSignal(false);
289
+ const { pressProps: labelPressProps } = press({
290
+ isDisabled: () => isDisabled() || state.isReadOnly(),
291
+ onPressStart: (event) => {
292
+ if (event.pointerType === "keyboard" || event.pointerType === "virtual") {
293
+ event.continuePropagation();
294
+ return;
295
+ }
296
+ setLabelPressed(true);
297
+ },
298
+ onPressEnd: (event) => {
299
+ if (event.pointerType === "keyboard" || event.pointerType === "virtual") {
300
+ event.continuePropagation();
301
+ return;
302
+ }
303
+ setLabelPressed(false);
304
+ },
305
+ onPress: (event) => {
306
+ if (event.pointerType === "keyboard" || event.pointerType === "virtual") {
307
+ event.continuePropagation();
308
+ return;
309
+ }
310
+ options.onPress?.(event);
311
+ },
312
+ });
313
+
314
+ const { focusableProps } = focusable(
315
+ {
316
+ ...options,
317
+ onFocus: (event) => {
318
+ state.setLastFocusedValue(value());
319
+ options.onFocus?.(event);
320
+ },
321
+ },
322
+ ref,
323
+ );
324
+
325
+ formReset(ref, state.defaultValue(), (next) => {
326
+ if (next !== null) state.setSelectedValue(next);
327
+ });
328
+
329
+ /**
330
+ * The roving tab index: exactly one radio in the group is tabbable.
331
+ *
332
+ * The selected one when there is a selection; otherwise the one focus last
333
+ * left, or the first. Every other radio is reachable only with the arrows,
334
+ * which is what makes the group a single Tab stop.
335
+ */
336
+ const tabIndex = (): number | undefined => {
337
+ if (isDisabled()) return undefined;
338
+ const selected = state.selectedValue();
339
+ if (selected !== null) return selected === value() ? 0 : -1;
340
+ const lastFocused = state.lastFocusedValue();
341
+ return lastFocused === value() || lastFocused === null ? 0 : -1;
342
+ };
343
+
344
+ return {
345
+ labelProps: mergeProps(labelPressProps, {
346
+ onMouseDown: (event: MouseEvent) => event.preventDefault(),
347
+ }),
348
+
349
+ inputProps: mergeProps(
350
+ filterDOMProps(options, { labelable: true }),
351
+ pressProps,
352
+ focusableProps,
353
+ {
354
+ type: "radio",
355
+ name,
356
+ tabIndex,
357
+ checked: isSelected,
358
+ value,
359
+ disabled: isDisabled,
360
+ required: () => state.isRequired(),
361
+ // On each radio as well as on the group: a screen reader moving
362
+ // through the radios reads theirs, not the group's.
363
+ "aria-invalid": () => state.isInvalid() || undefined,
364
+ onChange: (event: Event) => {
365
+ event.stopPropagation();
366
+ state.setSelectedValue(value());
367
+ // The platform already checked this radio and unchecked its
368
+ // siblings; if the state declined, put the DOM back.
369
+ (event.target as HTMLInputElement).checked = isSelected();
370
+ },
371
+ },
372
+ ),
373
+
374
+ isSelected,
375
+ isPressed: () => isPressed() || labelPressed(),
376
+ isDisabled,
377
+ };
378
+ }
379
+
380
+ // ---------------------------------------------------------------------------
381
+ // Components
382
+ // ---------------------------------------------------------------------------
383
+
384
+ interface RadioGroupContextValue {
385
+ state: RadioGroupState;
386
+ name: Accessor<string>;
387
+ }
388
+
389
+ const RadioGroupContext = createContext<RadioGroupContextValue | null>(null);
390
+
391
+ /** The enclosing radio group. Throws outside one, which is a coding error. */
392
+ export function useRadioGroup(): RadioGroupContextValue {
393
+ const value = getContext(RadioGroupContext);
394
+ if (value === null || value === undefined) {
395
+ throw new Error("A Radio must be rendered inside a RadioGroup.");
396
+ }
397
+ return value;
398
+ }
399
+
400
+ export interface RadioGroupComponentProps extends StyleProps {
401
+ children?: Child;
402
+ label?: Child;
403
+ description?: Child;
404
+ errorMessage?: Child;
405
+ value?: string | null;
406
+ defaultValue?: string | null;
407
+ name?: string;
408
+ orientation?: "horizontal" | "vertical";
409
+ isDisabled?: boolean;
410
+ isReadOnly?: boolean;
411
+ isRequired?: boolean;
412
+ isInvalid?: boolean;
413
+ /** What the page thinks of the choice, checked as it changes. */
414
+ validate?: ValidateFunction<string | null>;
415
+ /** @default "aria" */
416
+ validationBehavior?: ValidationBehavior;
417
+ "aria-label"?: string;
418
+ "aria-labelledby"?: string;
419
+ onChange?: (value: string) => void;
420
+ }
421
+
422
+ /**
423
+ * ```tsx
424
+ * <RadioGroup label="Size" defaultValue="m">
425
+ * <Radio value="s">Small</Radio>
426
+ * <Radio value="m">Medium</Radio>
427
+ * </RadioGroup>
428
+ * ```
429
+ */
430
+ export function RadioGroup(props: Incoming<RadioGroupComponentProps>) {
431
+ const options = fromProps(props);
432
+ const state = radioGroupState({
433
+ ...(options as RadioGroupStateOptions),
434
+ validate: callback(props.validate),
435
+ validationBehavior: () => props.validationBehavior?.(),
436
+ });
437
+ const { radioGroupProps, labelProps, descriptionProps, errorMessageProps, name } = radioGroup(
438
+ options,
439
+ state,
440
+ );
441
+
442
+ const owner = getOwner();
443
+ if (owner !== null) {
444
+ const value: RadioGroupContextValue = { state, name };
445
+ install(owner, RadioGroupContext, () => value);
446
+ }
447
+
448
+ const outerProps = mergeProps(
449
+ radioGroupProps,
450
+ filterDOMProps(options, { global: true }),
451
+ styleProps(props),
452
+ {
453
+ "data-disabled": state.isDisabled,
454
+ "data-readonly": state.isReadOnly,
455
+ "data-invalid": state.isInvalid,
456
+ "data-required": state.isRequired,
457
+ "data-orientation": () => props.orientation?.() ?? "vertical",
458
+ "data-testid": () => props["data-testid"]?.(),
459
+ },
460
+ );
461
+
462
+ return (
463
+ <div {...outerProps}>
464
+ <span {...labelProps}>{props.label}</span>
465
+ {props.children}
466
+ <span {...descriptionProps}>{props.description}</span>
467
+ <span {...errorMessageProps}>
468
+ {() => (state.isInvalid() ? (state.errorMessage() as Child) : null)}
469
+ </span>
470
+ </div>
471
+ );
472
+ }
473
+
474
+ export interface RadioComponentProps extends StyleProps {
475
+ value: string;
476
+ children?: Child;
477
+ /**
478
+ * `"label"` when the children are the radio's name, `"span"` when they are
479
+ * its drawing and the name comes from somewhere else. Defaults to a label
480
+ * with children and a span without.
481
+ */
482
+ elementType?: ToggleElementType;
483
+ isDisabled?: boolean;
484
+ autoFocus?: boolean;
485
+ "aria-label"?: string;
486
+ "aria-labelledby"?: string;
487
+ "aria-describedby"?: string;
488
+ ref?: RefTarget<HTMLInputElement>;
489
+ onFocus?: (event: FocusEvent) => void;
490
+ onBlur?: (event: FocusEvent) => void;
491
+ onPress?: (event: PressEvent) => void;
492
+ }
493
+
494
+ /** What a part drawn inside a radio reads. */
495
+ export interface RadioContextValue {
496
+ isSelected: Accessor<boolean>;
497
+ isDisabled: Accessor<boolean>;
498
+ }
499
+
500
+ const RadioContext = createContext<RadioContextValue | null>(null);
501
+
502
+ /**
503
+ * The radio a part is drawn inside: the dot of a design system's circle, which
504
+ * appears with a state it does not own.
505
+ */
506
+ export function useRadio(): RadioContextValue {
507
+ const value = getContext(RadioContext);
508
+ if (value === null || value === undefined) {
509
+ throw new Error("This must be rendered inside a Radio.");
510
+ }
511
+ return value;
512
+ }
513
+
514
+ export function Radio(props: Incoming<RadioComponentProps>) {
515
+ const inputRef = makeRef<HTMLInputElement>();
516
+ const options = fromProps(props);
517
+ const group = useRadioGroup();
518
+
519
+ const { labelProps, inputProps, isSelected, isPressed, isDisabled } = radio(
520
+ options as RadioOptions,
521
+ group.state,
522
+ inputRef,
523
+ group.name,
524
+ );
525
+ const { hoverProps, isHovered } = hover({ isDisabled });
526
+ const { focusProps, isFocused, isFocusVisible } = focusRing();
527
+
528
+ const owner = getOwner();
529
+ if (owner !== null) {
530
+ const value: RadioContextValue = { isSelected, isDisabled };
531
+ install(owner, RadioContext, () => value);
532
+ }
533
+
534
+ const outerProps = mergeProps(
535
+ labelProps,
536
+ hoverProps,
537
+ // NOT `id`: this is a `<label>`, and `id` belongs on the input it wraps.
538
+ // A `<label for>` elsewhere on the page can only reach a LABELABLE element,
539
+ // so an `id` here answered `getElementById` first — the label came earlier
540
+ // in the document — and clicking the text toggled nothing. Measured on the
541
+ // site's checkbox page.
542
+ filterDOMProps(options, { global: true, id: false }),
543
+ styleProps(props),
544
+ {
545
+ "data-selected": isSelected,
546
+ "data-state": () => (isSelected() ? "checked" : "unchecked"),
547
+ "data-pressed": isPressed,
548
+ "data-hovered": isHovered,
549
+ "data-focused": isFocused,
550
+ "data-focus-visible": isFocusVisible,
551
+ "data-disabled": isDisabled,
552
+ "data-invalid": group.state.isInvalid,
553
+ "data-testid": () => props["data-testid"]?.(),
554
+ },
555
+ );
556
+
557
+ return toggleInput({
558
+ elementType: toggleElementType(props.elementType?.(), props.children),
559
+ outerProps,
560
+ inputProps,
561
+ focusProps,
562
+ inputRef,
563
+ ref: props.ref?.(),
564
+ children: props.children,
565
+ isDisabled,
566
+ });
567
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * happy-dom's globals, installed as this module's BODY.
3
+ *
4
+ * It cannot be a statement in `test-setup.ts`: every import a module declares
5
+ * is evaluated before the first line of its own body runs, so a registration
6
+ * written there happens after `@barqjs/core` has already been evaluated, and
7
+ * `env.ts` reads `typeof document` once at module scope. The whole suite would
8
+ * then run with `isServer === true` against a live DOM.
9
+ */
10
+ import { GlobalRegistrator } from "@happy-dom/global-registrator";
11
+
12
+ GlobalRegistrator.register();