@plexui/vue 0.41.1 → 0.42.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 (87) hide show
  1. package/dist/es/components/Accordion/Accordion.js +18 -0
  2. package/dist/es/components/Accordion/Accordion.js.map +1 -1
  3. package/dist/es/components/Button/NavigationButton.js +13 -2
  4. package/dist/es/components/Button/NavigationButton.js.map +1 -1
  5. package/dist/es/components/Dialog/Dialog.js +47 -3
  6. package/dist/es/components/Dialog/Dialog.js.map +1 -1
  7. package/dist/es/components/Dialog/sheetDrag.js +45 -12
  8. package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
  9. package/dist/es/components/Field/Field.js +32 -3
  10. package/dist/es/components/Field/Field.js.map +1 -1
  11. package/dist/es/components/Icon/svg/Array.js +4 -4
  12. package/dist/es/components/Icon/svg/Array.js.map +1 -1
  13. package/dist/es/components/Icon/svg/Boolean.js +4 -4
  14. package/dist/es/components/Icon/svg/Boolean.js.map +1 -1
  15. package/dist/es/components/Icon/svg/Clipboard.js +4 -4
  16. package/dist/es/components/Icon/svg/Clipboard.js.map +1 -1
  17. package/dist/es/components/Icon/svg/Comment.js +4 -4
  18. package/dist/es/components/Icon/svg/Comment.js.map +1 -1
  19. package/dist/es/components/Icon/svg/Error.js +4 -4
  20. package/dist/es/components/Icon/svg/Error.js.map +1 -1
  21. package/dist/es/components/Icon/svg/Function.js +4 -4
  22. package/dist/es/components/Icon/svg/Function.js.map +1 -1
  23. package/dist/es/components/Icon/svg/Number.js +4 -4
  24. package/dist/es/components/Icon/svg/Number.js.map +1 -1
  25. package/dist/es/components/Icon/svg/Object.js +4 -4
  26. package/dist/es/components/Icon/svg/Object.js.map +1 -1
  27. package/dist/es/components/Icon/svg/Report.js +4 -4
  28. package/dist/es/components/Icon/svg/Report.js.map +1 -1
  29. package/dist/es/components/Icon/svg/Storage.js +4 -4
  30. package/dist/es/components/Icon/svg/Storage.js.map +1 -1
  31. package/dist/es/components/Icon/svg/String.js +4 -4
  32. package/dist/es/components/Icon/svg/String.js.map +1 -1
  33. package/dist/es/components/Icon/svg/Text.js +4 -4
  34. package/dist/es/components/Icon/svg/Text.js.map +1 -1
  35. package/dist/es/components/Menu/Menu.js +29 -2
  36. package/dist/es/components/Menu/Menu.js.map +1 -1
  37. package/dist/es/components/PlexUIProvider/PlexUIProvider.js +43 -3
  38. package/dist/es/components/PlexUIProvider/PlexUIProvider.js.map +1 -1
  39. package/dist/es/components/PlexUIProvider/androidRipple.js +98 -0
  40. package/dist/es/components/PlexUIProvider/androidRipple.js.map +1 -0
  41. package/dist/es/components/PlexUIProvider/index.js.map +1 -1
  42. package/dist/es/components/Select/Select.js +364 -22
  43. package/dist/es/components/Select/Select.js.map +1 -1
  44. package/dist/es/components/Sidebar/Sidebar.js +8 -1
  45. package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
  46. package/dist/es/components/Sidebar/index.js +1 -1
  47. package/dist/es/components/Sidebar/index.js.map +1 -1
  48. package/dist/es/components/Toolbar/Toolbar.js +276 -17
  49. package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
  50. package/dist/es/components/Toolbar/index.js.map +1 -1
  51. package/dist/es/lib/accordionMotion.js +144 -0
  52. package/dist/es/lib/accordionMotion.js.map +1 -0
  53. package/dist/es/lib/fieldRow.js +54 -0
  54. package/dist/es/lib/fieldRow.js.map +1 -1
  55. package/dist/es/lib/presentMotion.js +151 -0
  56. package/dist/es/lib/presentMotion.js.map +1 -0
  57. package/dist/types/components/Button/NavigationButton.d.ts +30 -1
  58. package/dist/types/components/ContextMenu/ContextMenu.d.ts +8 -8
  59. package/dist/types/components/Field/Field.d.ts +12 -2
  60. package/dist/types/components/FloatingLabelSelect/FloatingLabelSelect.d.ts +1 -1
  61. package/dist/types/components/Icon/svg/Array.d.ts +2 -2
  62. package/dist/types/components/Icon/svg/Boolean.d.ts +2 -2
  63. package/dist/types/components/Icon/svg/Clipboard.d.ts +2 -2
  64. package/dist/types/components/Icon/svg/Comment.d.ts +2 -2
  65. package/dist/types/components/Icon/svg/Error.d.ts +2 -2
  66. package/dist/types/components/Icon/svg/Function.d.ts +2 -2
  67. package/dist/types/components/Icon/svg/Number.d.ts +2 -2
  68. package/dist/types/components/Icon/svg/Object.d.ts +2 -2
  69. package/dist/types/components/Icon/svg/Report.d.ts +2 -2
  70. package/dist/types/components/Icon/svg/Storage.d.ts +2 -2
  71. package/dist/types/components/Icon/svg/String.d.ts +2 -2
  72. package/dist/types/components/Icon/svg/Text.d.ts +2 -2
  73. package/dist/types/components/PlexUIProvider/PlexUIProvider.d.ts +20 -3
  74. package/dist/types/components/PlexUIProvider/androidRipple.d.ts +9 -0
  75. package/dist/types/components/PlexUIProvider/index.d.ts +1 -1
  76. package/dist/types/components/Select/Select.d.ts +51 -0
  77. package/dist/types/components/Sidebar/Sidebar.d.ts +20 -0
  78. package/dist/types/components/Sidebar/index.d.ts +2 -2
  79. package/dist/types/components/Sidebar/useSidebarContext.d.ts +1 -1
  80. package/dist/types/components/TabBar/TabBar.d.ts +4 -4
  81. package/dist/types/components/Toast/Toaster.d.ts +1 -1
  82. package/dist/types/components/Toolbar/Toolbar.d.ts +49 -12
  83. package/dist/types/components/Toolbar/index.d.ts +1 -1
  84. package/dist/types/lib/accordionMotion.d.ts +20 -0
  85. package/dist/types/lib/fieldRow.d.ts +12 -0
  86. package/dist/types/lib/presentMotion.d.ts +46 -0
  87. package/package.json +2 -2
@@ -4,7 +4,9 @@ import { PopoverAnchor as RekaPopoverAnchor, PopoverContent as RekaPopoverConten
4
4
  import { useEscCloseStack } from "../../composables/useEscCloseStack.js";
5
5
  import { usePhoneWindow } from "../PhoneLayout/PhoneLayout.js";
6
6
  import { useFieldColumns, useFieldRow, useFieldRowPill } from "../../lib/fieldRow.js";
7
- import { preventDefaultHandler, toCssVariables, waitForAnimationFrame } from "../../lib/helpers.js";
7
+ import { keepMovedFocus, preventDefaultHandler, toCssVariables, waitForAnimationFrame } from "../../lib/helpers.js";
8
+ import { Button } from "../Button/index.js";
9
+ import { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "../Dialog/index.js";
8
10
  import { Check, Info, Search } from "../Icon/index.js";
9
11
  import { Input } from "../Input/index.js";
10
12
  import { useDeferredPointerDownOutside } from "../Popover/deferredPointerDownOutside.js";
@@ -105,6 +107,21 @@ const selectProps = {
105
107
  checkPosition: { type: String, default: "start" },
106
108
  /** Renders a custom trigger (or the `#trigger` slot), wrapped as the popover trigger */
107
109
  trigger: Function,
110
+ /**
111
+ * What a press opens on Android: the Plex Android look (`data-platform="android"` on the document's root) in a
112
+ * window 767px wide or narrower. `dialog`, Android's choice dialog: the setting's name over a row for each option,
113
+ * and Cancel. With one choice a row has a radio, and a press on it chooses it and closes the dialog; a `multiple`
114
+ * select has a checkbox in each row and OK, which applies the rows checked. `menu`, the popup of the options. iOS
115
+ * and a desktop always open the menu.
116
+ * @default "dialog", or "menu" for a `multiple` select
117
+ */
118
+ picker: { type: String, default: undefined },
119
+ /** Android: the title of the picker dialog (`picker="dialog"`), the setting's name. @default the field's label (`aria-labelledby`), else `aria-label` */
120
+ title: String,
121
+ /** Android: the button that closes the picker dialog (`picker="dialog"`) with no change. @default "Cancel" */
122
+ cancelLabel: { type: String, default: "Cancel" },
123
+ /** Android: the button of a `multiple` select's picker dialog (`picker="dialog"`) that applies the rows checked. @default "OK" */
124
+ okLabel: { type: String, default: "OK" },
108
125
  "ariaLabel": String,
109
126
  "ariaLabelledby": String,
110
127
  "ariaDescribedby": String,
@@ -197,6 +214,11 @@ const SelectComponent = defineComponent({
197
214
  change(selectedOption);
198
215
  }
199
216
  };
217
+ const onValues = (values) => {
218
+ if (!props.multiple || props.disabled || props.loading)
219
+ return;
220
+ change(getOptionsByValues(props.options, values));
221
+ };
200
222
  // It should be exceedingly uncommon to change actions dynamically: like
201
223
  // React's memo, the rendered actions only follow a change of length.
202
224
  const actions = shallowRef(props.actions ?? []);
@@ -237,6 +259,11 @@ const SelectComponent = defineComponent({
237
259
  void slotsVersion.value;
238
260
  return props.clearable && phone.value && !(slots.trigger || props.trigger);
239
261
  });
262
+ // On Android a single choice opens Android's single-choice dialog, as a value row of the reference messenger's
263
+ // settings does, unless `picker="menu"` asks for the popup; a multiple choice keeps the menu, where it picks
264
+ // several, unless `picker="dialog"` asks for the dialog of checkboxes. The window decides, as for the search; the
265
+ // platform is read as the press opens it (isAndroidLook).
266
+ const choiceDialog = computed(() => phone.value && (props.multiple ? props.picker === "dialog" : props.picker !== "menu"));
240
267
  provide(SelectContextKey, {
241
268
  props,
242
269
  slots,
@@ -252,8 +279,10 @@ const SelectComponent = defineComponent({
252
279
  listMaxWidth,
253
280
  searchable,
254
281
  noneRow,
282
+ choiceDialog,
255
283
  actions,
256
284
  onSelect,
285
+ onValues,
257
286
  onActionSelect,
258
287
  searchPredicate: () => toRaw(rawProps).searchPredicate ?? defaultSearchPredicate,
259
288
  });
@@ -430,14 +459,15 @@ const SelectPopoverTrigger = defineComponent({
430
459
  };
431
460
  },
432
461
  });
433
- // ============================================================
434
- // Custom Select
435
- // ============================================================
436
462
  const CustomSelect = defineComponent({
437
463
  name: "CustomSelect",
438
464
  setup() {
439
- const { props, slots, slotsVersion, triggerEl } = useSelectContext();
465
+ const { props, slots, slotsVersion, triggerEl, choiceDialog } = useSelectContext();
440
466
  const open = ref(false);
467
+ // What this opening shows: the list (the menu), or on Android the single-choice dialog. Decided as it opens and
468
+ // kept until the next opening, so a closing dialog leaves as the dialog.
469
+ const presentation = shallowRef({ dialog: false, label: undefined });
470
+ const menuOpen = computed(() => open.value && !presentation.value.dialog);
441
471
  const selectContentRef = shallowRef(null);
442
472
  const popoverTriggerEl = shallowRef(null);
443
473
  // A mouse opens the list as its button goes down, so on a phone the list is under it when the button comes up
@@ -458,12 +488,21 @@ const CustomSelect = defineComponent({
458
488
  const mounted = ref(false);
459
489
  let focusRestore;
460
490
  let focusRestoreTimer;
491
+ // An opening decides what it shows: on Android, as the press opens it, the single-choice dialog, titled by the
492
+ // field's label as it reads then
493
+ const present = () => {
494
+ const doc = popoverTriggerEl.value?.ownerDocument ?? document;
495
+ const dialog = choiceDialog.value && isAndroidLook(doc);
496
+ presentation.value = { dialog, label: dialog ? labelledByText(doc, props.ariaLabelledby) : undefined };
497
+ };
461
498
  const handleOpenChange = (maybeNextState) => {
462
499
  clearTimeout(focusRestoreTimer);
463
500
  // Toggle the current state when called without a specific state
464
501
  const nextState = maybeNextState === undefined ? !open.value : maybeNextState;
465
502
  if (nextState && (props.disabled || props.loading))
466
503
  return;
504
+ if (nextState && !open.value)
505
+ present();
467
506
  open.value = nextState;
468
507
  // When we're closing, manage focus back to trigger manually
469
508
  if (!nextState) {
@@ -490,7 +529,8 @@ const CustomSelect = defineComponent({
490
529
  if (open.value && (props.disabled || props.loading))
491
530
  handleOpenChange(false);
492
531
  }, { flush: "sync" });
493
- useEscCloseStack(open, () => {
532
+ // The dialog closes on Escape itself
533
+ useEscCloseStack(menuOpen, () => {
494
534
  handleOpenChange(false);
495
535
  });
496
536
  const handleRootOpenChange = (nextState) => {
@@ -544,8 +584,11 @@ const CustomSelect = defineComponent({
544
584
  const renderProps = {
545
585
  open: open.value,
546
586
  onToggle: () => {
547
- if (!props.disabled && !props.loading)
548
- open.value = !open.value;
587
+ if (props.disabled || props.loading)
588
+ return;
589
+ if (!open.value)
590
+ present();
591
+ open.value = !open.value;
549
592
  },
550
593
  };
551
594
  if (slots.trigger)
@@ -556,21 +599,320 @@ const CustomSelect = defineComponent({
556
599
  };
557
600
  return () => {
558
601
  void slotsVersion.value;
559
- return h(RekaPopoverRoot, { "open": open.value, "onUpdate:open": handleRootOpenChange, "modal": false }, {
560
- default: () => [
561
- h(SelectPopoverTrigger, null, { default: renderTrigger }),
562
- // Without animations React replaces the menu's wrapper when it
563
- // opens or closes (see TransitionGroup), so React DOM appends the
564
- // new one to <body>. A Teleport keeps its place in <body>: a new
565
- // one per state moves the wrapper to the end the same way. With
566
- // animations the group has to stay, to run the exit.
567
- h(RekaPopoverPortal, { key: !getDisableAnimations() || open.value ? "open" : "closed", forceMount: mounted.value }, {
568
- default: () => [
569
- h(TransitionGroup, { class: s.Menu, ...overlayTiming, overlay: true }, { default: () => [open.value ? h(SelectPopoverContent, { key: "dropdown" }) : createCommentVNode()] }),
570
- ],
571
- }),
572
- ],
602
+ return [h(RekaPopoverRoot, { "open": menuOpen.value, "onUpdate:open": handleRootOpenChange, "modal": false }, {
603
+ default: () => [
604
+ h(SelectPopoverTrigger, null, { default: renderTrigger }),
605
+ // Without animations React replaces the menu's wrapper when it
606
+ // opens or closes (see TransitionGroup), so React DOM appends the
607
+ // new one to <body>. A Teleport keeps its place in <body>: a new
608
+ // one per state moves the wrapper to the end the same way. With
609
+ // animations the group has to stay, to run the exit.
610
+ h(RekaPopoverPortal, { key: !getDisableAnimations() || menuOpen.value ? "open" : "closed", forceMount: mounted.value }, {
611
+ default: () => [
612
+ h(TransitionGroup, { class: s.Menu, ...overlayTiming, overlay: true }, { default: () => [menuOpen.value ? h(SelectPopoverContent, { key: "dropdown" }) : createCommentVNode()] }),
613
+ ],
614
+ }),
615
+ ],
616
+ }),
617
+ // Mounted from the first opening that shows it, so a page of selects that never open one has no dialog
618
+ presentation.value.dialog
619
+ ? h(SelectChoiceDialog, {
620
+ open: open.value,
621
+ label: presentation.value.label,
622
+ onClose: () => handleOpenChange(false),
623
+ trigger: () => popoverTriggerEl.value,
624
+ focusRestore: () => focusRestore,
625
+ })
626
+ : createCommentVNode()];
627
+ };
628
+ },
629
+ });
630
+ // ============================================================
631
+ // Android's single-choice dialog
632
+ // ============================================================
633
+ /**
634
+ * The Plex Android look is on: android.css draws it from the root's `data-platform`, and only there are its tokens
635
+ * set, so the dialog follows the root.
636
+ */
637
+ const isAndroidLook = (doc) => doc.documentElement.getAttribute("data-platform") === "android";
638
+ /** The text of the elements `aria-labelledby` names: the field's label */
639
+ const labelledByText = (doc, ids) => {
640
+ const text = (ids ?? "")
641
+ .split(/\s+/)
642
+ .map((id) => (id ? doc.getElementById(id)?.textContent?.trim() : ""))
643
+ .filter(Boolean)
644
+ .join(" ");
645
+ return text || undefined;
646
+ };
647
+ /** The row that takes focus as the dialog opens */
648
+ const FIRST_CHOICE_FOCUS = '[role="radio"][tabindex="0"], [role="checkbox"][tabindex="0"]';
649
+ /**
650
+ * Android's choice dialog (a value row of the reference messenger's settings: AlertDialog with a list of
651
+ * RadioColorCell rows, or of CheckBoxCell rows for several choices): the alert of Dialog (Dialog.module.css draws its
652
+ * Android look) with the setting's name, a row for each option across its width, and Cancel. With one choice a press
653
+ * on a row chooses it and closes the dialog; with several a press checks or unchecks its row and OK applies them.
654
+ * Cancel, Escape or a press outside close it with no change. Focus starts on the chosen row and returns to the trigger.
655
+ */
656
+ const SelectChoiceDialog = defineComponent({
657
+ name: "SelectChoiceDialog",
658
+ props: {
659
+ open: { type: Boolean, required: true },
660
+ /** The field's label, the title when there is no `title` */
661
+ label: String,
662
+ onClose: { type: Function, required: true },
663
+ trigger: { type: Function, required: true },
664
+ focusRestore: { type: Function, required: true },
665
+ },
666
+ setup(ownProps) {
667
+ // The chosen row takes focus, else the first that can be chosen
668
+ const handleOpenAutoFocus = (event) => {
669
+ event.preventDefault();
670
+ const container = event.target instanceof HTMLElement ? event.target : null;
671
+ const row = container?.querySelector(FIRST_CHOICE_FOCUS);
672
+ row?.focus({ preventScroll: true });
673
+ row?.scrollIntoView({ block: "nearest" });
674
+ };
675
+ // Focus returns to the trigger, unless it moved on outside the dialog
676
+ const handleCloseAutoFocus = (event) => {
677
+ keepMovedFocus(event);
678
+ const trigger = ownProps.trigger();
679
+ if (!event.defaultPrevented && trigger)
680
+ ownProps.focusRestore()?.restore(trigger);
681
+ event.preventDefault();
682
+ };
683
+ return () => h(Dialog, { "open": ownProps.open, "onUpdate:open": (next) => { if (!next)
684
+ ownProps.onClose(); } }, {
685
+ default: () => [
686
+ h(DialogContent, {
687
+ "mobileVariant": "alert",
688
+ "showClose": false,
689
+ "class": s.ChoicePanel,
690
+ "rootProps": { class: s.ChoiceDialog },
691
+ "data-select-dialog": "",
692
+ "onOpenAutoFocus": handleOpenAutoFocus,
693
+ "onCloseAutoFocus": handleCloseAutoFocus,
694
+ }, { default: () => [h(SelectChoiceContent, { label: ownProps.label, onClose: ownProps.onClose })] }),
695
+ ],
696
+ });
697
+ },
698
+ });
699
+ /**
700
+ * The dialog's title, rows and buttons, mounted with each opening: the choice they show is the value as it opened,
701
+ * and a multiple select's checked rows are kept here until OK applies them
702
+ */
703
+ const SelectChoiceContent = defineComponent({
704
+ name: "SelectChoiceContent",
705
+ props: {
706
+ label: String,
707
+ onClose: { type: Function, required: true },
708
+ },
709
+ setup(ownProps) {
710
+ const { props, actions, onActionSelect, onValues } = useSelectContext();
711
+ const checked = ref(props.multiple ? [...props.value] : []);
712
+ return () => {
713
+ const name = props.title ?? ownProps.label ?? props.ariaLabel;
714
+ return [
715
+ name ? h(DialogHeader, { class: s.ChoiceHeader }, { default: () => [h(DialogTitle, null, { default: () => name })] }) : null,
716
+ h(DialogBody, { class: s.ChoiceBody }, {
717
+ default: () => [h(SelectChoiceRows, {
718
+ name,
719
+ onChoose: ownProps.onClose,
720
+ checked: checked.value,
721
+ onCheckedChange: (next) => { checked.value = next; },
722
+ })],
723
+ }),
724
+ h(DialogFooter, { class: s.ChoiceFooter }, {
725
+ default: () => [
726
+ // The list's actions are the dialog's buttons, before Cancel
727
+ ...actions.value.map((action) => h(Button, {
728
+ key: action.id,
729
+ color: "secondary",
730
+ variant: "soft",
731
+ onClick: () => {
732
+ onActionSelect(action.id);
733
+ ownProps.onClose();
734
+ },
735
+ }, { default: () => action.label })),
736
+ h(DialogClose, null, {
737
+ default: () => [h(Button, { color: "secondary", variant: "soft" }, { default: () => props.cancelLabel })],
738
+ }),
739
+ props.multiple
740
+ ? h(Button, {
741
+ color: "secondary",
742
+ variant: "soft",
743
+ onClick: () => {
744
+ onValues(checked.value);
745
+ ownProps.onClose();
746
+ },
747
+ }, { default: () => props.okLabel })
748
+ : null,
749
+ ],
750
+ }),
751
+ ];
752
+ };
753
+ },
754
+ });
755
+ const SelectChoiceRows = defineComponent({
756
+ name: "SelectChoiceRows",
757
+ props: {
758
+ name: String,
759
+ /** One choice: a row was chosen */
760
+ onChoose: { type: Function, required: true },
761
+ /** Several choices: the rows checked, applied by OK */
762
+ checked: { type: Array, required: true },
763
+ onCheckedChange: { type: Function, required: true },
764
+ },
765
+ setup(ownProps) {
766
+ const { props, noneRow, onSelect } = useSelectContext();
767
+ // Kept for this opening, so the radio does not move while the dialog leaves
768
+ const openingValue = props.value;
769
+ const opening = Array.isArray(openingValue) ? [...openingValue] : [openingValue];
770
+ const choose = (option, none) => {
771
+ if (props.multiple) {
772
+ // The None row unchecks every row; another row checks or unchecks itself
773
+ const { checked } = ownProps;
774
+ if (none)
775
+ ownProps.onCheckedChange([]);
776
+ else
777
+ ownProps.onCheckedChange(checked.includes(option.value) ? checked.filter((item) => item !== option.value) : [...checked, option.value]);
778
+ return;
779
+ }
780
+ // The None row unsets the value, as the clear button does
781
+ onSelect(none ? { value: "", label: "" } : option);
782
+ ownProps.onChoose();
783
+ };
784
+ // The arrows move focus through the rows that can be chosen, round from the last to the first; a row is chosen
785
+ // (or checked) by a press, Enter or Space
786
+ const handleKeyDown = (event) => {
787
+ if (event.defaultPrevented || event.isComposing)
788
+ return;
789
+ const group = event.currentTarget;
790
+ const rows = Array.from(group.querySelectorAll(':is([role="radio"], [role="checkbox"]):not([aria-disabled="true"])'));
791
+ if (!rows.length)
792
+ return;
793
+ const index = rows.indexOf(document.activeElement);
794
+ let next;
795
+ switch (event.key) {
796
+ case "ArrowDown":
797
+ case "ArrowRight":
798
+ next = rows[(index + 1) % rows.length];
799
+ break;
800
+ case "ArrowUp":
801
+ case "ArrowLeft":
802
+ next = rows[index <= 0 ? rows.length - 1 : index - 1];
803
+ break;
804
+ case "Home":
805
+ next = rows[0];
806
+ break;
807
+ case "End":
808
+ next = rows[rows.length - 1];
809
+ break;
810
+ default:
811
+ return;
812
+ }
813
+ event.preventDefault();
814
+ next?.focus({ preventScroll: true });
815
+ next?.scrollIntoView({ block: "nearest" });
816
+ };
817
+ return () => {
818
+ const { options, multiple } = props;
819
+ const noneChosen = noneRow.value && !opening.some((item) => hasChosenOption(options, item));
820
+ const chosen = opening.map((item) => getOptionByValue(options, item)).find((option) => option && !option.disabled);
821
+ // The tab stop and the first focus: the chosen row (the first checked), else the first that can be chosen
822
+ const focusValue = noneChosen
823
+ ? NONE_OPTION_VALUE
824
+ : chosen ? chosen.value : noneRow.value ? NONE_OPTION_VALUE : getFirstValidOption(options)?.value;
825
+ const row = (option, none = false) => h(SelectChoiceRow, {
826
+ key: none ? NONE_OPTION_VALUE : option.value,
827
+ option,
828
+ none,
829
+ checked: multiple
830
+ ? (none ? ownProps.checked.length === 0 : ownProps.checked.includes(option.value))
831
+ : (none ? noneChosen : option.value === openingValue),
832
+ focusable: (none ? NONE_OPTION_VALUE : option.value) === focusValue,
833
+ onChoose: () => choose(option, none),
573
834
  });
835
+ return h("div", { "class": s.ChoiceList, "role": multiple ? "group" : "radiogroup", "aria-label": ownProps.name, "onKeydown": handleKeyDown }, [
836
+ noneRow.value ? row({ value: NONE_OPTION_VALUE, label: props.noneLabel }, true) : null,
837
+ ...(isOptionGroupArray(options)
838
+ ? options.map((group) => h(SelectChoiceGroup, { key: group.label, group, row }))
839
+ : options.map((option) => row(option))),
840
+ ]);
841
+ };
842
+ },
843
+ });
844
+ const SelectChoiceGroup = defineComponent({
845
+ name: "SelectChoiceGroup",
846
+ props: {
847
+ group: { type: Object, required: true },
848
+ row: { type: Function, required: true },
849
+ },
850
+ setup(ownProps) {
851
+ const headingId = useId();
852
+ return () => h("div", { "role": "group", "aria-labelledby": headingId, "class": s.ChoiceGroup }, [
853
+ h("div", { id: headingId, class: s.ChoiceGroupHeading }, ownProps.group.label),
854
+ ...ownProps.group.options.map((option) => ownProps.row(option)),
855
+ ]);
856
+ },
857
+ });
858
+ /**
859
+ * A row of the dialog (RadioColorCell): 50 tall, a 20 radio in a 22 frame 22 in and 14 down, the label 16/20 at 55,
860
+ * one line, a description 14 in the secondary text 4 under it. The chosen radio is the accent, with a dot. A multiple
861
+ * select's row has an 18 checkbox in that frame (CheckBoxCell's square), the accent with a check when checked.
862
+ */
863
+ const SelectChoiceRow = defineComponent({
864
+ name: "SelectChoiceRow",
865
+ props: {
866
+ option: { type: Object, required: true },
867
+ none: { type: Boolean, required: true },
868
+ checked: { type: Boolean, required: true },
869
+ /** The list's one tab stop */
870
+ focusable: { type: Boolean, required: true },
871
+ onChoose: { type: Function, required: true },
872
+ },
873
+ setup(ownProps) {
874
+ const { props, slots, slotsVersion } = useSelectContext();
875
+ const renderOptionView = (option) => {
876
+ if (slots.optionView)
877
+ return slots.optionView(option);
878
+ if (props.OptionView)
879
+ return h(props.OptionView, option);
880
+ return option.label;
881
+ };
882
+ return () => {
883
+ void slotsVersion.value;
884
+ const { option, none } = ownProps;
885
+ const { disabled, description, tooltip } = option;
886
+ return h("div", {
887
+ "class": s.ChoiceRow,
888
+ "role": props.multiple ? "checkbox" : "radio",
889
+ "aria-checked": ownProps.checked,
890
+ "aria-disabled": disabled || undefined,
891
+ "data-disabled": disabled ? "" : undefined,
892
+ "tabindex": ownProps.focusable ? 0 : -1,
893
+ "onClick": () => {
894
+ if (!disabled)
895
+ ownProps.onChoose();
896
+ },
897
+ "onKeydown": (event) => {
898
+ if (event.target !== event.currentTarget || (event.key !== "Enter" && event.key !== " "))
899
+ return;
900
+ event.preventDefault();
901
+ if (!disabled)
902
+ ownProps.onChoose();
903
+ },
904
+ // iOS Safari applies :active, which draws a held row, only under a touch listener
905
+ "onTouchstartPassive": () => { },
906
+ }, [
907
+ h("span", { "class": props.multiple ? s.ChoiceCheck : s.ChoiceRadio, "aria-hidden": "true" }),
908
+ h("div", { class: s.ChoiceText }, [
909
+ h("div", { class: s.ChoiceLabel }, [none ? option.label : renderOptionView(option)]),
910
+ // React's `description && ...`: a 0 (or NaN) renders as text
911
+ description && h("div", { class: s.ChoiceDescription }, [renderContent(description)]),
912
+ // A dialog has no tooltips: the tooltip is the row's second line, as in a phone's list
913
+ tooltip ? h("div", { class: s.ChoiceDescription }, [renderContent(tooltip.content)]) : null,
914
+ ]),
915
+ ]);
574
916
  };
575
917
  },
576
918
  });