@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.
- package/README.md +24 -13
- package/package.json +127 -37
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +21 -20
- package/src/button.tsx +151 -25
- package/src/calendar.tsx +1019 -92
- package/src/checkbox.tsx +214 -52
- package/src/collections.ts +88 -5
- package/src/color.ts +1580 -23
- package/src/colorpicker.tsx +698 -153
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +635 -113
- package/src/command.tsx +78 -59
- package/src/date.ts +31 -9
- package/src/datefield.tsx +1451 -336
- package/src/datepicker.tsx +465 -114
- package/src/dialog.tsx +302 -115
- package/src/disclosure.tsx +81 -29
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +3 -6
- package/src/drag-and-drop.tsx +669 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/form.tsx +18 -18
- package/src/gridlist.tsx +912 -121
- package/src/group.tsx +146 -0
- package/src/index.ts +402 -0
- package/src/interactions/focus-events.ts +13 -5
- package/src/interactions/keyboard.ts +195 -2
- package/src/interactions/modality.ts +18 -6
- package/src/interactions/open-link.ts +46 -13
- package/src/interactions/press.ts +35 -18
- package/src/label.ts +18 -6
- package/src/link.tsx +146 -50
- package/src/listbox.tsx +615 -89
- package/src/live.ts +4 -0
- package/src/menu.tsx +182 -89
- package/src/menubar.tsx +21 -17
- package/src/navigation-tree.tsx +357 -0
- package/src/numberfield.tsx +164 -60
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +364 -62
- package/src/platform.ts +2 -1
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +109 -104
- package/src/radio.tsx +101 -27
- package/src/select.tsx +225 -145
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +73 -16
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +139 -44
- package/src/switch.tsx +47 -21
- package/src/table.tsx +0 -0
- package/src/tabs.tsx +198 -89
- package/src/tag.tsx +217 -32
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +103 -37
- package/src/toast-components.tsx +589 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +38 -0
- package/src/toggle.ts +68 -5
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +15 -10
- package/src/tooltip.tsx +46 -29
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +30 -1
- package/src/validation.ts +79 -22
- package/src/virtualizer.tsx +186 -23
package/src/live.ts
CHANGED
|
@@ -130,6 +130,10 @@ export function announce(
|
|
|
130
130
|
assertiveness: Assertiveness = "assertive",
|
|
131
131
|
timeout: number = DEFAULT_TIMEOUT,
|
|
132
132
|
): void {
|
|
133
|
+
// A region the page took out of the document says nothing, and an
|
|
134
|
+
// application that replaces the body's content does take it out.
|
|
135
|
+
if (announcer !== null && !announcer.isAttached()) destroyAnnouncer();
|
|
136
|
+
|
|
133
137
|
if (announcer !== null) {
|
|
134
138
|
announcer.announce(message, assertiveness, timeout);
|
|
135
139
|
return;
|
package/src/menu.tsx
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
|
+
cells,
|
|
25
26
|
type Accessor,
|
|
26
27
|
type Child,
|
|
27
28
|
For,
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
onCleanup,
|
|
36
37
|
provide,
|
|
37
38
|
createSignal,
|
|
39
|
+
Show,
|
|
38
40
|
} from "@barqjs/core";
|
|
39
41
|
import { isServer } from "@barqjs/web";
|
|
40
42
|
import { tryCleanup } from "@barqjs/primitives/utils";
|
|
@@ -47,7 +49,7 @@ import type {
|
|
|
47
49
|
Node,
|
|
48
50
|
SelectionMode,
|
|
49
51
|
} from "./collections.ts";
|
|
50
|
-
import { listState, type ListState } from "./collections.ts";
|
|
52
|
+
import { getItemCount, listState, type ListState } from "./collections.ts";
|
|
51
53
|
import {
|
|
52
54
|
contains,
|
|
53
55
|
focusWithoutScrolling,
|
|
@@ -56,6 +58,9 @@ import {
|
|
|
56
58
|
targetElement,
|
|
57
59
|
} from "./dom.ts";
|
|
58
60
|
import { Popover, popoverStateProps } from "./dialog.tsx";
|
|
61
|
+
import { useAutocompleteCollection } from "./autocomplete.tsx";
|
|
62
|
+
import { SelectionIndicatorProvider } from "./selection-indicator.tsx";
|
|
63
|
+
import { SharedElementTransition } from "./shared-element-transition.tsx";
|
|
59
64
|
import { focusRing } from "./focus.ts";
|
|
60
65
|
import { hover } from "./interactions/hover.ts";
|
|
61
66
|
import { getInteractionModality, isFocusVisible } from "./interactions/modality.ts";
|
|
@@ -116,7 +121,7 @@ export interface MenuOptions {
|
|
|
116
121
|
"aria-labelledby"?: MaybeAccessor<string | undefined>;
|
|
117
122
|
/** Called when an item is chosen and the menu should go away. */
|
|
118
123
|
onClose?: () => void;
|
|
119
|
-
onAction?: (key: Key) => void;
|
|
124
|
+
onAction?: (key: Key, value?: unknown) => void;
|
|
120
125
|
/**
|
|
121
126
|
* Chained BEFORE the collection's own key handling.
|
|
122
127
|
*
|
|
@@ -232,7 +237,8 @@ export interface MenuItemOptions {
|
|
|
232
237
|
onToggle?: () => void;
|
|
233
238
|
/** Called when the item is chosen, before the menu closes; preventing it keeps the menu open. */
|
|
234
239
|
onSelect?: (event: MenuSelectEvent) => void;
|
|
235
|
-
|
|
240
|
+
/** Called with the item's key and the value it was built from. */
|
|
241
|
+
onAction?: (key: Key, value?: unknown) => void;
|
|
236
242
|
onClose?: () => void;
|
|
237
243
|
}
|
|
238
244
|
|
|
@@ -342,7 +348,7 @@ export function menuItem(options: MenuItemOptions, state: ListState<unknown>): M
|
|
|
342
348
|
|
|
343
349
|
const itemAction = node()?.props?.onAction;
|
|
344
350
|
if (typeof itemAction === "function") (itemAction as () => void)();
|
|
345
|
-
options.onAction?.(options.key);
|
|
351
|
+
options.onAction?.(options.key, node()?.value ?? undefined);
|
|
346
352
|
|
|
347
353
|
const closes = !prevented && shouldClose(event);
|
|
348
354
|
// Followed here rather than by the collection, which was told to leave
|
|
@@ -407,8 +413,9 @@ export function menuItem(options: MenuItemOptions, state: ListState<unknown>): M
|
|
|
407
413
|
"aria-controls": () => access(options["aria-controls"]),
|
|
408
414
|
"aria-posinset": () =>
|
|
409
415
|
access(options.isVirtualized) === true ? (node()?.index ?? 0) + 1 : undefined,
|
|
416
|
+
// Items only: a section is not a member of the set.
|
|
410
417
|
"aria-setsize": () =>
|
|
411
|
-
access(options.isVirtualized) === true ? state.collection()
|
|
418
|
+
access(options.isVirtualized) === true ? getItemCount(state.collection()) : undefined,
|
|
412
419
|
}),
|
|
413
420
|
};
|
|
414
421
|
}
|
|
@@ -1269,8 +1276,10 @@ interface MenuContextValue {
|
|
|
1269
1276
|
*/
|
|
1270
1277
|
root: RootMenuTriggerState;
|
|
1271
1278
|
shouldUseVirtualFocus: Accessor<boolean | undefined>;
|
|
1272
|
-
onAction: Accessor<((key: Key) => void) | undefined>;
|
|
1279
|
+
onAction: Accessor<((key: Key, value?: unknown) => void) | undefined>;
|
|
1273
1280
|
onClose: Accessor<(() => void) | undefined>;
|
|
1281
|
+
/** Whether choosing an item closes the menu, for every item that does not say. */
|
|
1282
|
+
shouldCloseOnSelect?: Accessor<boolean | undefined>;
|
|
1274
1283
|
/**
|
|
1275
1284
|
* Where a `<MenuItem>` written as a child registers itself.
|
|
1276
1285
|
*
|
|
@@ -1494,9 +1503,9 @@ export interface MenuTriggerComponentProps {
|
|
|
1494
1503
|
* The `<Menu>` inside puts itself in a popover anchored to the button and
|
|
1495
1504
|
* renders only while open, so neither has to be told about the other.
|
|
1496
1505
|
*/
|
|
1497
|
-
export function MenuTrigger(props:
|
|
1506
|
+
export function MenuTrigger(props: MenuTriggerComponentProps) {
|
|
1498
1507
|
const triggerRef = makeRef<HTMLElement>();
|
|
1499
|
-
const options = fromProps(props);
|
|
1508
|
+
const options = fromProps(cells(props));
|
|
1500
1509
|
const state = menuTriggerState(options);
|
|
1501
1510
|
|
|
1502
1511
|
const { menuTriggerProps, menuProps } = menuTrigger(options, state);
|
|
@@ -1532,13 +1541,13 @@ export interface MenuButtonComponentProps extends StyleProps {
|
|
|
1532
1541
|
}
|
|
1533
1542
|
|
|
1534
1543
|
/** The button an enclosing {@link MenuTrigger} opens its menu from. */
|
|
1535
|
-
export function MenuButton(props:
|
|
1544
|
+
export function MenuButton(props: MenuButtonComponentProps) {
|
|
1536
1545
|
const menuTriggerValue = useMenuTrigger();
|
|
1537
1546
|
if (menuTriggerValue === null) {
|
|
1538
1547
|
throw new Error("A MenuButton must be rendered inside a MenuTrigger.");
|
|
1539
1548
|
}
|
|
1540
1549
|
|
|
1541
|
-
const options = fromProps(props);
|
|
1550
|
+
const options = fromProps(cells(props));
|
|
1542
1551
|
const { buttonProps, isPressed } = button(
|
|
1543
1552
|
{ ...(options as ButtonOptions), ...menuTriggerValue.menuTriggerProps },
|
|
1544
1553
|
menuTriggerValue.triggerRef,
|
|
@@ -1553,20 +1562,20 @@ export function MenuButton(props: Incoming<MenuButtonComponentProps>) {
|
|
|
1553
1562
|
hoverProps,
|
|
1554
1563
|
focusProps,
|
|
1555
1564
|
filterDOMProps(options, { global: true }),
|
|
1556
|
-
styleProps(props),
|
|
1565
|
+
styleProps(cells(props)),
|
|
1557
1566
|
{
|
|
1558
1567
|
"data-pressed": isPressed,
|
|
1559
1568
|
"data-hovered": isHovered,
|
|
1560
1569
|
"data-focused": isFocused,
|
|
1561
1570
|
"data-focus-visible": showsRing,
|
|
1562
|
-
"data-disabled": () => props.isDisabled
|
|
1571
|
+
"data-disabled": () => props.isDisabled === true,
|
|
1563
1572
|
"data-state": () => (menuTriggerValue.state.isOpen() ? "open" : "closed"),
|
|
1564
|
-
"data-testid": () => props["data-testid"]
|
|
1573
|
+
"data-testid": () => props["data-testid"],
|
|
1565
1574
|
},
|
|
1566
1575
|
);
|
|
1567
1576
|
|
|
1568
1577
|
return (
|
|
1569
|
-
<button {...elementProps} ref={mergeRefs(menuTriggerValue.triggerRef.set, props.ref
|
|
1578
|
+
<button {...elementProps} ref={mergeRefs(menuTriggerValue.triggerRef.set, props.ref)}>
|
|
1570
1579
|
{props.children}
|
|
1571
1580
|
</button>
|
|
1572
1581
|
);
|
|
@@ -1642,22 +1651,22 @@ export interface ContextMenuTriggerComponentProps extends StyleProps {
|
|
|
1642
1651
|
* inside the region, so a region whose content is not focusable needs a
|
|
1643
1652
|
* `tabIndex` of its own or there is no keyboard route to the menu at all.
|
|
1644
1653
|
*/
|
|
1645
|
-
export function ContextMenuTrigger(props:
|
|
1654
|
+
export function ContextMenuTrigger(props: ContextMenuTriggerComponentProps) {
|
|
1646
1655
|
const trigger = useMenuTrigger();
|
|
1647
1656
|
if (trigger === null) {
|
|
1648
1657
|
throw new Error("A ContextMenuTrigger must be rendered inside a ContextMenu.");
|
|
1649
1658
|
}
|
|
1650
1659
|
|
|
1651
|
-
const options = fromProps(props);
|
|
1660
|
+
const options = fromProps(cells(props));
|
|
1652
1661
|
const elementProps = mergeProps(
|
|
1653
1662
|
trigger.menuTriggerProps,
|
|
1654
1663
|
filterDOMProps(options, { global: true, labelable: true }),
|
|
1655
|
-
styleProps(props),
|
|
1656
|
-
{ "data-testid": () => props["data-testid"]
|
|
1664
|
+
styleProps(cells(props)),
|
|
1665
|
+
{ "data-testid": () => props["data-testid"] },
|
|
1657
1666
|
);
|
|
1658
1667
|
|
|
1659
1668
|
return (
|
|
1660
|
-
<div {...elementProps} ref={mergeRefs(trigger.triggerRef.set, props.ref
|
|
1669
|
+
<div {...elementProps} ref={mergeRefs(trigger.triggerRef.set, props.ref)}>
|
|
1661
1670
|
{props.children}
|
|
1662
1671
|
</div>
|
|
1663
1672
|
);
|
|
@@ -1690,8 +1699,16 @@ export interface MenuComponentProps<T> extends StyleProps, ItemAccessors<T> {
|
|
|
1690
1699
|
/** Distance along the trigger's edge, from where `placement` aligns it. @default 0 */
|
|
1691
1700
|
crossOffset?: number;
|
|
1692
1701
|
ref?: RefTarget<HTMLUListElement>;
|
|
1702
|
+
/**
|
|
1703
|
+
* Whether choosing an item closes the menu, for every item that does not
|
|
1704
|
+
* say for itself. @default by the selection mode, as {@link menuItem} says
|
|
1705
|
+
*/
|
|
1706
|
+
shouldCloseOnSelect?: boolean;
|
|
1707
|
+
/** Shown, as the menu's one entry, when it has no items. */
|
|
1708
|
+
renderEmpty?: Child;
|
|
1693
1709
|
onSelectionChange?: (keys: "all" | Set<Key>) => void;
|
|
1694
|
-
|
|
1710
|
+
/** Called with the chosen item's key, and the value it was built from. */
|
|
1711
|
+
onAction?: (key: Key, value: T) => void;
|
|
1695
1712
|
onClose?: () => void;
|
|
1696
1713
|
}
|
|
1697
1714
|
|
|
@@ -1706,7 +1723,7 @@ export interface MenuComponentProps<T> extends StyleProps, ItemAccessors<T> {
|
|
|
1706
1723
|
* once has no reason to render them twice, once to discover them and once to
|
|
1707
1724
|
* show them.
|
|
1708
1725
|
*/
|
|
1709
|
-
export function Menu<T>(props:
|
|
1726
|
+
export function Menu<T>(props: MenuComponentProps<T>) {
|
|
1710
1727
|
const enclosing = useSubmenuTrigger();
|
|
1711
1728
|
const parent = useEnclosingMenu();
|
|
1712
1729
|
// The submenu of the trigger this menu sits in, rather than of a trigger
|
|
@@ -1728,20 +1745,20 @@ export function Menu<T>(props: Incoming<MenuComponentProps<T>>) {
|
|
|
1728
1745
|
if (!isOpen) submenu.state.close();
|
|
1729
1746
|
}}
|
|
1730
1747
|
placement={
|
|
1731
|
-
props.placement
|
|
1748
|
+
props.placement ?? access(submenu.popoverProps.placement as MaybeAccessor<Placement>)
|
|
1732
1749
|
}
|
|
1733
|
-
offset={props.offset
|
|
1734
|
-
crossOffset={props.crossOffset
|
|
1750
|
+
offset={props.offset ?? 0}
|
|
1751
|
+
crossOffset={props.crossOffset}
|
|
1735
1752
|
isNested
|
|
1736
1753
|
>
|
|
1737
|
-
<MenuList of={props} trigger={null} />
|
|
1754
|
+
<MenuList of={cells(props)} trigger={null} />
|
|
1738
1755
|
</Popover>
|
|
1739
1756
|
);
|
|
1740
1757
|
}
|
|
1741
1758
|
|
|
1742
1759
|
const trigger = useMenuTrigger();
|
|
1743
1760
|
|
|
1744
|
-
if (trigger === null) return <MenuList of={props} trigger={null} />;
|
|
1761
|
+
if (trigger === null) return <MenuList of={cells(props)} trigger={null} />;
|
|
1745
1762
|
|
|
1746
1763
|
// The list is written inside the popover rather than built and handed to it,
|
|
1747
1764
|
// so it is a Block: nothing is constructed until the menu opens, and the
|
|
@@ -1752,11 +1769,11 @@ export function Menu<T>(props: Incoming<MenuComponentProps<T>>) {
|
|
|
1752
1769
|
triggerRect={trigger.anchorRect()}
|
|
1753
1770
|
isOpen={trigger.state.isOpen()}
|
|
1754
1771
|
onOpenChange={trigger.state.setOpen}
|
|
1755
|
-
placement={props.placement
|
|
1756
|
-
offset={props.offset
|
|
1757
|
-
crossOffset={props.crossOffset
|
|
1772
|
+
placement={props.placement ?? trigger.placement}
|
|
1773
|
+
offset={props.offset ?? trigger.offset}
|
|
1774
|
+
crossOffset={props.crossOffset}
|
|
1758
1775
|
>
|
|
1759
|
-
<MenuList of={props} trigger={trigger} />
|
|
1776
|
+
<MenuList of={cells(props)} trigger={trigger} />
|
|
1760
1777
|
</Popover>
|
|
1761
1778
|
);
|
|
1762
1779
|
}
|
|
@@ -1767,11 +1784,11 @@ interface MenuListProps<T> {
|
|
|
1767
1784
|
trigger: MenuTriggerValue | null;
|
|
1768
1785
|
}
|
|
1769
1786
|
|
|
1770
|
-
function MenuList<T>(listProps:
|
|
1787
|
+
function MenuList<T>(listProps: MenuListProps<T>) {
|
|
1771
1788
|
const domRef = makeRef<HTMLUListElement>();
|
|
1772
|
-
const props = listProps.of
|
|
1789
|
+
const props = listProps.of;
|
|
1773
1790
|
const options = fromProps(props as unknown as Incoming<Record<string, unknown>>);
|
|
1774
|
-
const trigger = listProps.trigger
|
|
1791
|
+
const trigger = listProps.trigger;
|
|
1775
1792
|
const enclosing = useEnclosingMenu();
|
|
1776
1793
|
const trigger_ = useSubmenuTrigger();
|
|
1777
1794
|
// The same guard `<Menu>` applies: a menu nested inside a submenu's items is
|
|
@@ -1787,12 +1804,16 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1787
1804
|
const written = props.items === undefined ? staticCollection() : null;
|
|
1788
1805
|
// The trigger at the top of the tree, which a submenu is not handed.
|
|
1789
1806
|
const treeKeyDown = useMenuTrigger()?.onMenuKeyDown;
|
|
1807
|
+
// Inside an `<Autocomplete>` the field's query narrows the items, and the
|
|
1808
|
+
// field keeps focus while the arrows move a highlight here.
|
|
1809
|
+
const auto = useAutocompleteCollection();
|
|
1790
1810
|
|
|
1791
1811
|
const state = listState<T>({
|
|
1792
1812
|
...(options as ListStateOptions<T>),
|
|
1793
1813
|
...(written === null
|
|
1794
1814
|
? {}
|
|
1795
1815
|
: ({ items: written.entries, ...staticAccessors } as unknown as ListStateOptions<T>)),
|
|
1816
|
+
filter: auto?.filterNodes as ListStateOptions<T>["filter"],
|
|
1796
1817
|
onSelectionChange: (keys) => props.onSelectionChange?.()?.(keys),
|
|
1797
1818
|
});
|
|
1798
1819
|
|
|
@@ -1817,6 +1838,16 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1817
1838
|
},
|
|
1818
1839
|
}),
|
|
1819
1840
|
ref: domRef,
|
|
1841
|
+
// The caller's own name first; inside an autocomplete, the one it gives.
|
|
1842
|
+
"aria-label": () =>
|
|
1843
|
+
props["aria-label"]?.() ??
|
|
1844
|
+
(props["aria-labelledby"]?.() === undefined
|
|
1845
|
+
? auto?.collectionProps["aria-label"]
|
|
1846
|
+
: undefined),
|
|
1847
|
+
shouldUseVirtualFocus: () => auto?.collectionProps.shouldUseVirtualFocus() === true,
|
|
1848
|
+
disallowTypeAhead: () =>
|
|
1849
|
+
access((options as unknown as MenuOptions).disallowTypeAhead) ??
|
|
1850
|
+
auto?.collectionProps.disallowTypeAhead(),
|
|
1820
1851
|
// A submenu with no label of its own is named by the ITEM that opens it,
|
|
1821
1852
|
// which is what a screen reader announces on the way in.
|
|
1822
1853
|
"aria-labelledby": () =>
|
|
@@ -1829,6 +1860,7 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1829
1860
|
) ?? undefined)),
|
|
1830
1861
|
autoFocus: () =>
|
|
1831
1862
|
props.autoFocus?.() ??
|
|
1863
|
+
(auto === null ? undefined : auto.collectionProps.autoFocus() || undefined) ??
|
|
1832
1864
|
(submenu === null
|
|
1833
1865
|
? trigger === null
|
|
1834
1866
|
? undefined
|
|
@@ -1846,14 +1878,25 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1846
1878
|
baseId,
|
|
1847
1879
|
menuRef: domRef,
|
|
1848
1880
|
root,
|
|
1849
|
-
shouldUseVirtualFocus: () =>
|
|
1850
|
-
onAction: () => props.onAction?.(),
|
|
1881
|
+
shouldUseVirtualFocus: () => auto?.collectionProps.shouldUseVirtualFocus(),
|
|
1882
|
+
onAction: () => props.onAction?.() as ((key: Key, value?: unknown) => void) | undefined,
|
|
1851
1883
|
onClose: () => close,
|
|
1884
|
+
shouldCloseOnSelect: () => props.shouldCloseOnSelect?.(),
|
|
1852
1885
|
staticItems: written ?? undefined,
|
|
1853
1886
|
};
|
|
1854
1887
|
install(owner, MenuContext, () => value);
|
|
1855
1888
|
}
|
|
1856
1889
|
|
|
1890
|
+
if (auto !== null) {
|
|
1891
|
+
onCleanup(
|
|
1892
|
+
auto.connect({
|
|
1893
|
+
ref: domRef,
|
|
1894
|
+
state,
|
|
1895
|
+
idFor: (key) => menuItemIdFor(baseId(), key),
|
|
1896
|
+
}),
|
|
1897
|
+
);
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1857
1900
|
const elementProps = mergeProps(
|
|
1858
1901
|
menuProps,
|
|
1859
1902
|
filterDOMProps(options, { global: true }),
|
|
@@ -1862,7 +1905,9 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1862
1905
|
id: () =>
|
|
1863
1906
|
access(
|
|
1864
1907
|
(submenu?.submenuProps.id ?? trigger?.menuProps.id) as MaybeAccessor<string | undefined>,
|
|
1865
|
-
)
|
|
1908
|
+
) ??
|
|
1909
|
+
access((options as unknown as { id?: MaybeAccessor<string | undefined> }).id) ??
|
|
1910
|
+
auto?.collectionProps.id(),
|
|
1866
1911
|
"data-testid": () => props["data-testid"]?.(),
|
|
1867
1912
|
"data-empty": () => state.collection().size === 0,
|
|
1868
1913
|
},
|
|
@@ -1871,10 +1916,21 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1871
1916
|
popoverStateProps(),
|
|
1872
1917
|
);
|
|
1873
1918
|
|
|
1919
|
+
// A menu with nothing in it still says why, as its one entry: a menu
|
|
1920
|
+
// with no items at all is announced as empty with no reason given.
|
|
1921
|
+
const empty = (
|
|
1922
|
+
<Show when={state.collection().size === 0 && props.renderEmpty?.() !== undefined}>
|
|
1923
|
+
<li role="menuitem" aria-disabled="true" style={{ display: "contents" }}>
|
|
1924
|
+
{props.renderEmpty?.()}
|
|
1925
|
+
</li>
|
|
1926
|
+
</Show>
|
|
1927
|
+
);
|
|
1928
|
+
|
|
1874
1929
|
if (written !== null) {
|
|
1875
1930
|
return (
|
|
1876
1931
|
<ul {...elementProps} ref={mergeRefs(domRef.set, submenu?.submenuRef.set, props.ref?.())}>
|
|
1877
|
-
{props.children}
|
|
1932
|
+
<SharedElementTransition>{props.children}</SharedElementTransition>
|
|
1933
|
+
{empty}
|
|
1878
1934
|
</ul>
|
|
1879
1935
|
);
|
|
1880
1936
|
}
|
|
@@ -1883,12 +1939,15 @@ function MenuList<T>(listProps: Incoming<MenuListProps<T>>) {
|
|
|
1883
1939
|
|
|
1884
1940
|
return (
|
|
1885
1941
|
<ul {...elementProps} ref={mergeRefs(domRef.set, submenu?.submenuRef.set, props.ref?.())}>
|
|
1886
|
-
<
|
|
1887
|
-
{(
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1942
|
+
<SharedElementTransition>
|
|
1943
|
+
<For each={() => [...state.collection()]}>
|
|
1944
|
+
{(node: Node<T>) => {
|
|
1945
|
+
provideMenuNode(node);
|
|
1946
|
+
return render(node.value as T);
|
|
1947
|
+
}}
|
|
1948
|
+
</For>
|
|
1949
|
+
</SharedElementTransition>
|
|
1950
|
+
{empty}
|
|
1892
1951
|
</ul>
|
|
1893
1952
|
);
|
|
1894
1953
|
}
|
|
@@ -1947,7 +2006,7 @@ export interface MenuItemComponentProps extends StyleProps {
|
|
|
1947
2006
|
* modifiers the press carried, which is what keeps a Control-click a new tab
|
|
1948
2007
|
* and lets the menu close in the same gesture. A disabled one has no `href`.
|
|
1949
2008
|
*/
|
|
1950
|
-
export function MenuItem(props:
|
|
2009
|
+
export function MenuItem(props: MenuItemComponentProps) {
|
|
1951
2010
|
const domRef = makeRef<HTMLElement>();
|
|
1952
2011
|
const list = useMenu();
|
|
1953
2012
|
const enclosing = useSubmenuTrigger();
|
|
@@ -1959,9 +2018,10 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
1959
2018
|
? enclosing
|
|
1960
2019
|
: null;
|
|
1961
2020
|
const group = registry === undefined ? null : (getContext(MenuRadioGroupContext) ?? null);
|
|
2021
|
+
const sectionCloses = getContext(MenuSectionCloseContext) ?? null;
|
|
1962
2022
|
const ownType = (): MenuItemType | undefined => {
|
|
1963
2023
|
if (registry === undefined) return undefined;
|
|
1964
|
-
const declared = props.type
|
|
2024
|
+
const declared = props.type;
|
|
1965
2025
|
if (declared !== undefined) return declared;
|
|
1966
2026
|
if (group !== null && props.value !== undefined) return "radio";
|
|
1967
2027
|
return props.isSelected !== undefined ||
|
|
@@ -1974,24 +2034,24 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
1974
2034
|
registry === undefined
|
|
1975
2035
|
? null
|
|
1976
2036
|
: toggleState({
|
|
1977
|
-
isSelected: () => props.isSelected
|
|
1978
|
-
defaultSelected: () => props.defaultSelected
|
|
1979
|
-
onChange: (isSelected) => props.onChange?.(
|
|
2037
|
+
isSelected: () => props.isSelected,
|
|
2038
|
+
defaultSelected: () => props.defaultSelected,
|
|
2039
|
+
onChange: (isSelected) => props.onChange?.(isSelected),
|
|
1980
2040
|
});
|
|
1981
2041
|
|
|
1982
2042
|
const written =
|
|
1983
2043
|
registry === undefined
|
|
1984
2044
|
? null
|
|
1985
2045
|
: staticItem(registry, {
|
|
1986
|
-
key: opensWritten?.triggerKey ?? props.id
|
|
1987
|
-
textValue: () => props.textValue
|
|
2046
|
+
key: opensWritten?.triggerKey ?? props.id,
|
|
2047
|
+
textValue: () => props.textValue,
|
|
1988
2048
|
props: () => ({
|
|
1989
|
-
isDisabled: props.isDisabled
|
|
1990
|
-
href: props.href
|
|
1991
|
-
target: props.target
|
|
1992
|
-
rel: props.rel
|
|
1993
|
-
download: props.download
|
|
1994
|
-
onAction: props.onAction
|
|
2049
|
+
isDisabled: props.isDisabled === true,
|
|
2050
|
+
href: props.href,
|
|
2051
|
+
target: props.target,
|
|
2052
|
+
rel: props.rel,
|
|
2053
|
+
download: props.download,
|
|
2054
|
+
onAction: props.onAction,
|
|
1995
2055
|
}),
|
|
1996
2056
|
});
|
|
1997
2057
|
const node: Pick<Node<unknown>, "key" | "props"> = written === null
|
|
@@ -2013,21 +2073,23 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2013
2073
|
key: node.key,
|
|
2014
2074
|
ref: domRef,
|
|
2015
2075
|
baseId: list.baseId,
|
|
2016
|
-
"aria-label": () => props["aria-label"]
|
|
2017
|
-
isDisabled: () => props.isDisabled
|
|
2018
|
-
shouldCloseOnSelect: () =>
|
|
2076
|
+
"aria-label": () => props["aria-label"],
|
|
2077
|
+
isDisabled: () => props.isDisabled === true || node.props?.isDisabled === true,
|
|
2078
|
+
shouldCloseOnSelect: () =>
|
|
2079
|
+
props.shouldCloseOnSelect ?? sectionCloses?.() ?? list.shouldCloseOnSelect?.(),
|
|
2019
2080
|
shouldUseVirtualFocus: list.shouldUseVirtualFocus,
|
|
2020
2081
|
type: ownType,
|
|
2021
2082
|
isSelected: () =>
|
|
2022
|
-
ownType() === "radio" ? group?.value() === props.value
|
|
2083
|
+
ownType() === "radio" ? group?.value() === props.value : ticked?.isSelected(),
|
|
2023
2084
|
onToggle: () => {
|
|
2024
|
-
const value = props.value
|
|
2085
|
+
const value = props.value;
|
|
2025
2086
|
if (ownType() === "radio") {
|
|
2026
2087
|
if (value !== undefined) group?.setValue(value);
|
|
2027
2088
|
} else ticked?.toggle();
|
|
2028
2089
|
},
|
|
2029
|
-
onSelect: (event) => props.onSelect?.(
|
|
2030
|
-
|
|
2090
|
+
onSelect: (event) => props.onSelect?.(event),
|
|
2091
|
+
// A written item was built from no value of the caller's.
|
|
2092
|
+
onAction: (key, value) => list.onAction()?.(key, written === null ? value : undefined),
|
|
2031
2093
|
onClose: () => list.onClose()?.(),
|
|
2032
2094
|
...(opens as unknown as Record<string, never>),
|
|
2033
2095
|
},
|
|
@@ -2039,7 +2101,7 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2039
2101
|
|
|
2040
2102
|
const toHref = router().href;
|
|
2041
2103
|
const linked = (name: "href" | "target" | "rel" | "download"): unknown =>
|
|
2042
|
-
props[name]?.() ?? node.props?.[name];
|
|
2104
|
+
cells(props)[name]?.() ?? node.props?.[name];
|
|
2043
2105
|
const href = (): string | undefined => {
|
|
2044
2106
|
const to = linked("href");
|
|
2045
2107
|
return typeof to === "string" ? to : undefined;
|
|
@@ -2055,8 +2117,12 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2055
2117
|
hoverProps,
|
|
2056
2118
|
focusProps,
|
|
2057
2119
|
// A written item's `id` is its key; the element's id is derived from it.
|
|
2058
|
-
filterDOMProps(fromProps(props), {
|
|
2059
|
-
|
|
2120
|
+
filterDOMProps(fromProps(cells(props)), {
|
|
2121
|
+
global: true,
|
|
2122
|
+
labelable: true,
|
|
2123
|
+
id: written === null,
|
|
2124
|
+
}),
|
|
2125
|
+
styleProps(cells(props)),
|
|
2060
2126
|
{
|
|
2061
2127
|
"data-selected": isSelected,
|
|
2062
2128
|
"data-focused": isFocused,
|
|
@@ -2066,12 +2132,18 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2066
2132
|
"data-pressed": isPressed,
|
|
2067
2133
|
"data-hovered": isHovered,
|
|
2068
2134
|
"data-disabled": isDisabled,
|
|
2135
|
+
"data-selection-mode": () => {
|
|
2136
|
+
const mode = list.state.selectionManager().selectionMode;
|
|
2137
|
+
return mode === "none" ? undefined : mode;
|
|
2138
|
+
},
|
|
2139
|
+
"data-has-submenu": () => submenu !== null,
|
|
2140
|
+
"data-open": () => submenu?.state.isOpen() === true,
|
|
2069
2141
|
"data-state": () => {
|
|
2070
2142
|
if (submenu !== null) return submenu.state.isOpen() ? "open" : "closed";
|
|
2071
2143
|
if (!checks()) return undefined;
|
|
2072
2144
|
return isSelected() ? "checked" : "unchecked";
|
|
2073
2145
|
},
|
|
2074
|
-
"data-testid": () => props["data-testid"]
|
|
2146
|
+
"data-testid": () => props["data-testid"],
|
|
2075
2147
|
},
|
|
2076
2148
|
);
|
|
2077
2149
|
|
|
@@ -2099,7 +2171,9 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2099
2171
|
return (
|
|
2100
2172
|
<li role="none">
|
|
2101
2173
|
<a {...linkProps} ref={anchorRef}>
|
|
2102
|
-
{
|
|
2174
|
+
<SelectionIndicatorProvider isSelected={isSelected()}>
|
|
2175
|
+
{props.children}
|
|
2176
|
+
</SelectionIndicatorProvider>
|
|
2103
2177
|
</a>
|
|
2104
2178
|
</li>
|
|
2105
2179
|
);
|
|
@@ -2108,9 +2182,11 @@ export function MenuItem(props: Incoming<MenuItemComponentProps>) {
|
|
|
2108
2182
|
return (
|
|
2109
2183
|
<li
|
|
2110
2184
|
{...elementProps}
|
|
2111
|
-
ref={mergeRefs(domRef.set, submenu?.triggerRef.set, written?.ref, props.ref
|
|
2185
|
+
ref={mergeRefs(domRef.set, submenu?.triggerRef.set, written?.ref, props.ref)}
|
|
2112
2186
|
>
|
|
2113
|
-
{
|
|
2187
|
+
<SelectionIndicatorProvider isSelected={isSelected()}>
|
|
2188
|
+
{props.children}
|
|
2189
|
+
</SelectionIndicatorProvider>
|
|
2114
2190
|
</li>
|
|
2115
2191
|
);
|
|
2116
2192
|
}
|
|
@@ -2122,6 +2198,9 @@ interface MenuRadioGroupValue {
|
|
|
2122
2198
|
|
|
2123
2199
|
const MenuRadioGroupContext = createContext<MenuRadioGroupValue | null>(null);
|
|
2124
2200
|
|
|
2201
|
+
/** A section's `shouldCloseOnSelect`, for the items inside it. */
|
|
2202
|
+
const MenuSectionCloseContext = createContext<Accessor<boolean | undefined> | null>(null);
|
|
2203
|
+
|
|
2125
2204
|
interface MenuGroupHeading {
|
|
2126
2205
|
id: Accessor<string>;
|
|
2127
2206
|
readonly name: (has: boolean) => void;
|
|
@@ -2157,8 +2236,8 @@ interface WrittenGroupProps extends StyleProps {
|
|
|
2157
2236
|
* It registers nothing: the items inside are the menu's own, in document
|
|
2158
2237
|
* order, so the arrows cross the boundary without the group taking part.
|
|
2159
2238
|
*/
|
|
2160
|
-
function WrittenGroup(groupProps:
|
|
2161
|
-
const props = groupProps.of
|
|
2239
|
+
function WrittenGroup(groupProps: { of: Incoming<WrittenGroupProps> }) {
|
|
2240
|
+
const props = groupProps.of;
|
|
2162
2241
|
const headingId = id();
|
|
2163
2242
|
const [isNamed, setNamed] = createSignal(false, { ownedWrite: true });
|
|
2164
2243
|
const hasHeading = (): boolean => props.heading?.() !== undefined;
|
|
@@ -2217,12 +2296,12 @@ export interface MenuRadioGroupComponentProps extends StyleProps {
|
|
|
2217
2296
|
* The group owns the value rather than the menu, because a written menu can
|
|
2218
2297
|
* hold two of these beside a checkbox and a plain item.
|
|
2219
2298
|
*/
|
|
2220
|
-
export function MenuRadioGroup(props:
|
|
2299
|
+
export function MenuRadioGroup(props: MenuRadioGroupComponentProps) {
|
|
2221
2300
|
const [value, setValue] = controllable<string | undefined>(
|
|
2222
|
-
() => props.value
|
|
2223
|
-
() => props.defaultValue
|
|
2301
|
+
() => props.value,
|
|
2302
|
+
() => props.defaultValue,
|
|
2224
2303
|
(next) => {
|
|
2225
|
-
if (next !== undefined) props.onValueChange?.(
|
|
2304
|
+
if (next !== undefined) props.onValueChange?.(next);
|
|
2226
2305
|
},
|
|
2227
2306
|
);
|
|
2228
2307
|
const group: MenuRadioGroupValue = { value, setValue };
|
|
@@ -2230,7 +2309,7 @@ export function MenuRadioGroup(props: Incoming<MenuRadioGroupComponentProps>) {
|
|
|
2230
2309
|
return provide(
|
|
2231
2310
|
MenuRadioGroupContext,
|
|
2232
2311
|
() => group,
|
|
2233
|
-
() => <WrittenGroup of={props} />,
|
|
2312
|
+
() => <WrittenGroup of={cells(props)} />,
|
|
2234
2313
|
);
|
|
2235
2314
|
}
|
|
2236
2315
|
|
|
@@ -2238,6 +2317,8 @@ export interface MenuSectionComponentProps<T> extends StyleProps {
|
|
|
2238
2317
|
heading?: Child;
|
|
2239
2318
|
"aria-label"?: string;
|
|
2240
2319
|
"aria-labelledby"?: string;
|
|
2320
|
+
/** Whether choosing one of this section's items closes the menu. @default the menu's */
|
|
2321
|
+
shouldCloseOnSelect?: boolean;
|
|
2241
2322
|
/** How one child of this section renders; or, in a written menu, its items. */
|
|
2242
2323
|
children: ((item: T) => Child) | Child;
|
|
2243
2324
|
}
|
|
@@ -2260,30 +2341,42 @@ export interface MenuSectionComponentProps<T> extends StyleProps {
|
|
|
2260
2341
|
* </Menu>
|
|
2261
2342
|
* ```
|
|
2262
2343
|
*/
|
|
2263
|
-
export function MenuSection<T>(props:
|
|
2344
|
+
export function MenuSection<T>(props: MenuSectionComponentProps<T>) {
|
|
2345
|
+
const enclosing = getContext(MenuSectionCloseContext) ?? null;
|
|
2346
|
+
const closes = (): boolean | undefined => props.shouldCloseOnSelect ?? enclosing?.();
|
|
2264
2347
|
if (useMenu().staticItems !== undefined) {
|
|
2265
|
-
return
|
|
2348
|
+
return provide(
|
|
2349
|
+
MenuSectionCloseContext,
|
|
2350
|
+
() => closes,
|
|
2351
|
+
() => <WrittenGroup of={cells(props)} />,
|
|
2352
|
+
);
|
|
2266
2353
|
}
|
|
2267
2354
|
|
|
2268
2355
|
const node = useMenuNode();
|
|
2269
2356
|
|
|
2270
2357
|
const { itemProps, headingProps, groupProps } = menuSection({
|
|
2271
|
-
heading: () => props.heading
|
|
2272
|
-
"aria-label": () => props["aria-label"]
|
|
2358
|
+
heading: () => props.heading,
|
|
2359
|
+
"aria-label": () => props["aria-label"],
|
|
2273
2360
|
});
|
|
2274
2361
|
|
|
2275
|
-
const render = props.children;
|
|
2362
|
+
const render = cells(props).children;
|
|
2276
2363
|
|
|
2277
2364
|
return (
|
|
2278
2365
|
<li {...itemProps}>
|
|
2279
2366
|
<span {...headingProps}>{props.heading}</span>
|
|
2280
|
-
<ul {...mergeProps(groupProps, styleProps(props))}>
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2367
|
+
<ul {...mergeProps(groupProps, styleProps(cells(props)))}>
|
|
2368
|
+
{provide(
|
|
2369
|
+
MenuSectionCloseContext,
|
|
2370
|
+
() => closes,
|
|
2371
|
+
() => (
|
|
2372
|
+
<For each={() => [...node.childNodes]}>
|
|
2373
|
+
{(child: Node<unknown>) => {
|
|
2374
|
+
provideMenuNode(child);
|
|
2375
|
+
return render(child.value as T);
|
|
2376
|
+
}}
|
|
2377
|
+
</For>
|
|
2378
|
+
),
|
|
2379
|
+
)}
|
|
2287
2380
|
</ul>
|
|
2288
2381
|
</li>
|
|
2289
2382
|
);
|