@barqjs/aria 0.2.0-next.0 → 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.
Files changed (78) hide show
  1. package/README.md +24 -13
  2. package/package.json +127 -37
  3. package/src/autocomplete.tsx +581 -0
  4. package/src/breadcrumbs.tsx +21 -20
  5. package/src/button.tsx +151 -25
  6. package/src/calendar.tsx +1019 -92
  7. package/src/checkbox.tsx +214 -52
  8. package/src/collections.ts +88 -5
  9. package/src/color.ts +1580 -23
  10. package/src/colorpicker.tsx +698 -153
  11. package/src/colorswatchpicker.tsx +240 -0
  12. package/src/combobox.tsx +635 -113
  13. package/src/command.tsx +78 -59
  14. package/src/date.ts +31 -9
  15. package/src/datefield.tsx +1451 -336
  16. package/src/datepicker.tsx +465 -114
  17. package/src/dialog.tsx +302 -115
  18. package/src/disclosure.tsx +81 -29
  19. package/src/dnd/clipboard.ts +125 -0
  20. package/src/dnd/collection.ts +1265 -0
  21. package/src/dnd/data.ts +409 -0
  22. package/src/dnd/drag-drop.ts +801 -0
  23. package/src/dnd/index.ts +133 -0
  24. package/src/dnd/manager.ts +639 -0
  25. package/src/dnd/strings.ts +1279 -0
  26. package/src/dnd/targets.ts +726 -0
  27. package/src/dnd/types.ts +212 -0
  28. package/src/dom.ts +3 -6
  29. package/src/drag-and-drop.tsx +669 -0
  30. package/src/dropzone.tsx +208 -0
  31. package/src/file-trigger.tsx +103 -0
  32. package/src/form.tsx +18 -18
  33. package/src/gridlist.tsx +912 -121
  34. package/src/group.tsx +146 -0
  35. package/src/index.ts +402 -0
  36. package/src/interactions/focus-events.ts +13 -5
  37. package/src/interactions/keyboard.ts +195 -2
  38. package/src/interactions/modality.ts +18 -6
  39. package/src/interactions/open-link.ts +46 -13
  40. package/src/interactions/press.ts +35 -18
  41. package/src/label.ts +18 -6
  42. package/src/link.tsx +146 -50
  43. package/src/listbox.tsx +615 -89
  44. package/src/live.ts +4 -0
  45. package/src/menu.tsx +182 -89
  46. package/src/menubar.tsx +21 -17
  47. package/src/navigation-tree.tsx +357 -0
  48. package/src/numberfield.tsx +164 -60
  49. package/src/overlay-arrow.tsx +157 -0
  50. package/src/overlays.ts +364 -62
  51. package/src/platform.ts +2 -1
  52. package/src/preview-trigger.tsx +582 -0
  53. package/src/progress-bar-context.ts +15 -0
  54. package/src/questionnaire.tsx +109 -104
  55. package/src/radio.tsx +101 -27
  56. package/src/select.tsx +225 -145
  57. package/src/selection-indicator.tsx +74 -0
  58. package/src/selection.ts +73 -16
  59. package/src/shared-element-transition.tsx +316 -0
  60. package/src/sheet.tsx +1461 -0
  61. package/src/slider.tsx +139 -44
  62. package/src/switch.tsx +47 -21
  63. package/src/table.tsx +0 -0
  64. package/src/tabs.tsx +198 -89
  65. package/src/tag.tsx +217 -32
  66. package/src/textarea.tsx +186 -0
  67. package/src/textfield.tsx +103 -37
  68. package/src/toast-components.tsx +589 -0
  69. package/src/toggle-button-group.tsx +175 -0
  70. package/src/toggle-input.tsx +38 -0
  71. package/src/toggle.ts +68 -5
  72. package/src/tokenfield.tsx +1673 -0
  73. package/src/toolbar.tsx +15 -10
  74. package/src/tooltip.tsx +46 -29
  75. package/src/tree.tsx +2075 -0
  76. package/src/utils.ts +30 -1
  77. package/src/validation.ts +79 -22
  78. package/src/virtualizer.tsx +186 -23
package/src/select.tsx CHANGED
@@ -21,6 +21,7 @@
21
21
  */
22
22
 
23
23
  import {
24
+ cells,
24
25
  type Accessor,
25
26
  type Child,
26
27
  For,
@@ -41,6 +42,7 @@ import { resizeObserver } from "@barqjs/primitives/observers";
41
42
  import { ref as makeRef, mergeRefs, type RefTarget } from "@barqjs/primitives/refs";
42
43
  import { button, type ButtonOptions } from "./button.tsx";
43
44
  import type {
45
+ Collection,
44
46
  FocusStrategy,
45
47
  ItemAccessors,
46
48
  Key,
@@ -257,6 +259,8 @@ export interface SelectResult {
257
259
  validation: FormValidationState;
258
260
  errors: Accessor<string[]>;
259
261
  isInvalid: Accessor<boolean>;
262
+ /** The behaviour in force: the select's own, or the enclosing form's. */
263
+ validationBehavior: Accessor<ValidationBehavior | undefined>;
260
264
  }
261
265
 
262
266
  export function select(options: SelectOptions, state: SelectState<unknown>): SelectResult {
@@ -283,6 +287,7 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
283
287
 
284
288
  const {
285
289
  state: validation,
290
+ behavior,
286
291
  isInvalid,
287
292
  errors,
288
293
  errorMessage,
@@ -305,11 +310,18 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
305
310
  });
306
311
 
307
312
  // Typing on the CLOSED button moves the selection, as a native select does.
308
- const { typeSelectProps } = typeSelect({
309
- keyboardDelegate: delegate,
310
- selectionManager: state.selectionManager,
311
- onTypeSelect: (key) => state.setSelectedKey(key),
312
- });
313
+ const { typeSelectProps } = singleTypeSelect(delegate, state);
314
+
315
+ // With only an `aria-label`, the label lives on the trigger itself, and the
316
+ // value's id in `aria-labelledby` would replace it: the trigger joins the
317
+ // list so it keeps its own name.
318
+ const labelledBy = (): string | undefined => {
319
+ const given = access(fieldProps["aria-labelledby"] as MaybeAccessor<string | undefined>);
320
+ if (given !== undefined) return given;
321
+ return access(fieldProps["aria-label"] as MaybeAccessor<string | undefined>) === undefined
322
+ ? undefined
323
+ : triggerId();
324
+ };
313
325
 
314
326
  /**
315
327
  * Left and right step through the values WITHOUT opening.
@@ -339,6 +351,7 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
339
351
  validation,
340
352
  errors,
341
353
  isInvalid,
354
+ validationBehavior: behavior,
342
355
  valueProps: { id: valueId },
343
356
  labelProps: mergeProps(labelProps, {
344
357
  // Clicking the label focuses the button, as it would a native control.
@@ -358,10 +371,7 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
358
371
  "aria-invalid": () => isInvalid() || undefined,
359
372
  "aria-required": () => access(options.isRequired) === true || undefined,
360
373
  // The label FIRST and the value second: "Fruit, Banana", not "Banana".
361
- "aria-labelledby": () =>
362
- [access(fieldProps["aria-labelledby"] as MaybeAccessor<string | undefined>), valueId()]
363
- .filter(Boolean)
364
- .join(" "),
374
+ "aria-labelledby": () => [labelledBy(), valueId()].filter(Boolean).join(" "),
365
375
  onFocus: () => state.setFocused(true),
366
376
  onBlur: () => {
367
377
  // Focus inside the open popup is still focus on the select.
@@ -373,10 +383,7 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
373
383
  ),
374
384
  listBoxProps: {
375
385
  id: menuProps.id,
376
- "aria-labelledby": () =>
377
- [access(fieldProps["aria-labelledby"] as MaybeAccessor<string | undefined>), valueId()]
378
- .filter(Boolean)
379
- .join(" "),
386
+ "aria-labelledby": () => [labelledBy(), valueId()].filter(Boolean).join(" "),
380
387
  autoFocus: () => state.focusStrategy() ?? true,
381
388
  // A select's popup closes on choosing, so choosing on pointer DOWN would
382
389
  // consume the press that opened it.
@@ -387,6 +394,58 @@ export function select(options: SelectOptions, state: SelectState<unknown>): Sel
387
394
  };
388
395
  }
389
396
 
397
+ /**
398
+ * Typing on the closed trigger, which picks the match as a native select does.
399
+ *
400
+ * Not in multiple selection, where picking the match would replace every
401
+ * other choice with it.
402
+ */
403
+ function singleTypeSelect(
404
+ delegate: KeyboardDelegate,
405
+ state: SelectState<unknown>,
406
+ ): { typeSelectProps: DOMProps } {
407
+ const { typeSelectProps } = typeSelect({
408
+ keyboardDelegate: delegate,
409
+ selectionManager: state.selectionManager,
410
+ onTypeSelect: (key) => state.setSelectedKey(key),
411
+ });
412
+ const isSingle = (): boolean => state.selectionManager().selectionMode !== "multiple";
413
+ const onKeyDown = typeSelectProps.onKeyDown as (event: KeyboardEvent) => void;
414
+ const onKeyDownCapture = typeSelectProps.onKeyDownCapture as (event: KeyboardEvent) => void;
415
+ return {
416
+ typeSelectProps: {
417
+ onKeyDown: (event: KeyboardEvent) => {
418
+ if (isSingle()) onKeyDown(event);
419
+ },
420
+ onKeyDownCapture: (event: KeyboardEvent) => {
421
+ if (isSingle()) onKeyDownCapture(event);
422
+ },
423
+ },
424
+ };
425
+ }
426
+
427
+ /**
428
+ * Whether a select's hidden control belongs in the page: with a `name`, with
429
+ * `form`, or inside a form, where a required select with no name still has to
430
+ * hold back a native submit and only a control in the form can.
431
+ *
432
+ * The form is looked for once the trigger is attached; at the moment its ref
433
+ * resolves it has no ancestors yet.
434
+ */
435
+ function hiddenControlPresence(
436
+ triggerRef: Accessor<HTMLElement | null>,
437
+ name: Accessor<string | undefined>,
438
+ form: Accessor<string | undefined>,
439
+ ): { isNeeded: Accessor<boolean>; placed: () => void } {
440
+ const [isInsideForm, setInsideForm] = createSignal(false);
441
+ return {
442
+ isNeeded: () => name() !== undefined || form() !== undefined || isInsideForm(),
443
+ placed: () => {
444
+ setInsideForm((triggerRef()?.closest("form") ?? null) !== null);
445
+ },
446
+ };
447
+ }
448
+
390
449
  export interface HiddenSelectOptions {
391
450
  selectRef: ElementRef<HTMLSelectElement>;
392
451
  /**
@@ -492,7 +551,9 @@ export function hiddenSelect(
492
551
  tabIndex: -1,
493
552
  autocomplete: () => access(options.autoComplete),
494
553
  disabled: () => access(options.isDisabled) === true,
495
- required: () => access(options.isRequired) === true,
554
+ // Only a native select blocks the submit; under "aria" the page decides.
555
+ required: () =>
556
+ access(options.validationBehavior) === "native" && access(options.isRequired) === true,
496
557
  multiple: () => state.selectionManager().selectionMode === "multiple",
497
558
  name: () => access(options.name),
498
559
  form: () => access(options.form),
@@ -511,6 +572,15 @@ export function hiddenSelect(
511
572
  // Components
512
573
  // ---------------------------------------------------------------------------
513
574
 
575
+ function itemsOf<T>(collection: Collection<T>): Node<T>[] {
576
+ const items: Node<T>[] = [];
577
+ for (const key of collection.getKeys()) {
578
+ const node = collection.getItem(key);
579
+ if (node !== null && node.type === "item") items.push(node);
580
+ }
581
+ return items;
582
+ }
583
+
514
584
  interface SelectContextValue {
515
585
  state: SelectState<unknown>;
516
586
  valueProps: DOMProps;
@@ -549,17 +619,17 @@ const ITEM_TEXT_ATTRIBUTE = "data-barq-item-text";
549
619
  * shown here as it is drawn there: a COPY of its {@link SelectItemText}, since
550
620
  * one node cannot be in the list and in the trigger at once.
551
621
  */
552
- export function SelectValue(props: Incoming<SelectValueComponentProps>) {
622
+ export function SelectValue(props: SelectValueComponentProps) {
553
623
  const picker = useSelect();
554
- const placeholder = (): string => props.placeholder?.() ?? picker.placeholder() ?? "";
624
+ const placeholder = (): string => props.placeholder ?? picker.placeholder() ?? "";
555
625
 
556
626
  const elementProps = mergeProps(
557
627
  picker.valueProps,
558
- filterDOMProps(fromProps(props), { global: true }),
559
- styleProps(props),
628
+ filterDOMProps(fromProps(cells(props)), { global: true }),
629
+ styleProps(cells(props)),
560
630
  {
561
631
  "data-placeholder": () => picker.state.selectedItem() === null,
562
- "data-testid": () => props["data-testid"]?.(),
632
+ "data-testid": () => props["data-testid"],
563
633
  },
564
634
  );
565
635
 
@@ -604,6 +674,11 @@ export interface SelectComponentProps<T> extends StyleProps, ItemAccessors<T> {
604
674
  placeholder?: string;
605
675
  selectedKey?: Key | null;
606
676
  defaultSelectedKey?: Key | null;
677
+ /** @default "single" */
678
+ selectionMode?: "single" | "multiple";
679
+ /** Every chosen key, for a multiple select. */
680
+ selectedKeys?: Iterable<Key>;
681
+ defaultSelectedKeys?: Iterable<Key>;
607
682
  disabledKeys?: Iterable<Key>;
608
683
  isOpen?: boolean;
609
684
  defaultOpen?: boolean;
@@ -614,7 +689,10 @@ export interface SelectComponentProps<T> extends StyleProps, ItemAccessors<T> {
614
689
  validate?: ValidateFunction<Key | Key[] | null>;
615
690
  /** @default "aria" */
616
691
  validationBehavior?: ValidationBehavior;
617
- /** Submitted with the form. Without it, no hidden control is rendered. */
692
+ /**
693
+ * Submitted with the form. Without it, the hidden control is rendered only
694
+ * inside a form or with `form`, where it still carries `isRequired`.
695
+ */
618
696
  name?: string;
619
697
  form?: string;
620
698
  autoComplete?: string;
@@ -642,6 +720,8 @@ export interface SelectComponentProps<T> extends StyleProps, ItemAccessors<T> {
642
720
  "aria-labelledby"?: string;
643
721
  ref?: RefTarget<HTMLButtonElement>;
644
722
  onSelectionChange?: (key: Key | null) => void;
723
+ /** Every chosen key, for a multiple select. */
724
+ onSelectionChangeAll?: (keys: SelectionValue) => void;
645
725
  onOpenChange?: (isOpen: boolean) => void;
646
726
  }
647
727
 
@@ -653,15 +733,15 @@ export interface SelectComponentProps<T> extends StyleProps, ItemAccessors<T> {
653
733
  * </Select>
654
734
  * ```
655
735
  */
656
- export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
736
+ export function Select<T>(props: SelectComponentProps<T>) {
657
737
  const triggerRef = makeRef<HTMLButtonElement>();
658
738
  const listRef = makeRef<HTMLUListElement>();
659
739
  const selectRef = makeRef<HTMLSelectElement>();
660
- const options = fromProps(props as unknown as Incoming<Record<string, unknown>>);
740
+ const options = fromProps(cells(props) as unknown as Incoming<Record<string, unknown>>);
661
741
 
662
742
  const state = selectState<T>({
663
743
  ...(options as SelectStateOptions<T>),
664
- onSelectionChange: (key) => props.onSelectionChange?.()?.(key),
744
+ onSelectionChange: (key) => props.onSelectionChange?.(key),
665
745
  });
666
746
 
667
747
  const {
@@ -674,12 +754,13 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
674
754
  errors,
675
755
  isInvalid,
676
756
  validation,
757
+ validationBehavior,
677
758
  } = select(
678
759
  {
679
760
  ...(options as unknown as SelectOptions),
680
761
  ref: triggerRef,
681
- validate: callback(props.validate),
682
- validationBehavior: () => props.validationBehavior?.(),
762
+ validate: callback(cells(props).validate),
763
+ validationBehavior: () => props.validationBehavior,
683
764
  },
684
765
  state,
685
766
  );
@@ -688,7 +769,7 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
688
769
  { ...(options as ButtonOptions), ...triggerProps },
689
770
  triggerRef,
690
771
  );
691
- const { hoverProps, isHovered } = hover({ isDisabled: () => props.isDisabled?.() });
772
+ const { hoverProps, isHovered } = hover({ isDisabled: () => props.isDisabled });
692
773
  const { focusProps, isFocusVisible } = focusRing();
693
774
 
694
775
  const buttonElementProps = mergeProps(
@@ -700,17 +781,17 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
700
781
  hoverProps,
701
782
  focusProps,
702
783
  filterDOMProps(options, { global: true }),
703
- styleProps(props),
784
+ styleProps(cells(props)),
704
785
  {
705
786
  "data-pressed": isPressed,
706
787
  "data-hovered": isHovered,
707
788
  "data-focus-visible": isFocusVisible,
708
789
  "data-open": state.isOpen,
709
790
  "data-state": () => (state.isOpen() ? "open" : "closed"),
710
- "data-disabled": () => props.isDisabled?.() === true,
791
+ "data-disabled": () => props.isDisabled === true,
711
792
  "data-placeholder": () => state.selectedItem() === null,
712
793
  "data-invalid": isInvalid,
713
- "data-testid": () => props["data-testid"]?.(),
794
+ "data-testid": () => props["data-testid"],
714
795
  },
715
796
  );
716
797
 
@@ -718,17 +799,24 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
718
799
  {
719
800
  selectRef,
720
801
  triggerRef,
721
- name: () => props.name?.(),
722
- form: () => props.form?.(),
723
- autoComplete: () => props.autoComplete?.(),
724
- isDisabled: () => props.isDisabled?.(),
725
- isRequired: () => props.isRequired?.(),
726
- validationBehavior: () => props.validationBehavior?.(),
802
+ name: () => props.name,
803
+ form: () => props.form,
804
+ autoComplete: () => props.autoComplete,
805
+ isDisabled: () => props.isDisabled,
806
+ isRequired: () => props.isRequired,
807
+ validationBehavior,
727
808
  validation,
728
809
  },
729
810
  state,
730
811
  );
731
812
 
813
+ const formControl = hiddenControlPresence(
814
+ triggerRef,
815
+ () => props.name,
816
+ () => props.form,
817
+ );
818
+ onSettled(formControl.placed);
819
+
732
820
  const renderOption = props.children;
733
821
 
734
822
  const owner = getOwner();
@@ -736,42 +824,44 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
736
824
  install(owner, SelectContext, () => ({
737
825
  state: state as unknown as SelectState<unknown>,
738
826
  valueProps,
739
- placeholder: () => props.placeholder?.(),
827
+ placeholder: () => props.placeholder,
740
828
  }));
741
829
  }
742
830
 
743
831
  return (
744
832
  <>
745
833
  <span {...labelProps}>{props.label}</span>
746
- <button {...buttonElementProps} ref={mergeRefs(triggerRef.set, props.ref?.())}>
834
+ <button {...buttonElementProps} ref={mergeRefs(triggerRef.set, props.ref)}>
747
835
  <SelectValue />
748
836
  </button>
749
- {() =>
750
- props.name?.() === undefined ? null : (
751
- <div {...containerProps}>
752
- <label>
753
- {props.label}
754
- <select {...selectProps} ref={selectRef.set}>
755
- <option value="" label="&nbsp;" />
756
- <For each={() => [...state.collection()].filter((node) => node.type === "item")}>
757
- {(node: Node<T>) => <option value={String(node.key)}>{node.textValue}</option>}
758
- </For>
759
- </select>
760
- </label>
761
- </div>
762
- )
763
- }
837
+ <Show when={formControl.isNeeded()}>
838
+ <div {...containerProps}>
839
+ <label>
840
+ {/* Text only: an element can be in one place, and it belongs in
841
+ the visible label that names the trigger. */}
842
+ {() => (typeof props.label === "string" ? props.label : null)}
843
+ <select {...selectProps} ref={selectRef.set}>
844
+ <option value="" label="&nbsp;" />
845
+ {/* Every item, whichever section holds it: the top level of a
846
+ sectioned collection is its sections. */}
847
+ <For each={() => itemsOf(state.collection())}>
848
+ {(node: Node<T>) => <option value={String(node.key)}>{node.textValue}</option>}
849
+ </For>
850
+ </select>
851
+ </label>
852
+ </div>
853
+ </Show>
764
854
  <Popover
765
855
  triggerRef={triggerRef}
766
856
  isOpen={state.isOpen()}
767
857
  onOpenChange={state.setOpen}
768
- placement={props.placement?.() ?? "bottom start"}
858
+ placement={props.placement ?? "bottom start"}
769
859
  >
770
860
  <SelectList
771
861
  options={listBoxOptions}
772
- ariaLabel={props["aria-label"]?.()}
773
- listClass={props.listClass?.()}
774
- listSlot={props.listSlot?.()}
862
+ ariaLabel={props["aria-label"]}
863
+ listClass={props.listClass}
864
+ listSlot={props.listSlot}
775
865
  state={state}
776
866
  listRef={listRef}
777
867
  render={renderOption as unknown as (item: unknown) => Child}
@@ -780,7 +870,7 @@ export function Select<T>(props: Incoming<SelectComponentProps<T>>) {
780
870
  <span {...descriptionProps}>{props.description}</span>
781
871
  <span {...errorMessageProps}>
782
872
  {() => {
783
- const given = props.errorMessage?.();
873
+ const given = props.errorMessage;
784
874
  if (given !== undefined && given !== null && given !== "") return given;
785
875
  const found = errors();
786
876
  return found.length === 0 ? null : found.join(" ");
@@ -808,17 +898,17 @@ interface SelectListProps {
808
898
  * reading it before the popover opened would always find the strategy unset
809
899
  * and land focus on the list instead of on an option.
810
900
  */
811
- function SelectList(props: Incoming<SelectListProps>) {
812
- const state = props.state();
813
- const listRef = props.listRef();
814
- const render = props.render();
815
- const options = props.options();
901
+ function SelectList(props: SelectListProps) {
902
+ const state = props.state;
903
+ const listRef = props.listRef;
904
+ const render = props.render;
905
+ const options = props.options;
816
906
 
817
907
  const { listBoxProps, baseId } = listBox(
818
908
  {
819
909
  ...(options as unknown as Record<string, MaybeAccessor<never>>),
820
910
  ref: listRef,
821
- "aria-label": props.ariaLabel,
911
+ "aria-label": cells(props).ariaLabel,
822
912
  },
823
913
  state,
824
914
  );
@@ -826,8 +916,8 @@ function SelectList(props: Incoming<SelectListProps>) {
826
916
  const elementProps = mergeProps(listBoxProps, popoverStateProps(), {
827
917
  id: options.id,
828
918
  "aria-labelledby": options["aria-labelledby"],
829
- class: props.listClass,
830
- "data-slot": () => props.listSlot?.() ?? "select-list",
919
+ class: cells(props).listClass,
920
+ "data-slot": () => props.listSlot ?? "select-list",
831
921
  });
832
922
 
833
923
  provideItemRender(render);
@@ -963,11 +1053,7 @@ export function selectTrigger(
963
1053
  state,
964
1054
  );
965
1055
 
966
- const { typeSelectProps } = typeSelect({
967
- keyboardDelegate: delegate,
968
- selectionManager: state.selectionManager,
969
- onTypeSelect: (key) => state.setSelectedKey(key),
970
- });
1056
+ const { typeSelectProps } = singleTypeSelect(delegate, state);
971
1057
 
972
1058
  return {
973
1059
  triggerProps: mergeProps(
@@ -1021,27 +1107,27 @@ export interface SelectRootComponentProps {
1021
1107
  }
1022
1108
 
1023
1109
  /** The state of a select written as parts. Renders no element of its own. */
1024
- export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1110
+ export function SelectRoot(props: SelectRootComponentProps) {
1025
1111
  const triggerRef = makeRef<HTMLButtonElement>();
1026
1112
  const valueRef = makeRef<HTMLSpanElement>();
1027
1113
  const selectRef = makeRef<HTMLSelectElement>();
1028
1114
  const registry = staticCollection();
1029
1115
  const baseId = id();
1030
- const isDisabled = (): boolean => props.isDisabled?.() === true;
1116
+ const isDisabled = (): boolean => props.isDisabled === true;
1031
1117
 
1032
1118
  const state = selectState<StaticEntry>({
1033
1119
  items: registry.entries,
1034
1120
  ...staticAccessors,
1035
- selectedKey: () => props.selectedKey?.(),
1036
- defaultSelectedKey: () => props.defaultSelectedKey?.(),
1037
- isOpen: () => props.isOpen?.(),
1038
- defaultOpen: () => props.defaultOpen?.(),
1039
- onOpenChange: (isOpen) => props.onOpenChange?.()?.(isOpen),
1040
- onSelectionChange: (key) => props.onSelectionChange?.()?.(key),
1121
+ selectedKey: () => props.selectedKey,
1122
+ defaultSelectedKey: () => props.defaultSelectedKey,
1123
+ isOpen: () => props.isOpen,
1124
+ defaultOpen: () => props.defaultOpen,
1125
+ onOpenChange: (isOpen) => props.onOpenChange?.(isOpen),
1126
+ onSelectionChange: (key) => props.onSelectionChange?.(key),
1041
1127
  }) as unknown as SelectState<unknown>;
1042
1128
 
1043
1129
  const { triggerProps, comboboxProps, listBoxProps } = selectTrigger(
1044
- { ref: triggerRef, isDisabled, isRequired: () => props.isRequired?.() },
1130
+ { ref: triggerRef, isDisabled, isRequired: () => props.isRequired },
1045
1131
  state,
1046
1132
  );
1047
1133
 
@@ -1051,7 +1137,7 @@ export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1051
1137
  const { state: validation, isInvalid } = fieldValidation<Key | Key[] | null>({
1052
1138
  value: state.value,
1053
1139
  validationBehavior: "native",
1054
- name: () => props.name?.(),
1140
+ name: () => props.name,
1055
1141
  });
1056
1142
 
1057
1143
  // The hidden control's options, written onto it rather than rendered into
@@ -1066,9 +1152,7 @@ export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1066
1152
  while (element.options.length > 1) element.remove(1);
1067
1153
  // By key rather than by walking the top level, which holds the GROUPS: a
1068
1154
  // native `<select>` wants every option, whichever group it was written in.
1069
- for (const key of collection.getKeys()) {
1070
- const node = collection.getItem(key);
1071
- if (node === null || node.type !== "item") continue;
1155
+ for (const node of itemsOf(collection)) {
1072
1156
  const option = element.ownerDocument.createElement("option");
1073
1157
  option.value = String(node.key);
1074
1158
  option.textContent = node.textValue;
@@ -1081,22 +1165,22 @@ export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1081
1165
  {
1082
1166
  selectRef,
1083
1167
  triggerRef,
1084
- name: () => props.name?.(),
1085
- form: () => props.form?.(),
1086
- autoComplete: () => props.autoComplete?.(),
1168
+ name: () => props.name,
1169
+ form: () => props.form,
1170
+ autoComplete: () => props.autoComplete,
1087
1171
  isDisabled,
1088
- isRequired: () => props.isRequired?.(),
1172
+ isRequired: () => props.isRequired,
1089
1173
  validationBehavior: "native",
1090
1174
  validation,
1091
1175
  },
1092
1176
  state,
1093
1177
  );
1094
1178
 
1095
- // Asked once the trigger is attached: at the moment its ref resolves it has
1096
- // no ancestors yet, and no form to find.
1097
- const [isInsideForm, setInsideForm] = createSignal(false);
1098
- const inForm = (): boolean =>
1099
- props.name?.() !== undefined || props.form?.() !== undefined || isInsideForm();
1179
+ const formControl = hiddenControlPresence(
1180
+ triggerRef,
1181
+ () => props.name,
1182
+ () => props.form,
1183
+ );
1100
1184
 
1101
1185
  const value: SelectContextValue = {
1102
1186
  state,
@@ -1112,10 +1196,8 @@ export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1112
1196
  baseId,
1113
1197
  isDisabled,
1114
1198
  isInvalid,
1115
- dir: () => props.dir?.(),
1116
- placed: () => {
1117
- setInsideForm((triggerRef()?.closest("form") ?? null) !== null);
1118
- },
1199
+ dir: () => props.dir,
1200
+ placed: formControl.placed,
1119
1201
  },
1120
1202
  };
1121
1203
 
@@ -1128,7 +1210,7 @@ export function SelectRoot(props: Incoming<SelectRootComponentProps>) {
1128
1210
  () => props.children as unknown,
1129
1211
  ) as Child
1130
1212
  }
1131
- <Show when={inForm()}>
1213
+ <Show when={formControl.isNeeded()}>
1132
1214
  <div {...containerProps}>
1133
1215
  <select {...selectProps} ref={selectRef.set}>
1134
1216
  <option value="" label="&nbsp;" />
@@ -1152,23 +1234,23 @@ export interface SelectTriggerComponentProps extends StyleProps {
1152
1234
  }
1153
1235
 
1154
1236
  /** The control that shows the value and opens the list. */
1155
- export function SelectTrigger(props: Incoming<SelectTriggerComponentProps>) {
1237
+ export function SelectTrigger(props: SelectTriggerComponentProps) {
1156
1238
  const picker = useSelectParts("SelectTrigger");
1157
1239
  const { parts, state } = picker;
1158
- const isDisabled = (): boolean => parts.isDisabled() || props.isDisabled?.() === true;
1240
+ const isDisabled = (): boolean => parts.isDisabled() || props.isDisabled === true;
1159
1241
  const isInvalid = (): boolean => {
1160
- const given = props["aria-invalid"]?.();
1242
+ const given = props["aria-invalid"];
1161
1243
  return given === undefined ? parts.isInvalid() : given === true || given === "true";
1162
1244
  };
1163
1245
 
1164
- const options = fromProps(props);
1246
+ const options = fromProps(cells(props));
1165
1247
  const { buttonProps, isPressed } = button(
1166
1248
  {
1167
1249
  ...(parts.triggerProps as ButtonOptions),
1168
1250
  isDisabled,
1169
- "aria-label": () => props["aria-label"]?.(),
1170
- "aria-labelledby": () => props["aria-labelledby"]?.(),
1171
- "aria-describedby": () => props["aria-describedby"]?.(),
1251
+ "aria-label": () => props["aria-label"],
1252
+ "aria-labelledby": () => props["aria-labelledby"],
1253
+ "aria-describedby": () => props["aria-describedby"],
1172
1254
  "aria-invalid": isInvalid,
1173
1255
  },
1174
1256
  parts.triggerRef,
@@ -1184,10 +1266,10 @@ export function SelectTrigger(props: Incoming<SelectTriggerComponentProps>) {
1184
1266
  hoverProps,
1185
1267
  focusProps,
1186
1268
  filterDOMProps(options, { global: true }),
1187
- styleProps(props),
1269
+ styleProps(cells(props)),
1188
1270
  {
1189
1271
  // A caller's `id` is what a `<label for>` points at, and it wins.
1190
- id: () => props.id?.() ?? access(parts.comboboxProps.id as MaybeAccessor<string>),
1272
+ id: () => props.id ?? access(parts.comboboxProps.id as MaybeAccessor<string>),
1191
1273
  dir: () => parts.dir(),
1192
1274
  "data-state": () => (state.isOpen() ? "open" : "closed"),
1193
1275
  "data-open": state.isOpen,
@@ -1197,12 +1279,12 @@ export function SelectTrigger(props: Incoming<SelectTriggerComponentProps>) {
1197
1279
  "data-disabled": isDisabled,
1198
1280
  "data-placeholder": () => state.selectedItem() === null,
1199
1281
  "data-invalid": isInvalid,
1200
- "data-testid": () => props["data-testid"]?.(),
1282
+ "data-testid": () => props["data-testid"],
1201
1283
  },
1202
1284
  );
1203
1285
 
1204
1286
  return (
1205
- <button {...elementProps} ref={mergeRefs(parts.triggerRef.set, props.ref?.())}>
1287
+ <button {...elementProps} ref={mergeRefs(parts.triggerRef.set, props.ref)}>
1206
1288
  {props.children}
1207
1289
  </button>
1208
1290
  );
@@ -1296,10 +1378,10 @@ function useSelectContent(part: string): SelectContentValue {
1296
1378
  return value;
1297
1379
  }
1298
1380
 
1299
- function SelectContentProvider(props: Incoming<{ value: SelectContentValue; children?: Child }>) {
1381
+ function SelectContentProvider(props: { value: SelectContentValue; children?: Child }) {
1300
1382
  return provide(
1301
1383
  SelectContentContext,
1302
- () => props.value(),
1384
+ () => props.value,
1303
1385
  () => props.children as unknown,
1304
1386
  );
1305
1387
  }
@@ -1345,7 +1427,7 @@ function laidOutBox(element: Element | null): Box | null {
1345
1427
  * The listbox itself is the {@link SelectViewport} inside, so the scroll
1346
1428
  * buttons beside it are not children of a `role="listbox"`.
1347
1429
  */
1348
- export function SelectContent(props: Incoming<SelectContentComponentProps>) {
1430
+ export function SelectContent(props: SelectContentComponentProps) {
1349
1431
  const { parts, state } = useSelectParts("SelectContent");
1350
1432
  const locale = useLocale();
1351
1433
  const viewportRef = makeRef<HTMLUListElement>();
@@ -1371,7 +1453,7 @@ export function SelectContent(props: Incoming<SelectContentComponentProps>) {
1371
1453
  };
1372
1454
 
1373
1455
  const align = (): void => {
1374
- if (props.position?.() !== "item-aligned") return;
1456
+ if (props.position !== "item-aligned") return;
1375
1457
  const trigger = parts.triggerRef();
1376
1458
  const content = contentRef();
1377
1459
  const key = state.selectedKey();
@@ -1418,23 +1500,23 @@ export function SelectContent(props: Incoming<SelectContentComponentProps>) {
1418
1500
  align();
1419
1501
  measure();
1420
1502
  },
1421
- ariaLabel: () => props["aria-label"]?.(),
1422
- ariaLabelledBy: () => props["aria-labelledby"]?.(),
1503
+ ariaLabel: () => props["aria-label"],
1504
+ ariaLabelledBy: () => props["aria-labelledby"],
1423
1505
  };
1424
1506
 
1425
- const options = fromProps(props);
1507
+ const options = fromProps(cells(props));
1426
1508
  const elementProps = mergeProps(
1427
1509
  filterDOMProps(options, { global: true, labelable: true }),
1428
- styleProps(props),
1510
+ styleProps(cells(props)),
1429
1511
  {
1430
1512
  role: "presentation",
1431
1513
  dir: () => parts.dir(),
1432
- "data-position": () => props.position?.() ?? "popper",
1514
+ "data-position": () => props.position ?? "popper",
1433
1515
  // Said of what was ASKED for, so a design system can drop its entrance
1434
1516
  // animation before the first frame: the list is measured as it is drawn,
1435
1517
  // and a scale on it would be measured too.
1436
- "data-align-trigger": () => String(props.position?.() === "item-aligned"),
1437
- "data-testid": () => props["data-testid"]?.(),
1518
+ "data-align-trigger": () => String(props.position === "item-aligned"),
1519
+ "data-testid": () => props["data-testid"],
1438
1520
  },
1439
1521
  );
1440
1522
 
@@ -1452,15 +1534,15 @@ export function SelectContent(props: Incoming<SelectContentComponentProps>) {
1452
1534
  triggerRef={parts.triggerRef}
1453
1535
  isOpen={state.isOpen()}
1454
1536
  onOpenChange={state.setOpen}
1455
- placement={aligned() === null ? (props.placement?.() ?? "bottom start") : "bottom start"}
1456
- offset={aligned()?.offset ?? props.offset?.() ?? 8}
1457
- crossOffset={aligned()?.crossOffset ?? props.crossOffset?.()}
1537
+ placement={aligned() === null ? (props.placement ?? "bottom start") : "bottom start"}
1538
+ offset={aligned()?.offset ?? props.offset ?? 8}
1539
+ crossOffset={aligned()?.crossOffset ?? props.crossOffset}
1458
1540
  shouldFlip={aligned() === null}
1459
1541
  >
1460
1542
  <SelectContentBox
1461
1543
  elementProps={elementProps}
1462
1544
  contentRef={contentRef}
1463
- forwardedRef={props.ref?.()}
1545
+ forwardedRef={props.ref}
1464
1546
  value={showing}
1465
1547
  >
1466
1548
  {props.children}
@@ -1479,14 +1561,14 @@ interface SelectContentBoxProps {
1479
1561
  }
1480
1562
 
1481
1563
  /** Inside the popover, which is the only place its side and state can be read. */
1482
- function SelectContentBox(props: Incoming<SelectContentBoxProps>) {
1564
+ function SelectContentBox(props: SelectContentBoxProps) {
1483
1565
  return (
1484
1566
  <div
1485
- {...props.elementProps()}
1567
+ {...props.elementProps}
1486
1568
  {...popoverStateProps()}
1487
- ref={mergeRefs(props.contentRef().set, props.forwardedRef?.())}
1569
+ ref={mergeRefs(props.contentRef.set, props.forwardedRef)}
1488
1570
  >
1489
- <SelectContentProvider value={props.value()}>{props.children}</SelectContentProvider>
1571
+ <SelectContentProvider value={props.value}>{props.children}</SelectContentProvider>
1490
1572
  </div>
1491
1573
  );
1492
1574
  }
@@ -1497,7 +1579,7 @@ export interface SelectViewportComponentProps extends StyleProps {
1497
1579
  }
1498
1580
 
1499
1581
  /** The listbox: the scroller the options are in. */
1500
- export function SelectViewport(props: Incoming<SelectViewportComponentProps>) {
1582
+ export function SelectViewport(props: SelectViewportComponentProps) {
1501
1583
  const { parts, state } = useSelectParts("SelectViewport");
1502
1584
  const content = useSelectContent("SelectViewport");
1503
1585
 
@@ -1535,8 +1617,8 @@ export function SelectViewport(props: Incoming<SelectViewportComponentProps>) {
1535
1617
 
1536
1618
  const elementProps = mergeProps(
1537
1619
  listBoxProps,
1538
- filterDOMProps(fromProps(props), { global: true }),
1539
- styleProps(props),
1620
+ filterDOMProps(fromProps(cells(props)), { global: true }),
1621
+ styleProps(cells(props)),
1540
1622
  {
1541
1623
  id: options.id,
1542
1624
  "aria-labelledby": () =>
@@ -1545,7 +1627,7 @@ export function SelectViewport(props: Incoming<SelectViewportComponentProps>) {
1545
1627
  ? access(options["aria-labelledby"] as MaybeAccessor<string>)
1546
1628
  : undefined),
1547
1629
  onScroll: content.measure,
1548
- "data-testid": () => props["data-testid"]?.(),
1630
+ "data-testid": () => props["data-testid"],
1549
1631
  },
1550
1632
  );
1551
1633
 
@@ -1575,11 +1657,11 @@ export interface SelectItemTextComponentProps extends StyleProps {
1575
1657
  *
1576
1658
  * Everything else in the row, a tick or a shortcut, stays in the row.
1577
1659
  */
1578
- export function SelectItemText(props: Incoming<SelectItemTextComponentProps>) {
1660
+ export function SelectItemText(props: SelectItemTextComponentProps) {
1579
1661
  const elementProps = mergeProps(
1580
- filterDOMProps(fromProps(props), { global: true }),
1581
- styleProps(props),
1582
- { [ITEM_TEXT_ATTRIBUTE]: "", "data-testid": () => props["data-testid"]?.() },
1662
+ filterDOMProps(fromProps(cells(props)), { global: true }),
1663
+ styleProps(cells(props)),
1664
+ { [ITEM_TEXT_ATTRIBUTE]: "", "data-testid": () => props["data-testid"] },
1583
1665
  );
1584
1666
  return <span {...elementProps}>{props.children}</span>;
1585
1667
  }
@@ -1601,12 +1683,12 @@ const SCROLL_INTERVAL = 50;
1601
1683
  * moving through it, so the arrow is a pointer's convenience and nothing a
1602
1684
  * screen reader user needs to find.
1603
1685
  */
1604
- export function SelectScrollButton(props: Incoming<SelectScrollButtonComponentProps>) {
1686
+ export function SelectScrollButton(props: SelectScrollButtonComponentProps) {
1605
1687
  useSelectParts("SelectScrollButton");
1606
1688
  const content = useSelectContent("SelectScrollButton");
1607
1689
  if (content.isRegistering) return null;
1608
1690
 
1609
- const isUp = props.direction() === "up";
1691
+ const isUp = props.direction === "up";
1610
1692
  let timer: ReturnType<typeof setInterval> | undefined;
1611
1693
 
1612
1694
  const stop = (): void => {
@@ -1630,14 +1712,14 @@ export function SelectScrollButton(props: Incoming<SelectScrollButtonComponentPr
1630
1712
  onCleanup(stop);
1631
1713
 
1632
1714
  const elementProps = mergeProps(
1633
- filterDOMProps(fromProps(props), { global: true }),
1634
- styleProps(props),
1715
+ filterDOMProps(fromProps(cells(props)), { global: true }),
1716
+ styleProps(cells(props)),
1635
1717
  {
1636
1718
  "aria-hidden": "true",
1637
1719
  onPointerDown: start,
1638
1720
  onPointerMove: start,
1639
1721
  onPointerLeave: stop,
1640
- "data-testid": () => props["data-testid"]?.(),
1722
+ "data-testid": () => props["data-testid"],
1641
1723
  },
1642
1724
  );
1643
1725
 
@@ -1655,11 +1737,9 @@ export function SelectScrollButton(props: Incoming<SelectScrollButtonComponentPr
1655
1737
  * goes the moment the list reaches its end, with the pointer still over it and
1656
1738
  * no `pointerleave` to say so.
1657
1739
  */
1658
- function ScrollButton(
1659
- props: Incoming<{ elementProps: DOMProps; onLeave: () => void; children?: Child }>,
1660
- ) {
1661
- onCleanup(() => props.onLeave()());
1662
- return <div {...props.elementProps()}>{props.children}</div>;
1740
+ function ScrollButton(props: { elementProps: DOMProps; onLeave: () => void; children?: Child }) {
1741
+ onCleanup(() => props.onLeave());
1742
+ return <div {...props.elementProps}>{props.children}</div>;
1663
1743
  }
1664
1744
 
1665
1745
  export { Option };