menhir 0.1.3 → 0.1.5
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/LICENSE +6 -0
- package/README.md +9 -2
- package/dist/context-menu/index.js +2 -0
- package/dist/context-menu/index.parts.js +13 -0
- package/dist/context-menu/popup/ContextMenuPopup.js +30 -0
- package/dist/context-menu/root/ContextMenuContext.js +11 -0
- package/dist/context-menu/root/ContextMenuRoot.js +23 -0
- package/dist/context-menu/trigger/ContextMenuTrigger.js +47 -0
- package/dist/core/createControllableSignal.js +11 -2
- package/dist/core/listValue.js +2 -7
- package/dist/core/mergeElementProps.js +7 -1
- package/dist/floating/dismissal/escape.js +2 -1
- package/dist/floating/list-navigation/activeDescendant.js +29 -0
- package/dist/floating/list-navigation/listNavigation.js +108 -0
- package/dist/floating/list-navigation/roving.js +27 -0
- package/dist/floating/typeahead/match.js +24 -0
- package/dist/floating/typeahead/typeahead.js +56 -0
- package/dist/menu/checkbox-item/MenuCheckboxItem.js +28 -0
- package/dist/menu/group/MenuGroup.js +40 -0
- package/dist/menu/group/MenuGroupContext.js +10 -0
- package/dist/menu/group-label/MenuGroupLabel.js +27 -0
- package/dist/menu/index.js +2 -0
- package/dist/menu/index.parts.js +13 -0
- package/dist/menu/item/MenuItem.js +30 -0
- package/dist/menu/item/menuItemProps.js +77 -0
- package/dist/menu/item/renderCheckedItem.js +52 -0
- package/dist/menu/item-indicator/MenuItemIndicator.js +23 -0
- package/dist/menu/item-indicator/MenuItemIndicatorContext.js +10 -0
- package/dist/menu/popup/MenuPopup.js +123 -0
- package/dist/menu/radio-group/MenuRadioGroup.js +39 -0
- package/dist/menu/radio-item/MenuRadioItem.js +21 -0
- package/dist/menu/root/MenuContext.js +114 -0
- package/dist/menu/root/MenuRoot.js +19 -0
- package/dist/menu/submenu/MenuSubmenu.js +18 -0
- package/dist/menu/submenu-trigger/MenuSubmenuTrigger.js +114 -0
- package/dist/menu/trigger/MenuTrigger.js +67 -0
- package/dist/menubar/index.js +2 -0
- package/dist/menubar/index.parts.js +14 -0
- package/dist/menubar/menu/MenubarMenu.js +30 -0
- package/dist/menubar/root/MenubarContext.js +10 -0
- package/dist/menubar/root/MenubarRoot.js +68 -0
- package/dist/menubar/trigger/MenubarTrigger.js +73 -0
- package/dist/navigation-menu/index.js +2 -0
- package/dist/navigation-menu/index.parts.js +6 -0
- package/dist/navigation-menu/item/NavigationMenuItem.js +83 -0
- package/dist/navigation-menu/item/NavigationMenuItemContext.js +10 -0
- package/dist/navigation-menu/link/NavigationMenuLink.js +26 -0
- package/dist/navigation-menu/panel/NavigationMenuPanel.js +31 -0
- package/dist/navigation-menu/root/NavigationMenuRoot.js +100 -0
- package/dist/navigation-menu/root/NavigationMenuRootContext.js +10 -0
- package/dist/navigation-menu/trigger/NavigationMenuTrigger.js +36 -0
- package/dist/source/context-menu/index.d.ts +1 -0
- package/dist/source/context-menu/index.js +1 -0
- package/dist/source/context-menu/index.parts.d.ts +12 -0
- package/dist/source/context-menu/index.parts.js +13 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.d.ts +12 -0
- package/dist/source/context-menu/popup/ContextMenuPopup.jsx +36 -0
- package/dist/source/context-menu/root/ContextMenuContext.d.ts +18 -0
- package/dist/source/context-menu/root/ContextMenuContext.js +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.d.ts +12 -0
- package/dist/source/context-menu/root/ContextMenuRoot.jsx +16 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.d.ts +15 -0
- package/dist/source/context-menu/trigger/ContextMenuTrigger.jsx +46 -0
- package/dist/source/core/createControllableSignal.d.ts +9 -1
- package/dist/source/core/createControllableSignal.js +7 -2
- package/dist/source/core/listValue.js +4 -10
- package/dist/source/core/mergeElementProps.d.ts +8 -0
- package/dist/source/core/mergeElementProps.js +7 -1
- package/dist/source/floating/dismissal/escape.d.ts +2 -1
- package/dist/source/floating/dismissal/escape.js +2 -1
- package/dist/source/floating/dismissal/reason.d.ts +11 -2
- package/dist/source/floating/list-navigation/activeDescendant.d.ts +30 -0
- package/dist/source/floating/list-navigation/activeDescendant.js +24 -0
- package/dist/source/floating/list-navigation/listNavigation.d.ts +68 -0
- package/dist/source/floating/list-navigation/listNavigation.js +148 -0
- package/dist/source/floating/list-navigation/roving.d.ts +23 -0
- package/dist/source/floating/list-navigation/roving.js +25 -0
- package/dist/source/floating/typeahead/match.d.ts +14 -0
- package/dist/source/floating/typeahead/match.js +32 -0
- package/dist/source/floating/typeahead/typeahead.d.ts +41 -0
- package/dist/source/floating/typeahead/typeahead.js +81 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.d.ts +20 -0
- package/dist/source/menu/checkbox-item/MenuCheckboxItem.jsx +26 -0
- package/dist/source/menu/group/MenuGroup.d.ts +16 -0
- package/dist/source/menu/group/MenuGroup.jsx +31 -0
- package/dist/source/menu/group/MenuGroupContext.d.ts +10 -0
- package/dist/source/menu/group/MenuGroupContext.js +12 -0
- package/dist/source/menu/group-label/MenuGroupLabel.d.ts +11 -0
- package/dist/source/menu/group-label/MenuGroupLabel.jsx +25 -0
- package/dist/source/menu/index.d.ts +1 -0
- package/dist/source/menu/index.js +1 -0
- package/dist/source/menu/index.parts.d.ts +12 -0
- package/dist/source/menu/index.parts.js +12 -0
- package/dist/source/menu/item/MenuItem.d.ts +11 -0
- package/dist/source/menu/item/MenuItem.jsx +21 -0
- package/dist/source/menu/item/menuItemProps.d.ts +35 -0
- package/dist/source/menu/item/menuItemProps.js +78 -0
- package/dist/source/menu/item/renderCheckedItem.d.ts +22 -0
- package/dist/source/menu/item/renderCheckedItem.jsx +41 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.d.ts +12 -0
- package/dist/source/menu/item-indicator/MenuItemIndicator.jsx +17 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.d.ts +11 -0
- package/dist/source/menu/item-indicator/MenuItemIndicatorContext.js +12 -0
- package/dist/source/menu/popup/MenuPopup.d.ts +41 -0
- package/dist/source/menu/popup/MenuPopup.jsx +156 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.d.ts +27 -0
- package/dist/source/menu/radio-group/MenuRadioGroup.jsx +36 -0
- package/dist/source/menu/radio-item/MenuRadioItem.d.ts +14 -0
- package/dist/source/menu/radio-item/MenuRadioItem.jsx +19 -0
- package/dist/source/menu/root/MenuContext.d.ts +114 -0
- package/dist/source/menu/root/MenuContext.js +123 -0
- package/dist/source/menu/root/MenuRoot.d.ts +11 -0
- package/dist/source/menu/root/MenuRoot.jsx +9 -0
- package/dist/source/menu/submenu/MenuSubmenu.d.ts +22 -0
- package/dist/source/menu/submenu/MenuSubmenu.jsx +10 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.d.ts +14 -0
- package/dist/source/menu/submenu-trigger/MenuSubmenuTrigger.jsx +121 -0
- package/dist/source/menu/trigger/MenuTrigger.d.ts +13 -0
- package/dist/source/menu/trigger/MenuTrigger.jsx +73 -0
- package/dist/source/menubar/index.d.ts +1 -0
- package/dist/source/menubar/index.js +1 -0
- package/dist/source/menubar/index.parts.d.ts +13 -0
- package/dist/source/menubar/index.parts.js +14 -0
- package/dist/source/menubar/menu/MenubarMenu.d.ts +11 -0
- package/dist/source/menubar/menu/MenubarMenu.jsx +24 -0
- package/dist/source/menubar/root/MenubarContext.d.ts +30 -0
- package/dist/source/menubar/root/MenubarContext.js +12 -0
- package/dist/source/menubar/root/MenubarRoot.d.ts +11 -0
- package/dist/source/menubar/root/MenubarRoot.jsx +77 -0
- package/dist/source/menubar/trigger/MenubarTrigger.d.ts +11 -0
- package/dist/source/menubar/trigger/MenubarTrigger.jsx +78 -0
- package/dist/source/navigation-menu/index.d.ts +1 -0
- package/dist/source/navigation-menu/index.js +1 -0
- package/dist/source/navigation-menu/index.parts.d.ts +5 -0
- package/dist/source/navigation-menu/index.parts.js +5 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.d.ts +16 -0
- package/dist/source/navigation-menu/item/NavigationMenuItem.jsx +85 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.d.ts +27 -0
- package/dist/source/navigation-menu/item/NavigationMenuItemContext.js +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.d.ts +12 -0
- package/dist/source/navigation-menu/link/NavigationMenuLink.jsx +18 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.d.ts +11 -0
- package/dist/source/navigation-menu/panel/NavigationMenuPanel.jsx +26 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.d.ts +37 -0
- package/dist/source/navigation-menu/root/NavigationMenuRoot.jsx +103 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.d.ts +33 -0
- package/dist/source/navigation-menu/root/NavigationMenuRootContext.js +13 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.d.ts +12 -0
- package/dist/source/navigation-menu/trigger/NavigationMenuTrigger.jsx +32 -0
- package/package.json +23 -2
- package/skills/menhir-styling/SKILL.md +35 -0
- package/skills/menhir-styling/looks/shadcn/LICENSE +24 -0
- package/skills/menhir-styling/looks/shadcn/LOOK.md +106 -0
- package/skills/menhir-styling/looks/shadcn/dialog.md +63 -0
- package/skills/menhir-styling/looks/shadcn/popover.md +39 -0
- package/skills/menhir-styling/looks/shadcn/switch.md +26 -0
- package/skills/menhir-styling/looks/shadcn/tabs.md +62 -0
- package/skills/menhir-styling/looks/shadcn/tokens.css +80 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { merge } from "solid-js";
|
|
3
|
+
import { callHandler } from "../../core/mergeElementProps.js";
|
|
4
|
+
import { MenuPopup } from "../../menu/popup/MenuPopup.jsx";
|
|
5
|
+
import { useMenuContext } from "../../menu/root/MenuContext.js";
|
|
6
|
+
import { useContextMenu } from "../root/ContextMenuContext.js";
|
|
7
|
+
/**
|
|
8
|
+
* The menu itself: Menu's `<div popover="auto" role="menu">` in the top
|
|
9
|
+
* layer, placed at the pointer, or below the element a key opened it from,
|
|
10
|
+
* or the area before the first `contextmenu`. Name it with `aria-label`.
|
|
11
|
+
* A `contextmenu` inside it is cancelled, so the browser's own menu does not
|
|
12
|
+
* show over it. Place it inside `ContextMenu.Root`, right after
|
|
13
|
+
* `ContextMenu.Trigger`, or inside `ContextMenu.Submenu`, right after
|
|
14
|
+
* `ContextMenu.SubmenuTrigger`, where it is placed as in Menu.
|
|
15
|
+
*/
|
|
16
|
+
export function ContextMenuPopup(props) {
|
|
17
|
+
const menu = useMenuContext();
|
|
18
|
+
// The Root's Popup needs the Root's anchor. Production builds drop the
|
|
19
|
+
// check with `isDev`.
|
|
20
|
+
if (isDev && !menu.parent)
|
|
21
|
+
useContextMenu();
|
|
22
|
+
return MenuPopup(merge(props, {
|
|
23
|
+
// The consumer's, else, for the Root's menu, where it was asked for.
|
|
24
|
+
get anchor() {
|
|
25
|
+
return (props.anchor ??
|
|
26
|
+
(menu.parent ? undefined : () => menu.anchor() ?? menu.area));
|
|
27
|
+
},
|
|
28
|
+
// A right-click, or the Menu key on a focused item, inside the menu
|
|
29
|
+
// (README, "Decisions"). Called here, not merged, so the consumer's
|
|
30
|
+
// handler runs too.
|
|
31
|
+
onContextMenu: (event) => {
|
|
32
|
+
event.preventDefault();
|
|
33
|
+
callHandler(props.onContextMenu, event);
|
|
34
|
+
},
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { MenuAnchor } from "../../menu/popup/MenuPopup.tsx";
|
|
2
|
+
import type { Menu } from "../../menu/root/MenuContext.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A context menu: Menu's state, plus where the menu was asked for, which
|
|
5
|
+
* its Trigger sets and its Popup is placed against.
|
|
6
|
+
*/
|
|
7
|
+
export interface ContextMenu extends Menu {
|
|
8
|
+
/**
|
|
9
|
+
* The point of the last `contextmenu` from a pointer, or the element a
|
|
10
|
+
* key's was fired at; `undefined` before the first.
|
|
11
|
+
*/
|
|
12
|
+
anchor(): MenuAnchor | undefined;
|
|
13
|
+
setAnchor(anchor: MenuAnchor): void;
|
|
14
|
+
/** The Trigger's element, once rendered: the anchor before the first. */
|
|
15
|
+
area: HTMLElement | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** The Root's context menu, for its Trigger and its Popup. */
|
|
18
|
+
export declare function useContextMenu(): ContextMenu;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isDev } from "@solidjs/web";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { MenuContext } from "../../menu/root/MenuContext.js";
|
|
4
|
+
/** The Root's context menu, for its Trigger and its Popup. */
|
|
5
|
+
export function useContextMenu() {
|
|
6
|
+
const context = useContext(MenuContext);
|
|
7
|
+
// Production builds drop the check, and its message, with `isDev`.
|
|
8
|
+
if (isDev && !context?.setAnchor) {
|
|
9
|
+
throw new Error("[menhir] Context Menu parts must be placed within <ContextMenu.Root>.");
|
|
10
|
+
}
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { MenuStateProps } from "../../menu/root/MenuContext.ts";
|
|
3
|
+
export interface ContextMenuRootProps extends MenuStateProps {
|
|
4
|
+
children?: JSX.Element;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A menu that an area opens with the `contextmenu` event: holds whether it
|
|
8
|
+
* is open, and where it was asked for, and shares them with
|
|
9
|
+
* `ContextMenu.Trigger`, `ContextMenu.Popup` and the items inside it.
|
|
10
|
+
* Renders no element of its own.
|
|
11
|
+
*/
|
|
12
|
+
export declare function ContextMenuRoot(props: ContextMenuRootProps): JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createSignal } from "solid-js";
|
|
2
|
+
import { createMenu, MenuContext } from "../../menu/root/MenuContext.js";
|
|
3
|
+
/**
|
|
4
|
+
* A menu that an area opens with the `contextmenu` event: holds whether it
|
|
5
|
+
* is open, and where it was asked for, and shares them with
|
|
6
|
+
* `ContextMenu.Trigger`, `ContextMenu.Popup` and the items inside it.
|
|
7
|
+
* Renders no element of its own.
|
|
8
|
+
*/
|
|
9
|
+
export function ContextMenuRoot(props) {
|
|
10
|
+
const [anchor, setAnchor] = createSignal();
|
|
11
|
+
// Added to Menu's state, not copied: its functions write to that object.
|
|
12
|
+
const menu = createMenu(props);
|
|
13
|
+
menu.anchor = anchor;
|
|
14
|
+
menu.setAnchor = (value) => setAnchor(() => value);
|
|
15
|
+
return <MenuContext value={menu}>{props.children}</MenuContext>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import type { RenderProp } from "../../core/renderElement.tsx";
|
|
3
|
+
export interface ContextMenuTriggerProps extends JSX.HTMLAttributes<HTMLElement> {
|
|
4
|
+
/** Opens nothing, so the browser's own menu shows instead. */
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
render?: RenderProp;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The area that opens the menu: a `<div>` whose `contextmenu` event, from a
|
|
10
|
+
* secondary-button press, a long press, Shift+F10 or the Menu key, opens
|
|
11
|
+
* the menu at the pointer, or below the focused element for a key, with
|
|
12
|
+
* focus on its first item. Place it inside `ContextMenu.Root`, right before
|
|
13
|
+
* `ContextMenu.Popup`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ContextMenuTrigger(props: ContextMenuTriggerProps): JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { merge, omit } from "solid-js";
|
|
2
|
+
import { mergeElementProps } from "../../core/mergeElementProps.js";
|
|
3
|
+
import { renderElement } from "../../core/renderElement.jsx";
|
|
4
|
+
import { useContextMenu } from "../root/ContextMenuContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* The area that opens the menu: a `<div>` whose `contextmenu` event, from a
|
|
7
|
+
* secondary-button press, a long press, Shift+F10 or the Menu key, opens
|
|
8
|
+
* the menu at the pointer, or below the focused element for a key, with
|
|
9
|
+
* focus on its first item. Place it inside `ContextMenu.Root`, right before
|
|
10
|
+
* `ContextMenu.Popup`.
|
|
11
|
+
*/
|
|
12
|
+
export function ContextMenuTrigger(props) {
|
|
13
|
+
const menu = useContextMenu();
|
|
14
|
+
const ownProps = merge(menu.attributes, {
|
|
15
|
+
get "data-disabled"() {
|
|
16
|
+
return props.disabled ? "" : undefined;
|
|
17
|
+
},
|
|
18
|
+
onContextMenu: (event) => {
|
|
19
|
+
if (props.disabled)
|
|
20
|
+
return;
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
// A key has no pointer: Chromium sends its `contextmenu` with no
|
|
23
|
+
// button, as it does a long press, which is a touch, and the Pointer
|
|
24
|
+
// Events spec with no pointer type (README, "Decisions").
|
|
25
|
+
const { pointerType } = event;
|
|
26
|
+
const { clientX, clientY } = event;
|
|
27
|
+
menu.setAnchor(pointerType === "" || (event.button < 0 && pointerType === "mouse")
|
|
28
|
+
? event.target
|
|
29
|
+
: { getBoundingClientRect: () => new DOMRect(clientX, clientY) });
|
|
30
|
+
// The element the menu opens from, where Menu returns focus when the
|
|
31
|
+
// browser does not, as after an item in a submenu: the element a key
|
|
32
|
+
// was pressed on, or the one a press focused (README, "Decisions").
|
|
33
|
+
const focused = document.activeElement;
|
|
34
|
+
menu.trigger = focused === document.body ? undefined : focused;
|
|
35
|
+
const details = { reason: "trigger-press", event };
|
|
36
|
+
// A second one while open moves the menu and starts it over.
|
|
37
|
+
menu.closeSubmenus(details);
|
|
38
|
+
menu.openFromKey(details);
|
|
39
|
+
},
|
|
40
|
+
ref: (element) => {
|
|
41
|
+
menu.area = element;
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const elementProps = mergeElementProps(ownProps, omit(props, "render", "disabled"));
|
|
45
|
+
return renderElement(props, elementProps, (p) => <div {...p}/>);
|
|
46
|
+
}
|
|
@@ -20,9 +20,17 @@ import type { Accessor } from "solid-js";
|
|
|
20
20
|
* does nothing. Set from event handlers, not from a component body or a
|
|
21
21
|
* memo. A set may pass `details`, such as why a popup closed, which
|
|
22
22
|
* `onChange` receives after the value.
|
|
23
|
+
*
|
|
24
|
+
* The third item, `requested`, reads untracked the value set last in this
|
|
25
|
+
* turn, or `value` if nothing was: for a handler that builds on a set made
|
|
26
|
+
* earlier in the same turn, which `value` shows only after the flush.
|
|
23
27
|
*/
|
|
24
28
|
export declare function createControllableSignal<T, Details = void>(options: {
|
|
25
29
|
readonly value?: T;
|
|
26
30
|
readonly defaultValue: T;
|
|
27
31
|
onChange?: (value: T, details: Details) => void;
|
|
28
|
-
}): [
|
|
32
|
+
}): [
|
|
33
|
+
value: Accessor<T>,
|
|
34
|
+
setValue: (next: T, details: Details) => void,
|
|
35
|
+
requested: () => T
|
|
36
|
+
];
|
|
@@ -21,6 +21,10 @@ import { createSignal, onFlush, untrack } from "solid-js";
|
|
|
21
21
|
* does nothing. Set from event handlers, not from a component body or a
|
|
22
22
|
* memo. A set may pass `details`, such as why a popup closed, which
|
|
23
23
|
* `onChange` receives after the value.
|
|
24
|
+
*
|
|
25
|
+
* The third item, `requested`, reads untracked the value set last in this
|
|
26
|
+
* turn, or `value` if nothing was: for a handler that builds on a set made
|
|
27
|
+
* earlier in the same turn, which `value` shows only after the flush.
|
|
24
28
|
*/
|
|
25
29
|
export function createControllableSignal(options) {
|
|
26
30
|
// A writable derived signal that reads the default once, untracked, so a
|
|
@@ -52,8 +56,9 @@ export function createControllableSignal(options) {
|
|
|
52
56
|
// Reads lag writes, so a set is compared with the last value set in this
|
|
53
57
|
// turn, if any, not with what `value` still reads.
|
|
54
58
|
let pending;
|
|
59
|
+
const requested = () => (pending ? pending[0] : untrack(value));
|
|
55
60
|
const setValue = (next, details) => {
|
|
56
|
-
if (Object.is(next,
|
|
61
|
+
if (Object.is(next, requested()))
|
|
57
62
|
return;
|
|
58
63
|
// The part's own write is an update of its own, after the pending
|
|
59
64
|
// flush: written inline, it would be held with any async work that
|
|
@@ -71,5 +76,5 @@ export function createControllableSignal(options) {
|
|
|
71
76
|
pending = undefined;
|
|
72
77
|
});
|
|
73
78
|
};
|
|
74
|
-
return [value, setValue];
|
|
79
|
+
return [value, setValue, requested];
|
|
75
80
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { onFlush } from "solid-js";
|
|
2
1
|
import { createControllableSignal } from "./createControllableSignal.js";
|
|
3
2
|
/**
|
|
4
3
|
* A part's value that lists items and that the consumer may control, as an
|
|
@@ -20,7 +19,7 @@ import { createControllableSignal } from "./createControllableSignal.js";
|
|
|
20
19
|
* Sets in one turn build on each other, before the flush.
|
|
21
20
|
*/
|
|
22
21
|
export function createListValue(options) {
|
|
23
|
-
const [value, setValue] = createControllableSignal({
|
|
22
|
+
const [value, setValue, requested] = createControllableSignal({
|
|
24
23
|
get value() {
|
|
25
24
|
return options.value;
|
|
26
25
|
},
|
|
@@ -29,22 +28,17 @@ export function createListValue(options) {
|
|
|
29
28
|
},
|
|
30
29
|
onChange: (value) => options.onChange?.(value),
|
|
31
30
|
});
|
|
32
|
-
// The value asked for in this turn, if any: reads lag writes, so a second
|
|
33
|
-
// set before the flush builds on this, not on what `value` still reads.
|
|
34
|
-
let pending;
|
|
35
31
|
return {
|
|
36
32
|
has: (item) => value().includes(item),
|
|
37
33
|
set: (item, included) => {
|
|
38
|
-
const current = pending ?? value();
|
|
39
34
|
let next = included ? [item] : [];
|
|
40
35
|
if (options.multiple) {
|
|
41
|
-
|
|
36
|
+
// Reads lag writes, so a second set before the flush builds on the
|
|
37
|
+
// first, not on what `value` still reads.
|
|
38
|
+
next = requested().filter((other) => other !== item);
|
|
42
39
|
if (included)
|
|
43
40
|
next.push(item);
|
|
44
41
|
}
|
|
45
|
-
if (!pending)
|
|
46
|
-
onFlush(() => (pending = undefined));
|
|
47
|
-
pending = next;
|
|
48
42
|
setValue(next);
|
|
49
43
|
},
|
|
50
44
|
};
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { JSX } from "@solidjs/web";
|
|
2
2
|
import type { ElementProps } from "./renderElement.tsx";
|
|
3
|
+
export type Handler = ((event: Event) => void) | [(data: unknown, event: Event) => void, unknown];
|
|
4
|
+
/**
|
|
5
|
+
* Calls a JSX event handler in either of Solid's forms, a function or a
|
|
6
|
+
* `[handler, data]` pair, for a part that calls the consumer's handler
|
|
7
|
+
* itself instead of through the merge, such as a menu item that skips it
|
|
8
|
+
* while disabled.
|
|
9
|
+
*/
|
|
10
|
+
export declare function callHandler(handler: Handler | undefined, event: Event): void;
|
|
3
11
|
/**
|
|
4
12
|
* Merges a part's own props with the consumer's, for one element. The
|
|
5
13
|
* consumer's props win, except for these, where both apply:
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { merge } from "solid-js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Calls a JSX event handler in either of Solid's forms, a function or a
|
|
4
|
+
* `[handler, data]` pair, for a part that calls the consumer's handler
|
|
5
|
+
* itself instead of through the merge, such as a menu item that skips it
|
|
6
|
+
* while disabled.
|
|
7
|
+
*/
|
|
8
|
+
export function callHandler(handler, event) {
|
|
3
9
|
if (typeof handler === "function")
|
|
4
10
|
handler(event);
|
|
5
11
|
else if (handler)
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { OpenChangeDetails } from "./reason.ts";
|
|
2
2
|
/**
|
|
3
3
|
* Escape for a popup the browser does not close on Escape, a `manual`
|
|
4
|
-
* popover such as Tooltip's
|
|
4
|
+
* popover such as Tooltip's, or for content in the page's flow, such as
|
|
5
|
+
* Navigation Menu's Panels. While `open`, an Escape key calls `onDismiss`
|
|
5
6
|
* with the reason `escape-key`:
|
|
6
7
|
*
|
|
7
8
|
* ```ts
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createEffect } from "solid-js";
|
|
2
2
|
/**
|
|
3
3
|
* Escape for a popup the browser does not close on Escape, a `manual`
|
|
4
|
-
* popover such as Tooltip's
|
|
4
|
+
* popover such as Tooltip's, or for content in the page's flow, such as
|
|
5
|
+
* Navigation Menu's Panels. While `open`, an Escape key calls `onDismiss`
|
|
5
6
|
* with the reason `escape-key`:
|
|
6
7
|
*
|
|
7
8
|
* ```ts
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* - `escape-key`: Escape.
|
|
7
7
|
* - `outside-press`: a press outside the popup, on a dialog's backdrop or
|
|
8
8
|
* in a popover's light dismiss.
|
|
9
|
-
* - `trigger-press`: the trigger, pressed by pointer or keyboard
|
|
9
|
+
* - `trigger-press`: the trigger, pressed by pointer or keyboard, or a
|
|
10
|
+
* Context Menu's area by its `contextmenu` event.
|
|
10
11
|
* - `close-request`: the browser closed the popup for another reason, such
|
|
11
12
|
* as the back gesture on Android, a `<form method="dialog">` or another
|
|
12
13
|
* popover opening.
|
|
@@ -16,8 +17,16 @@
|
|
|
16
17
|
* keyboard (Dialog's `Close`).
|
|
17
18
|
* - `trigger-focus`: the trigger received keyboard focus, or lost it
|
|
18
19
|
* (Tooltip).
|
|
20
|
+
* - `focus-out`: focus moved to an element outside the component, such as
|
|
21
|
+
* Tab out of a Navigation Menu's `<nav>`.
|
|
22
|
+
* - `link-press`: a link inside the component was activated, by pointer or
|
|
23
|
+
* keyboard, such as a Navigation Menu's `Link`.
|
|
24
|
+
* - `item-press`: an item of a menu was activated, by pointer or keyboard,
|
|
25
|
+
* which closes every open menu (Menu).
|
|
26
|
+
* - `arrow-key`: an arrow key opened or closed a submenu, or a key that
|
|
27
|
+
* moves through a menu closed its open submenu (Menu).
|
|
19
28
|
*/
|
|
20
|
-
export type OpenChangeReason = "escape-key" | "outside-press" | "trigger-press" | "close-request" | "trigger-hover" | "close-press" | "trigger-focus";
|
|
29
|
+
export type OpenChangeReason = "escape-key" | "outside-press" | "trigger-press" | "close-request" | "trigger-hover" | "close-press" | "trigger-focus" | "focus-out" | "link-press" | "item-press" | "arrow-key";
|
|
21
30
|
/**
|
|
22
31
|
* The second argument of `onOpenChange`. `event` is the event that caused
|
|
23
32
|
* the change: the key or pointer event when there was one, else the
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ListItem, type ListNavigation, type ListNavigationOptions } from "./listNavigation.ts";
|
|
2
|
+
/** An item named in `aria-activedescendant`, which needs an `id`. */
|
|
3
|
+
export interface ActiveDescendantItem extends ListItem {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
}
|
|
6
|
+
/** What `createActiveDescendantList` returns. */
|
|
7
|
+
export interface ActiveDescendantList<T extends ActiveDescendantItem> extends ListNavigation<T> {
|
|
8
|
+
/** The active item's `id`, for `aria-activedescendant`, if any. */
|
|
9
|
+
activeId(): string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* List navigation where focus stays on another element, such as a
|
|
13
|
+
* combobox's input, which names the active item in `aria-activedescendant`.
|
|
14
|
+
* The item part takes `props.id ?? createUniqueId()` and registers once
|
|
15
|
+
* mounted, so the server HTML names no item:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const list = createActiveDescendantList<Entry>({
|
|
19
|
+
* get open() { return open(); },
|
|
20
|
+
* });
|
|
21
|
+
* // On the input:
|
|
22
|
+
* const inputProps = {
|
|
23
|
+
* get "aria-activedescendant"() { return list.activeId(); },
|
|
24
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
25
|
+
* };
|
|
26
|
+
* // In the item part:
|
|
27
|
+
* onSettled(() => list.register(item));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function createActiveDescendantList<T extends ActiveDescendantItem>(options: ListNavigationOptions<T>): ActiveDescendantList<T>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createListNavigation, } from "./listNavigation.js";
|
|
2
|
+
/**
|
|
3
|
+
* List navigation where focus stays on another element, such as a
|
|
4
|
+
* combobox's input, which names the active item in `aria-activedescendant`.
|
|
5
|
+
* The item part takes `props.id ?? createUniqueId()` and registers once
|
|
6
|
+
* mounted, so the server HTML names no item:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const list = createActiveDescendantList<Entry>({
|
|
10
|
+
* get open() { return open(); },
|
|
11
|
+
* });
|
|
12
|
+
* // On the input:
|
|
13
|
+
* const inputProps = {
|
|
14
|
+
* get "aria-activedescendant"() { return list.activeId(); },
|
|
15
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
16
|
+
* };
|
|
17
|
+
* // In the item part:
|
|
18
|
+
* onSettled(() => list.register(item));
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function createActiveDescendantList(options) {
|
|
22
|
+
const list = createListNavigation(options);
|
|
23
|
+
return { ...list, activeId: () => list.active()?.id };
|
|
24
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** An item of a list, as list navigation knows it. */
|
|
2
|
+
export interface ListItem {
|
|
3
|
+
readonly element: HTMLElement;
|
|
4
|
+
/**
|
|
5
|
+
* The item's text, for typeahead (#98) and a Select's value, when its
|
|
6
|
+
* content is not its label. Without it, the element's text content.
|
|
7
|
+
*/
|
|
8
|
+
readonly text?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The options of `createListNavigation`, as getters and functions. */
|
|
11
|
+
export interface ListNavigationOptions<T extends ListItem> {
|
|
12
|
+
/**
|
|
13
|
+
* Whether the list's popup is open. While it is closed, focus does not
|
|
14
|
+
* move and, once it has closed, no item is active. Left out for a list
|
|
15
|
+
* that is always shown.
|
|
16
|
+
*/
|
|
17
|
+
readonly open?: boolean;
|
|
18
|
+
/** Up and Down move in a vertical list (the default), Left and Right in a horizontal one. */
|
|
19
|
+
readonly orientation?: "horizontal" | "vertical";
|
|
20
|
+
/** Whether the keys wrap from the last item to the first and back (default `false`). */
|
|
21
|
+
readonly wrap?: boolean;
|
|
22
|
+
/** Whether the keys and the pointer reach this item (by default, every item). */
|
|
23
|
+
reachable?(item: T): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The key that points into the active item: Right in a vertical list
|
|
26
|
+
* (Left right to left), Down in a horizontal one. Opens a submenu.
|
|
27
|
+
*/
|
|
28
|
+
onArrowIn?(item: T, event: KeyboardEvent): void;
|
|
29
|
+
/**
|
|
30
|
+
* The key that points out of the list: Left in a vertical list (Right
|
|
31
|
+
* right to left), Up in a horizontal one. Closes a submenu.
|
|
32
|
+
*/
|
|
33
|
+
onArrowOut?(item: T | undefined, event: KeyboardEvent): void;
|
|
34
|
+
}
|
|
35
|
+
/** What `createListNavigation` returns, in both ways of holding focus. */
|
|
36
|
+
export interface ListNavigation<T extends ListItem> {
|
|
37
|
+
/** Adds a mounted item; returns what removes it. */
|
|
38
|
+
register(item: T): () => void;
|
|
39
|
+
/** The items the keys reach, in document order. */
|
|
40
|
+
items(): T[];
|
|
41
|
+
/** The active item, if any. */
|
|
42
|
+
active(): T | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Whether `item` is the active one. A move re-runs it for the item that
|
|
45
|
+
* was active and the one that is, not for every item.
|
|
46
|
+
*/
|
|
47
|
+
isActive(item: T): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Makes `item` active as the keyboard does: it is focused, in the roving
|
|
50
|
+
* form, and scrolled into view. An item the keys do not reach is ignored;
|
|
51
|
+
* `undefined` leaves no item active.
|
|
52
|
+
*/
|
|
53
|
+
move(item: T | undefined): void;
|
|
54
|
+
/**
|
|
55
|
+
* Arrow keys, Home and End, from one of the items or from the element
|
|
56
|
+
* that hands them over; returns whether it used the key.
|
|
57
|
+
*/
|
|
58
|
+
onKeyDown(event: KeyboardEvent): boolean;
|
|
59
|
+
/** The pointer moving on an item makes it active, without scrolling. */
|
|
60
|
+
onPointerMove(item: T, event: PointerEvent): void;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The items of a list in document order, the active item, the keys and the
|
|
64
|
+
* pointer: what both ways of holding focus share. `focusItem` is the way's
|
|
65
|
+
* own: the roving form focuses the item. Nothing runs at import time, nor,
|
|
66
|
+
* until a key or the pointer, on the server.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createListNavigation<T extends ListItem>(options: ListNavigationOptions<T>, focusItem?: (item: T) => void): ListNavigation<T>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal } from "solid-js";
|
|
2
|
+
// Document order, which can differ from the order items registered in.
|
|
3
|
+
const byPosition = (a, b) => a.element.compareDocumentPosition(b.element) &
|
|
4
|
+
Node.DOCUMENT_POSITION_FOLLOWING
|
|
5
|
+
? -1
|
|
6
|
+
: 1;
|
|
7
|
+
/**
|
|
8
|
+
* The items of a list in document order, the active item, the keys and the
|
|
9
|
+
* pointer: what both ways of holding focus share. `focusItem` is the way's
|
|
10
|
+
* own: the roving form focuses the item. Nothing runs at import time, nor,
|
|
11
|
+
* until a key or the pointer, on the server.
|
|
12
|
+
*/
|
|
13
|
+
export function createListNavigation(options, focusItem) {
|
|
14
|
+
const [registered, setRegistered] = createSignal([]);
|
|
15
|
+
// Sorted again only when an item registers or leaves.
|
|
16
|
+
const ordered = createMemo(() => [...registered()].sort(byPosition));
|
|
17
|
+
const reachable = (item) => options.reachable?.(item) ?? true;
|
|
18
|
+
const [active, setActive] = createSignal();
|
|
19
|
+
// Each item's own active signal, so a move sets two of them, and only the
|
|
20
|
+
// two items that read them run again. Made on the item's first read.
|
|
21
|
+
const activeSignals = new WeakMap();
|
|
22
|
+
const activeSignal = (item) => {
|
|
23
|
+
let signal = activeSignals.get(item);
|
|
24
|
+
if (!signal) {
|
|
25
|
+
const [read, write] = createSignal(false);
|
|
26
|
+
activeSignals.set(item, (signal = [read, write]));
|
|
27
|
+
}
|
|
28
|
+
return signal;
|
|
29
|
+
};
|
|
30
|
+
// The active item as written, where `active()` lags until the flush.
|
|
31
|
+
let activeItem;
|
|
32
|
+
const activate = (item) => {
|
|
33
|
+
if (activeItem)
|
|
34
|
+
activeSignal(activeItem)[1](false);
|
|
35
|
+
if (item)
|
|
36
|
+
activeSignal(item)[1](true);
|
|
37
|
+
activeItem = item;
|
|
38
|
+
setActive(() => item);
|
|
39
|
+
};
|
|
40
|
+
// As the keyboard shows an item: focused, in the roving form, and
|
|
41
|
+
// scrolled into view at the near edge, so one already in view does not
|
|
42
|
+
// move.
|
|
43
|
+
const focusAndScroll = (item) => {
|
|
44
|
+
focusItem?.(item);
|
|
45
|
+
item.element.scrollIntoView({ block: "nearest", inline: "nearest" });
|
|
46
|
+
};
|
|
47
|
+
const list = {
|
|
48
|
+
register: (item) => {
|
|
49
|
+
setRegistered((items) => [...items, item]);
|
|
50
|
+
return () => {
|
|
51
|
+
setRegistered((items) => items.filter((other) => other !== item));
|
|
52
|
+
if (activeItem === item)
|
|
53
|
+
activate(undefined);
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
items: () => ordered().filter(reachable),
|
|
57
|
+
active,
|
|
58
|
+
isActive: (item) => activeSignal(item)[0](),
|
|
59
|
+
move: (item) => {
|
|
60
|
+
if (item && !reachable(item))
|
|
61
|
+
return;
|
|
62
|
+
activate(item);
|
|
63
|
+
// While the popup is closed, the item takes no focus and does not
|
|
64
|
+
// scroll, though an exit animation may still show it: it is focused
|
|
65
|
+
// and scrolled into view once the popup opens (below).
|
|
66
|
+
if (item && options.open !== false)
|
|
67
|
+
focusAndScroll(item);
|
|
68
|
+
},
|
|
69
|
+
onKeyDown: (event) => {
|
|
70
|
+
// Only a key from one of its items, or from the element that hands
|
|
71
|
+
// it over, such as a combobox's input: a nested list, such as a
|
|
72
|
+
// submenu in an item, takes its own keys, which bubble through it.
|
|
73
|
+
const { target } = event;
|
|
74
|
+
if (target !== event.currentTarget &&
|
|
75
|
+
!registered().some((item) => item.element === target))
|
|
76
|
+
return false;
|
|
77
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
78
|
+
return false;
|
|
79
|
+
const items = list.items();
|
|
80
|
+
const itemCount = items.length;
|
|
81
|
+
const activeIndex = items.indexOf(activeItem);
|
|
82
|
+
// Right to left, Left points forward. `direction` inherits, so an
|
|
83
|
+
// item's own is its list's.
|
|
84
|
+
const directionSource = (activeItem ?? items[0])?.element;
|
|
85
|
+
const [leftKey, rightKey] = directionSource && getComputedStyle(directionSource).direction === "rtl"
|
|
86
|
+
? ["ArrowRight", "ArrowLeft"]
|
|
87
|
+
: ["ArrowLeft", "ArrowRight"];
|
|
88
|
+
const [backKey, forwardKey, outKey, intoKey] = options.orientation === "horizontal"
|
|
89
|
+
? [leftKey, rightKey, "ArrowUp", "ArrowDown"]
|
|
90
|
+
: ["ArrowUp", "ArrowDown", leftKey, rightKey];
|
|
91
|
+
// Into the active item, or out of the list: the component's to act
|
|
92
|
+
// on, such as a submenu.
|
|
93
|
+
const { onArrowIn, onArrowOut } = options;
|
|
94
|
+
if (event.key === intoKey && activeItem && onArrowIn) {
|
|
95
|
+
onArrowIn(activeItem, event);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (event.key === outKey && onArrowOut) {
|
|
99
|
+
onArrowOut(activeItem, event);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
const toIndex = event.key === backKey
|
|
103
|
+
? (activeIndex < 0 ? itemCount : activeIndex) - 1
|
|
104
|
+
: event.key === forwardKey
|
|
105
|
+
? activeIndex + 1
|
|
106
|
+
: event.key === "Home"
|
|
107
|
+
? 0
|
|
108
|
+
: event.key === "End"
|
|
109
|
+
? itemCount - 1
|
|
110
|
+
: undefined;
|
|
111
|
+
if (toIndex === undefined || !itemCount)
|
|
112
|
+
return false;
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
list.move(items[options.wrap
|
|
115
|
+
? (toIndex + itemCount) % itemCount
|
|
116
|
+
: Math.min(Math.max(toIndex, 0), itemCount - 1)]);
|
|
117
|
+
return true;
|
|
118
|
+
},
|
|
119
|
+
onPointerMove: (item, event) => {
|
|
120
|
+
// A finger that scrolls the list would make each item it crosses
|
|
121
|
+
// active; a tap activates an item through the component's click.
|
|
122
|
+
// A closed popup still shown, as during an exit animation, is left
|
|
123
|
+
// alone, as `move` leaves it.
|
|
124
|
+
if (options.open === false || event.pointerType === "touch")
|
|
125
|
+
return;
|
|
126
|
+
if (activeItem === item)
|
|
127
|
+
return;
|
|
128
|
+
if (!reachable(item))
|
|
129
|
+
return;
|
|
130
|
+
activate(item);
|
|
131
|
+
focusItem?.(item);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
createEffect(() => options.open, (open) => {
|
|
135
|
+
// Set again on each opening, by the component.
|
|
136
|
+
if (open === false) {
|
|
137
|
+
activate(undefined);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Once the popup is shown: after its own `showPopover()` in this
|
|
141
|
+
// flush, whichever effect runs first, as `focus/initialFocus.ts`.
|
|
142
|
+
queueMicrotask(() => {
|
|
143
|
+
if (activeItem)
|
|
144
|
+
focusAndScroll(activeItem);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
return list;
|
|
148
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ListItem, type ListNavigation, type ListNavigationOptions } from "./listNavigation.ts";
|
|
2
|
+
/**
|
|
3
|
+
* List navigation where focus moves to the active item (roving `tabindex`),
|
|
4
|
+
* as in a menu. The item part registers once mounted, sets `tabindex` to 0
|
|
5
|
+
* on the active item and -1 on the others, and hands its key and pointer
|
|
6
|
+
* events over:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const list = createRovingList<Entry>({
|
|
10
|
+
* get open() { return open(); },
|
|
11
|
+
* reachable: (item) => true,
|
|
12
|
+
* });
|
|
13
|
+
* // In the item part:
|
|
14
|
+
* onSettled(() => list.register(item));
|
|
15
|
+
* const ownProps = {
|
|
16
|
+
* get tabindex() { return list.isActive(item) ? 0 : -1; },
|
|
17
|
+
* get "data-active"() { return list.isActive(item) ? "" : undefined; },
|
|
18
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
19
|
+
* onPointerMove: (event) => list.onPointerMove(item, event),
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createRovingList<T extends ListItem>(options: ListNavigationOptions<T>): ListNavigation<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createListNavigation, } from "./listNavigation.js";
|
|
2
|
+
/**
|
|
3
|
+
* List navigation where focus moves to the active item (roving `tabindex`),
|
|
4
|
+
* as in a menu. The item part registers once mounted, sets `tabindex` to 0
|
|
5
|
+
* on the active item and -1 on the others, and hands its key and pointer
|
|
6
|
+
* events over:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const list = createRovingList<Entry>({
|
|
10
|
+
* get open() { return open(); },
|
|
11
|
+
* reachable: (item) => true,
|
|
12
|
+
* });
|
|
13
|
+
* // In the item part:
|
|
14
|
+
* onSettled(() => list.register(item));
|
|
15
|
+
* const ownProps = {
|
|
16
|
+
* get tabindex() { return list.isActive(item) ? 0 : -1; },
|
|
17
|
+
* get "data-active"() { return list.isActive(item) ? "" : undefined; },
|
|
18
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
19
|
+
* onPointerMove: (event) => list.onPointerMove(item, event),
|
|
20
|
+
* };
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function createRovingList(options) {
|
|
24
|
+
return createListNavigation(options, (item) => item.element.focus({ preventScroll: true }));
|
|
25
|
+
}
|