@plexui/ui 0.61.1 → 0.62.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/dist/es/components/Accordion/Accordion.js +21 -2
- package/dist/es/components/Accordion/Accordion.js.map +1 -1
- package/dist/es/components/Button/NavigationButton.js +1 -1
- package/dist/es/components/Button/NavigationButton.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +51 -3
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Dialog/sheetDrag.js +45 -12
- package/dist/es/components/Dialog/sheetDrag.js.map +1 -1
- package/dist/es/components/Field/Field.js +3 -1
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +22 -1
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/PlexUIProvider/PlexUIProvider.js +40 -6
- package/dist/es/components/PlexUIProvider/PlexUIProvider.js.map +1 -1
- package/dist/es/components/PlexUIProvider/androidRipple.js +98 -0
- package/dist/es/components/PlexUIProvider/androidRipple.js.map +1 -0
- package/dist/es/components/PlexUIProvider/index.js.map +1 -1
- package/dist/es/components/Select/Select.js +217 -39
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +230 -5
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/components/Toolbar/index.js.map +1 -1
- package/dist/es/lib/accordionMotion.js +144 -0
- package/dist/es/lib/accordionMotion.js.map +1 -0
- package/dist/es/lib/fieldRow.js +73 -1
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/presentMotion.js +151 -0
- package/dist/es/lib/presentMotion.js.map +1 -0
- package/dist/es/styles/android.css +1 -0
- package/dist/types/components/Accordion/Accordion.d.ts +1 -1
- package/dist/types/components/Button/NavigationButton.d.ts +8 -1
- package/dist/types/components/Field/Field.d.ts +3 -0
- package/dist/types/components/PlexUIProvider/PlexUIProvider.d.ts +10 -3
- package/dist/types/components/PlexUIProvider/androidRipple.d.ts +9 -0
- package/dist/types/components/PlexUIProvider/index.d.ts +1 -1
- package/dist/types/components/Select/Select.d.ts +24 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +16 -1
- package/dist/types/components/Toolbar/index.d.ts +1 -1
- package/dist/types/lib/accordionMotion.d.ts +20 -0
- package/dist/types/lib/fieldRow.d.ts +14 -0
- package/dist/types/lib/presentMotion.d.ts +46 -0
- package/package.json +2 -2
|
@@ -8,6 +8,8 @@ import { useEscCloseStack } from "../../hooks/useEscCloseStack.js";
|
|
|
8
8
|
import { useLatestValue } from "../../hooks/useLatestValue.js";
|
|
9
9
|
import { useFieldColumns, useFieldRow, useFieldRowPill } from "../../lib/fieldRow.js";
|
|
10
10
|
import { keepMovedFocus, preventDefaultHandler, toCssVariables, waitForAnimationFrame } from "../../lib/helpers.js";
|
|
11
|
+
import { Button } from "../Button/index.js";
|
|
12
|
+
import { Dialog } from "../Dialog/index.js";
|
|
11
13
|
import { Check, Info, Search } from "../Icon/index.js";
|
|
12
14
|
import { Input } from "../Input/index.js";
|
|
13
15
|
import { SelectControl } from "../SelectControl/index.js";
|
|
@@ -43,7 +45,7 @@ const DefaultMultiTriggerView = ({ values, selectedAll, }) => {
|
|
|
43
45
|
return _jsx(_Fragment, { children: displayValue });
|
|
44
46
|
};
|
|
45
47
|
export const Select = (props) => {
|
|
46
|
-
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, required, value, name, multiple, variant = "outline", size = "md", dropdownIconType = "dropdown", loading = false, clearable = false, disabled = false, placeholder = "Select...", loadingPlaceholder = "Loading...", allSelectedLabel = "All selected", noneLabel = "None", pill: pillProp, listPill: listPillProp, listMinWidth, options, actions: propActions = [], side, avoidCollisions = true, onChange, optionClassName, OptionView = DefaultOptionView, TriggerStartIcon, triggerClassName, opticallyAlign, TriggerView: TriggerViewFromProps, searchPlaceholder = "", searchAriaLabel = "Search options", searchSize, searchPredicate = defaultSearchPredicate, searchEmptyMessage = "No results found.", trigger, checkPosition = 'start', } = props;
|
|
48
|
+
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, required, value, name, multiple, variant = "outline", size = "md", dropdownIconType = "dropdown", loading = false, clearable = false, disabled = false, placeholder = "Select...", loadingPlaceholder = "Loading...", allSelectedLabel = "All selected", noneLabel = "None", pill: pillProp, listPill: listPillProp, listMinWidth, options, actions: propActions = [], side, avoidCollisions = true, onChange, optionClassName, OptionView = DefaultOptionView, TriggerStartIcon, triggerClassName, opticallyAlign, TriggerView: TriggerViewFromProps, searchPlaceholder = "", searchAriaLabel = "Search options", searchSize, searchPredicate = defaultSearchPredicate, searchEmptyMessage = "No results found.", trigger, checkPosition = 'start', picker, title, cancelLabel = "Cancel", okLabel = "OK", } = props;
|
|
47
49
|
const pill = useFieldRowPill(pillProp);
|
|
48
50
|
const listPill = listPillProp ?? pill;
|
|
49
51
|
// At the end of a Field row the menu opens from the row's end and fits its options: on a phone
|
|
@@ -83,6 +85,11 @@ export const Select = (props) => {
|
|
|
83
85
|
onChange(selectedOption);
|
|
84
86
|
}
|
|
85
87
|
});
|
|
88
|
+
const onValuesRef = useLatestValue((nextValues) => {
|
|
89
|
+
if (!multiple || disabled || loading)
|
|
90
|
+
return;
|
|
91
|
+
onChange(getOptionsByValues(options, nextValues));
|
|
92
|
+
});
|
|
86
93
|
const searchPredicateRef = useRef(searchPredicate);
|
|
87
94
|
searchPredicateRef.current = searchPredicate;
|
|
88
95
|
// It should be exceedingly uncommon to change actions dynamically, and they are unlikely to be a stable array reference from consumers
|
|
@@ -116,6 +123,11 @@ export const Select = (props) => {
|
|
|
116
123
|
// the search.
|
|
117
124
|
// A custom trigger owns its clearing, so only the default one gives its clear button to the row.
|
|
118
125
|
const noneRow = clearable && phone && !trigger;
|
|
126
|
+
// On Android a single choice opens Android's single-choice dialog, as a value row of the reference messenger's settings
|
|
127
|
+
// does, unless `picker="menu"` asks for the popup; a multiple choice keeps the menu, where it picks several, unless
|
|
128
|
+
// `picker="dialog"` asks for the dialog of checkboxes. The window decides, as for the search; the platform is read as
|
|
129
|
+
// the press opens it (isAndroidLook).
|
|
130
|
+
const choiceDialog = phone && (multiple ? picker === "dialog" : picker !== "menu");
|
|
119
131
|
// A block menu matches its field. An inline one, or one at the end of a Field row, fits its
|
|
120
132
|
// options: no narrower than its trigger (the CSS fallback reads the trigger width), no wider than 300px.
|
|
121
133
|
const fitsOptions = (!block || inRow) && props.listWidth === undefined;
|
|
@@ -186,6 +198,11 @@ export const Select = (props) => {
|
|
|
186
198
|
disabled,
|
|
187
199
|
trigger,
|
|
188
200
|
checkPosition,
|
|
201
|
+
choiceDialog,
|
|
202
|
+
title,
|
|
203
|
+
cancelLabel,
|
|
204
|
+
okLabel,
|
|
205
|
+
onValuesRef,
|
|
189
206
|
}), [
|
|
190
207
|
dynamicContextProps,
|
|
191
208
|
triggerId,
|
|
@@ -233,6 +250,11 @@ export const Select = (props) => {
|
|
|
233
250
|
disabled,
|
|
234
251
|
trigger,
|
|
235
252
|
checkPosition,
|
|
253
|
+
choiceDialog,
|
|
254
|
+
title,
|
|
255
|
+
cancelLabel,
|
|
256
|
+
okLabel,
|
|
257
|
+
onValuesRef,
|
|
236
258
|
]);
|
|
237
259
|
return (
|
|
238
260
|
// NOTE: Cannot peacefully coerce SelectContextValue into a generic, so casting to any here.
|
|
@@ -316,13 +338,14 @@ export const SelectTrigger = (props) => {
|
|
|
316
338
|
// prevents the value from being required
|
|
317
339
|
onChange: () => { }, required: required, className: s.FormInput, "aria-hidden": "true" }, index)))] }));
|
|
318
340
|
};
|
|
319
|
-
// ============================================================
|
|
320
|
-
// Custom Select
|
|
321
|
-
// ============================================================
|
|
322
341
|
const CustomSelect = () => {
|
|
323
|
-
const { loading, disabled, side, align, alignOffset, avoidCollisions, listWidth, listMinWidth, listMaxWidth, trigger, listPill, } = useSelectContext();
|
|
324
|
-
const [open,
|
|
325
|
-
|
|
342
|
+
const { loading, disabled, side, align, alignOffset, avoidCollisions, listWidth, listMinWidth, listMaxWidth, trigger, listPill, choiceDialog, "aria-labelledby": ariaLabelledBy, } = useSelectContext();
|
|
343
|
+
const [open, setOpenState] = useState(false);
|
|
344
|
+
// What this opening shows: the list (the menu), or on Android the single-choice dialog. Decided as it opens and kept
|
|
345
|
+
// until the next opening, so a closing dialog leaves as the dialog.
|
|
346
|
+
const [presentation, setPresentation] = useState({ dialog: false, label: undefined });
|
|
347
|
+
const menuOpen = open && !presentation.dialog;
|
|
348
|
+
const floatingBoundary = useFloatingBoundary(menuOpen && avoidCollisions, { bottom: 30, top: 30 });
|
|
326
349
|
const selectContentRef = useRef(null);
|
|
327
350
|
// The trigger element, the default one or a custom `trigger` (which has no `triggerId`)
|
|
328
351
|
const popoverTriggerRef = useRef(null);
|
|
@@ -343,16 +366,16 @@ const CustomSelect = () => {
|
|
|
343
366
|
// Only in a phone-wide window, where the list is laid out as on a phone (Select.module.css)
|
|
344
367
|
const [cover, setCover] = useState(null);
|
|
345
368
|
useLayoutEffect(() => {
|
|
346
|
-
if (!
|
|
369
|
+
if (!menuOpen || !triggerElement)
|
|
347
370
|
return;
|
|
348
371
|
return observeMenuTriggerCover(triggerElement, setCover, { windowOnly: true });
|
|
349
|
-
}, [
|
|
372
|
+
}, [menuOpen, triggerElement]);
|
|
350
373
|
// The covered trigger is hidden while the list is open, and shown again as it closes, before focus returns to it
|
|
351
374
|
useLayoutEffect(() => {
|
|
352
|
-
if (!
|
|
375
|
+
if (!menuOpen || !cover || !triggerElement || !contentElement)
|
|
353
376
|
return;
|
|
354
377
|
return markCoveredMenuTrigger(triggerElement, contentElement);
|
|
355
|
-
}, [
|
|
378
|
+
}, [menuOpen, cover, triggerElement, contentElement]);
|
|
356
379
|
// A mouse opens the list as its button goes down, so on a phone the list is under it when the button comes up: that
|
|
357
380
|
// release chooses nothing while it is over the trigger, as in Menu
|
|
358
381
|
useEffect(() => {
|
|
@@ -376,13 +399,22 @@ const CustomSelect = () => {
|
|
|
376
399
|
focusRestoreRef.current = null;
|
|
377
400
|
};
|
|
378
401
|
}, []);
|
|
402
|
+
// An opening decides what it shows: on Android, as the press opens it, the single-choice dialog, titled by the
|
|
403
|
+
// field's label as it reads then
|
|
404
|
+
const present = useCallback(() => {
|
|
405
|
+
const doc = popoverTriggerRef.current?.ownerDocument ?? document;
|
|
406
|
+
const dialog = choiceDialog && isAndroidLook(doc);
|
|
407
|
+
setPresentation({ dialog, label: dialog ? labelledByText(doc, ariaLabelledBy) : undefined });
|
|
408
|
+
}, [choiceDialog, ariaLabelledBy]);
|
|
379
409
|
const handleOpenChange = useCallback((maybeNextState) => {
|
|
380
410
|
clearTimeout(focusRestoreTimer.current);
|
|
381
411
|
// Toggle the current state when called without a specific state
|
|
382
412
|
const nextState = maybeNextState === undefined ? !open : maybeNextState;
|
|
383
413
|
if (nextState && (disabled || loading))
|
|
384
414
|
return;
|
|
385
|
-
|
|
415
|
+
if (nextState && !open)
|
|
416
|
+
present();
|
|
417
|
+
setOpenState(nextState);
|
|
386
418
|
// When we're closing, manage focus back to trigger manually
|
|
387
419
|
if (!nextState) {
|
|
388
420
|
// Read this now: with animations disabled the menu unmounts before the
|
|
@@ -403,39 +435,185 @@ const CustomSelect = () => {
|
|
|
403
435
|
}
|
|
404
436
|
});
|
|
405
437
|
}
|
|
406
|
-
}, [disabled, loading, open]);
|
|
438
|
+
}, [disabled, loading, open, present]);
|
|
407
439
|
// Forget the open request when availability changes, so re-enabling does not
|
|
408
440
|
// reopen an old menu. Radix's exit autofocus below handles this close.
|
|
409
441
|
if (open && (disabled || loading))
|
|
410
|
-
|
|
411
|
-
|
|
442
|
+
setOpenState(false);
|
|
443
|
+
// The dialog closes on Escape itself
|
|
444
|
+
useEscCloseStack(menuOpen, () => {
|
|
412
445
|
handleOpenChange(false);
|
|
413
446
|
});
|
|
414
|
-
return (_jsxs(Popover.Root, { open:
|
|
415
|
-
|
|
416
|
-
|
|
447
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Popover.Root, { open: menuOpen, onOpenChange: (nextState) => {
|
|
448
|
+
// Prevent opening while loading
|
|
449
|
+
if (loading && nextState) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
handleOpenChange(nextState);
|
|
453
|
+
}, modal: false, children: [_jsx(Popover.Trigger, { asChild: true, ref: setTrigger, children: trigger ? trigger({ open, onToggle: () => {
|
|
454
|
+
if (disabled || loading)
|
|
455
|
+
return;
|
|
456
|
+
if (!open)
|
|
457
|
+
present();
|
|
458
|
+
setOpenState((current) => !current);
|
|
459
|
+
} }) : _jsx(SelectTrigger, { onOpenChange: handleOpenChange }) }), _jsx(Popover.Portal, { forceMount: true, children: _jsx(TransitionGroup, { className: s.Menu, ...overlayTiming, overlay: true, children: menuOpen && (_jsx(Popover.Content, { ref: setContent, forceMount: true, className: s.MenuList, "data-pill": listPill ? "" : undefined, "data-list-width": listWidth === "auto" ? "auto" : undefined, "data-list-sized": typeof listWidth === "number" ? "" : undefined, side: side ?? cover?.side ?? "bottom", sideOffset: cover ? cover.sideOffset : 5, align: align, alignOffset: alignOffset, avoidCollisions: avoidCollisions, ...floatingBoundary,
|
|
460
|
+
// Prevent Radix auto focus so we can handle our own from within <CustomSelectMenu />
|
|
461
|
+
onOpenAutoFocus: preventDefaultHandler,
|
|
462
|
+
// Radix waits until the animation completes before directing focus, which is janky.
|
|
463
|
+
onCloseAutoFocus: (event) => {
|
|
464
|
+
if (disabled || loading) {
|
|
465
|
+
keepMovedFocus(event);
|
|
466
|
+
const trigger = popoverTriggerRef.current;
|
|
467
|
+
if (!event.defaultPrevented && trigger)
|
|
468
|
+
focusRestoreRef.current?.restore(trigger);
|
|
469
|
+
}
|
|
470
|
+
event.preventDefault();
|
|
471
|
+
}, onEscapeKeyDown: preventDefaultHandler, style: toCssVariables({
|
|
472
|
+
"select-list-width": listWidth,
|
|
473
|
+
"select-list-min-width": listMinWidth,
|
|
474
|
+
// "auto" is no maximum: the variable is left out, so a phone's 250pt floor can read the cap
|
|
475
|
+
"select-list-max-width": listMaxWidth === "auto" ? undefined : listMaxWidth,
|
|
476
|
+
}), children: _jsx(CustomSelectMenu, { onOpenChange: handleOpenChange }) }, "dropdown")) }) })] }), presentation.dialog && (_jsx(SelectChoiceDialog, { open: open, label: presentation.label, onClose: () => handleOpenChange(false), triggerRef: popoverTriggerRef, focusRestoreRef: focusRestoreRef }))] }));
|
|
477
|
+
};
|
|
478
|
+
// ============================================================
|
|
479
|
+
// Android's single-choice dialog
|
|
480
|
+
// ============================================================
|
|
481
|
+
/**
|
|
482
|
+
* The Plex Android look is on: android.css draws it from the root's `data-platform`, and only there are its tokens
|
|
483
|
+
* set, so the dialog follows the root.
|
|
484
|
+
*/
|
|
485
|
+
const isAndroidLook = (doc) => doc.documentElement.getAttribute("data-platform") === "android";
|
|
486
|
+
/** The text of the elements `aria-labelledby` names: the field's label */
|
|
487
|
+
const labelledByText = (doc, ids) => {
|
|
488
|
+
const text = (ids ?? "")
|
|
489
|
+
.split(/\s+/)
|
|
490
|
+
.map((id) => (id ? doc.getElementById(id)?.textContent?.trim() : ""))
|
|
491
|
+
.filter(Boolean)
|
|
492
|
+
.join(" ");
|
|
493
|
+
return text || undefined;
|
|
494
|
+
};
|
|
495
|
+
/** The row that takes focus as the dialog opens */
|
|
496
|
+
const FIRST_CHOICE_FOCUS = '[role="radio"][tabindex="0"], [role="checkbox"][tabindex="0"]';
|
|
497
|
+
/**
|
|
498
|
+
* Android's choice dialog (a value row of the reference messenger's settings: AlertDialog with a list of
|
|
499
|
+
* RadioColorCell rows, or of CheckBoxCell rows for several choices): the alert of Dialog (Dialog.module.css draws its
|
|
500
|
+
* Android look) with the setting's name, a row for each option across its width, and Cancel. With one choice a press
|
|
501
|
+
* on a row chooses it and closes the dialog; with several a press checks or unchecks its row and OK applies them.
|
|
502
|
+
* Cancel, Escape or a press outside close it with no change. Focus starts on the chosen row and returns to the trigger.
|
|
503
|
+
*/
|
|
504
|
+
const SelectChoiceDialog = ({ open, label, onClose, triggerRef, focusRestoreRef }) => {
|
|
505
|
+
return (_jsx(Dialog, { open: open, onOpenChange: (next) => { if (!next)
|
|
506
|
+
onClose(); }, children: _jsx(Dialog.Content, { mobileVariant: "alert", showClose: false, className: s.ChoicePanel, rootProps: { className: s.ChoiceDialog }, "data-select-dialog": "",
|
|
507
|
+
// The chosen row takes focus, else the first that can be chosen
|
|
508
|
+
onOpenAutoFocus: (event) => {
|
|
509
|
+
event.preventDefault();
|
|
510
|
+
const container = event.target instanceof HTMLElement ? event.target : null;
|
|
511
|
+
const row = container?.querySelector(FIRST_CHOICE_FOCUS);
|
|
512
|
+
row?.focus({ preventScroll: true });
|
|
513
|
+
row?.scrollIntoView({ block: "nearest" });
|
|
514
|
+
},
|
|
515
|
+
// Focus returns to the trigger, unless it moved on outside the dialog
|
|
516
|
+
onCloseAutoFocus: (event) => {
|
|
517
|
+
keepMovedFocus(event);
|
|
518
|
+
const trigger = triggerRef.current;
|
|
519
|
+
if (!event.defaultPrevented && trigger)
|
|
520
|
+
focusRestoreRef.current?.restore(trigger);
|
|
521
|
+
event.preventDefault();
|
|
522
|
+
}, children: _jsx(SelectChoiceContent, { label: label, onClose: onClose }) }) }));
|
|
523
|
+
};
|
|
524
|
+
/**
|
|
525
|
+
* The dialog's title, rows and buttons, mounted with each opening: the choice they show is the value as it opened,
|
|
526
|
+
* and a multiple select's checked rows are kept here until OK applies them
|
|
527
|
+
*/
|
|
528
|
+
const SelectChoiceContent = ({ label, onClose }) => {
|
|
529
|
+
const { multiple, value, title, "aria-label": ariaLabel, cancelLabel, okLabel, actions, onActionSelect, onValuesRef, } = useSelectContext();
|
|
530
|
+
const name = title ?? label ?? ariaLabel;
|
|
531
|
+
const [checked, setChecked] = useState(() => (multiple ? [...value] : []));
|
|
532
|
+
return (_jsxs(_Fragment, { children: [name && (_jsx(Dialog.Header, { className: s.ChoiceHeader, children: _jsx(Dialog.Title, { children: name }) })), _jsx(Dialog.Body, { className: s.ChoiceBody, children: _jsx(SelectChoiceRows, { name: name, onChoose: onClose, checked: checked, onCheckedChange: setChecked }) }), _jsxs(Dialog.Footer, { className: s.ChoiceFooter, children: [actions.map((action) => (_jsx(Button, { color: "secondary", variant: "soft", onClick: () => { onActionSelect(action.id); onClose(); }, children: action.label }, action.id))), _jsx(Dialog.Close, { children: _jsx(Button, { color: "secondary", variant: "soft", children: cancelLabel }) }), multiple && (_jsx(Button, { color: "secondary", variant: "soft", onClick: () => { onValuesRef.current(checked); onClose(); }, children: okLabel }))] })] }));
|
|
533
|
+
};
|
|
534
|
+
const SelectChoiceRows = ({ name, onChoose, checked, onCheckedChange }) => {
|
|
535
|
+
const { multiple, options, value, noneRow, noneLabel, onSelectRef } = useSelectContext();
|
|
536
|
+
// Kept for this opening, so the radio does not move while the dialog leaves
|
|
537
|
+
const [openingValue] = useState(() => value);
|
|
538
|
+
const opening = Array.isArray(openingValue) ? openingValue : [openingValue];
|
|
539
|
+
const noneChosen = noneRow && !opening.some((item) => hasChosenOption(options, item));
|
|
540
|
+
const chosen = opening.map((item) => getOptionByValue(options, item)).find((option) => option && !option.disabled);
|
|
541
|
+
// The tab stop and the first focus: the chosen row (the first checked), else the first that can be chosen
|
|
542
|
+
const focusValue = noneChosen
|
|
543
|
+
? NONE_OPTION_VALUE
|
|
544
|
+
: chosen ? chosen.value : noneRow ? NONE_OPTION_VALUE : getFirstValidOption(options)?.value;
|
|
545
|
+
const choose = (option, none) => {
|
|
546
|
+
if (multiple) {
|
|
547
|
+
// The None row unchecks every row; another row checks or unchecks itself
|
|
548
|
+
if (none)
|
|
549
|
+
onCheckedChange([]);
|
|
550
|
+
else
|
|
551
|
+
onCheckedChange(checked.includes(option.value) ? checked.filter((item) => item !== option.value) : [...checked, option.value]);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
// The None row unsets the value, as the clear button does
|
|
555
|
+
onSelectRef.current(none ? { value: "", label: "" } : option);
|
|
556
|
+
onChoose();
|
|
557
|
+
};
|
|
558
|
+
// The arrows move focus through the rows that can be chosen, round from the last to the first; a row is chosen
|
|
559
|
+
// (or checked) by a press, Enter or Space
|
|
560
|
+
const handleKeyDown = (event) => {
|
|
561
|
+
if (event.defaultPrevented || event.nativeEvent.isComposing)
|
|
562
|
+
return;
|
|
563
|
+
const rows = Array.from(event.currentTarget.querySelectorAll(':is([role="radio"], [role="checkbox"]):not([aria-disabled="true"])'));
|
|
564
|
+
if (!rows.length)
|
|
565
|
+
return;
|
|
566
|
+
const index = rows.indexOf(document.activeElement);
|
|
567
|
+
let next;
|
|
568
|
+
switch (event.key) {
|
|
569
|
+
case "ArrowDown":
|
|
570
|
+
case "ArrowRight":
|
|
571
|
+
next = rows[(index + 1) % rows.length];
|
|
572
|
+
break;
|
|
573
|
+
case "ArrowUp":
|
|
574
|
+
case "ArrowLeft":
|
|
575
|
+
next = rows[index <= 0 ? rows.length - 1 : index - 1];
|
|
576
|
+
break;
|
|
577
|
+
case "Home":
|
|
578
|
+
next = rows[0];
|
|
579
|
+
break;
|
|
580
|
+
case "End":
|
|
581
|
+
next = rows[rows.length - 1];
|
|
582
|
+
break;
|
|
583
|
+
default:
|
|
417
584
|
return;
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
585
|
+
}
|
|
586
|
+
event.preventDefault();
|
|
587
|
+
next?.focus({ preventScroll: true });
|
|
588
|
+
next?.scrollIntoView({ block: "nearest" });
|
|
589
|
+
};
|
|
590
|
+
const row = (option, none = false) => (_jsx(SelectChoiceRow, { option: option, none: none, checked: multiple
|
|
591
|
+
? (none ? checked.length === 0 : checked.includes(option.value))
|
|
592
|
+
: (none ? noneChosen : option.value === openingValue), focusable: (none ? NONE_OPTION_VALUE : option.value) === focusValue, onChoose: () => choose(option, none) }, none ? NONE_OPTION_VALUE : option.value));
|
|
593
|
+
return (_jsxs("div", { className: s.ChoiceList, role: multiple ? "group" : "radiogroup", "aria-label": name, onKeyDown: handleKeyDown, children: [noneRow && row({ value: NONE_OPTION_VALUE, label: noneLabel }, true), isOptionGroupArray(options)
|
|
594
|
+
? options.map((group) => _jsx(SelectChoiceGroup, { group: group, row: row }, group.label))
|
|
595
|
+
: options.map((option) => row(option))] }));
|
|
596
|
+
};
|
|
597
|
+
const SelectChoiceGroup = ({ group, row }) => {
|
|
598
|
+
const headingId = useId();
|
|
599
|
+
return (_jsxs("div", { role: "group", "aria-labelledby": headingId, className: s.ChoiceGroup, children: [_jsx("div", { id: headingId, className: s.ChoiceGroupHeading, children: group.label }), group.options.map((option) => row(option))] }));
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* 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,
|
|
603
|
+
* one line, a description 14 in the secondary text 4 under it. The chosen radio is the accent, with a dot. A multiple
|
|
604
|
+
* select's row has an 18 checkbox in that frame (CheckBoxCell's square), the accent with a check when checked.
|
|
605
|
+
*/
|
|
606
|
+
const SelectChoiceRow = ({ option, none, checked, focusable, onChoose }) => {
|
|
607
|
+
const { multiple, OptionView } = useSelectContext();
|
|
608
|
+
const { disabled, description, tooltip } = option;
|
|
609
|
+
return (_jsxs("div", { className: s.ChoiceRow, role: multiple ? "checkbox" : "radio", "aria-checked": checked, "aria-disabled": disabled || undefined, "data-disabled": disabled ? "" : undefined, tabIndex: focusable ? 0 : -1, onClick: () => { if (!disabled)
|
|
610
|
+
onChoose(); }, onKeyDown: (event) => {
|
|
611
|
+
if (event.target !== event.currentTarget || (event.key !== "Enter" && event.key !== " "))
|
|
612
|
+
return;
|
|
613
|
+
event.preventDefault();
|
|
614
|
+
if (!disabled)
|
|
615
|
+
onChoose();
|
|
616
|
+
}, children: [_jsx("span", { className: multiple ? s.ChoiceCheck : s.ChoiceRadio, "aria-hidden": "true" }), _jsxs("div", { className: s.ChoiceText, children: [_jsx("div", { className: s.ChoiceLabel, children: none ? option.label : _jsx(OptionView, { ...option }) }), description && _jsx("div", { className: s.ChoiceDescription, children: description }), tooltip && _jsx("div", { className: s.ChoiceDescription, children: tooltip.content })] })] }));
|
|
439
617
|
};
|
|
440
618
|
const CustomSelectMenuContext = createContext(null);
|
|
441
619
|
const useCustomSelectMenuContext = () => {
|