menhir 0.1.2 → 0.1.4
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/alert-dialog/index.js +2 -0
- package/dist/alert-dialog/index.parts.js +7 -0
- package/dist/alert-dialog/popup/AlertDialogPopup.js +13 -0
- package/dist/core/createControllableSignal.js +15 -5
- package/dist/core/listValue.js +2 -7
- package/dist/core/slot.js +30 -0
- package/dist/dialog/close/DialogClose.js +33 -0
- package/dist/dialog/description/DialogDescription.js +27 -0
- package/dist/dialog/index.js +2 -0
- package/dist/dialog/index.parts.js +7 -0
- package/dist/dialog/popup/DialogPopup.js +13 -0
- package/dist/dialog/popup/renderDialogPopup.js +71 -0
- package/dist/dialog/root/DialogRoot.js +46 -0
- package/dist/dialog/root/DialogRootContext.js +10 -0
- package/dist/dialog/title/DialogTitle.js +27 -0
- package/dist/dialog/trigger/DialogTrigger.js +33 -0
- package/dist/floating/dismissal/dialogClose.js +67 -0
- package/dist/floating/dismissal/escape.js +44 -0
- package/dist/floating/dismissal/outsidePress.js +52 -0
- package/dist/floating/dismissal/popoverClose.js +74 -0
- package/dist/floating/dismissal/reason.js +0 -0
- package/dist/floating/focus/initialFocus.js +33 -0
- package/dist/floating/focus/returnFocus.js +65 -0
- package/dist/floating/focus/tabWrap.js +55 -0
- package/dist/floating/focus/tabbable.js +50 -0
- package/dist/floating/focus/target.js +0 -0
- package/dist/floating/hover/group.js +36 -0
- package/dist/floating/hover/hover.js +105 -0
- package/dist/floating/hover/safeArea.js +64 -0
- 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/presence/presence.js +57 -0
- package/dist/floating/scroll-lock/scrollLock.js +125 -0
- package/dist/floating/typeahead/match.js +24 -0
- package/dist/floating/typeahead/typeahead.js +56 -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/popover/arrow/PopoverArrow.js +39 -0
- package/dist/popover/close/PopoverClose.js +33 -0
- package/dist/popover/description/PopoverDescription.js +27 -0
- package/dist/popover/index.js +2 -0
- package/dist/popover/index.parts.js +8 -0
- package/dist/popover/popup/PopoverPopup.js +116 -0
- package/dist/popover/popup/PopoverPopupContext.js +10 -0
- package/dist/popover/root/PopoverRoot.js +50 -0
- package/dist/popover/root/PopoverRootContext.js +10 -0
- package/dist/popover/title/PopoverTitle.js +27 -0
- package/dist/popover/trigger/PopoverTrigger.js +44 -0
- package/dist/source/alert-dialog/index.d.ts +1 -0
- package/dist/source/alert-dialog/index.js +1 -0
- package/dist/source/alert-dialog/index.parts.d.ts +6 -0
- package/dist/source/alert-dialog/index.parts.js +7 -0
- package/dist/source/alert-dialog/popup/AlertDialogPopup.d.ts +10 -0
- package/dist/source/alert-dialog/popup/AlertDialogPopup.jsx +11 -0
- package/dist/source/core/createControllableSignal.d.ts +13 -4
- package/dist/source/core/createControllableSignal.js +11 -5
- package/dist/source/core/listValue.js +4 -10
- package/dist/source/core/slot.d.ts +21 -0
- package/dist/source/core/slot.js +28 -0
- package/dist/source/dialog/close/DialogClose.d.ts +11 -0
- package/dist/source/dialog/close/DialogClose.jsx +25 -0
- package/dist/source/dialog/description/DialogDescription.d.ts +10 -0
- package/dist/source/dialog/description/DialogDescription.jsx +26 -0
- package/dist/source/dialog/index.d.ts +1 -0
- package/dist/source/dialog/index.js +1 -0
- package/dist/source/dialog/index.parts.d.ts +6 -0
- package/dist/source/dialog/index.parts.js +6 -0
- package/dist/source/dialog/popup/DialogPopup.d.ts +9 -0
- package/dist/source/dialog/popup/DialogPopup.jsx +11 -0
- package/dist/source/dialog/popup/renderDialogPopup.d.ts +40 -0
- package/dist/source/dialog/popup/renderDialogPopup.jsx +73 -0
- package/dist/source/dialog/root/DialogRoot.d.ts +20 -0
- package/dist/source/dialog/root/DialogRoot.jsx +39 -0
- package/dist/source/dialog/root/DialogRootContext.d.ts +32 -0
- package/dist/source/dialog/root/DialogRootContext.js +14 -0
- package/dist/source/dialog/title/DialogTitle.d.ts +10 -0
- package/dist/source/dialog/title/DialogTitle.jsx +26 -0
- package/dist/source/dialog/trigger/DialogTrigger.d.ts +10 -0
- package/dist/source/dialog/trigger/DialogTrigger.jsx +27 -0
- package/dist/source/floating/dismissal/dialogClose.d.ts +26 -0
- package/dist/source/floating/dismissal/dialogClose.js +69 -0
- package/dist/source/floating/dismissal/escape.d.ts +24 -0
- package/dist/source/floating/dismissal/escape.js +48 -0
- package/dist/source/floating/dismissal/outsidePress.d.ts +26 -0
- package/dist/source/floating/dismissal/outsidePress.js +50 -0
- package/dist/source/floating/dismissal/popoverClose.d.ts +28 -0
- package/dist/source/floating/dismissal/popoverClose.js +82 -0
- package/dist/source/floating/dismissal/reason.d.ts +34 -0
- package/dist/source/floating/dismissal/reason.js +1 -0
- package/dist/source/floating/focus/initialFocus.d.ts +24 -0
- package/dist/source/floating/focus/initialFocus.js +38 -0
- package/dist/source/floating/focus/returnFocus.d.ts +27 -0
- package/dist/source/floating/focus/returnFocus.js +81 -0
- package/dist/source/floating/focus/tabWrap.d.ts +21 -0
- package/dist/source/floating/focus/tabWrap.js +69 -0
- package/dist/source/floating/focus/tabbable.d.ts +16 -0
- package/dist/source/floating/focus/tabbable.js +69 -0
- package/dist/source/floating/focus/target.d.ts +8 -0
- package/dist/source/floating/focus/target.js +1 -0
- package/dist/source/floating/hover/group.d.ts +39 -0
- package/dist/source/floating/hover/group.js +38 -0
- package/dist/source/floating/hover/hover.d.ts +35 -0
- package/dist/source/floating/hover/hover.js +130 -0
- package/dist/source/floating/hover/safeArea.d.ts +23 -0
- package/dist/source/floating/hover/safeArea.js +67 -0
- 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/presence/presence.d.ts +24 -0
- package/dist/source/floating/presence/presence.js +73 -0
- package/dist/source/floating/scroll-lock/scrollLock.d.ts +27 -0
- package/dist/source/floating/scroll-lock/scrollLock.js +151 -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/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/dist/source/popover/arrow/PopoverArrow.d.ts +11 -0
- package/dist/source/popover/arrow/PopoverArrow.jsx +32 -0
- package/dist/source/popover/close/PopoverClose.d.ts +11 -0
- package/dist/source/popover/close/PopoverClose.jsx +25 -0
- package/dist/source/popover/description/PopoverDescription.d.ts +10 -0
- package/dist/source/popover/description/PopoverDescription.jsx +26 -0
- package/dist/source/popover/index.d.ts +1 -0
- package/dist/source/popover/index.js +1 -0
- package/dist/source/popover/index.parts.d.ts +7 -0
- package/dist/source/popover/index.parts.js +7 -0
- package/dist/source/popover/popup/PopoverPopup.d.ts +47 -0
- package/dist/source/popover/popup/PopoverPopup.jsx +120 -0
- package/dist/source/popover/popup/PopoverPopupContext.d.ts +14 -0
- package/dist/source/popover/popup/PopoverPopupContext.js +11 -0
- package/dist/source/popover/root/PopoverRoot.d.ts +20 -0
- package/dist/source/popover/root/PopoverRoot.jsx +42 -0
- package/dist/source/popover/root/PopoverRootContext.d.ts +39 -0
- package/dist/source/popover/root/PopoverRootContext.js +13 -0
- package/dist/source/popover/title/PopoverTitle.d.ts +10 -0
- package/dist/source/popover/title/PopoverTitle.jsx +26 -0
- package/dist/source/popover/trigger/PopoverTrigger.d.ts +12 -0
- package/dist/source/popover/trigger/PopoverTrigger.jsx +40 -0
- package/dist/source/tooltip/arrow/TooltipArrow.d.ts +11 -0
- package/dist/source/tooltip/arrow/TooltipArrow.jsx +32 -0
- package/dist/source/tooltip/group/TooltipGroup.d.ts +20 -0
- package/dist/source/tooltip/group/TooltipGroup.jsx +18 -0
- package/dist/source/tooltip/group/TooltipGroupContext.d.ts +2 -0
- package/dist/source/tooltip/group/TooltipGroupContext.js +5 -0
- package/dist/source/tooltip/index.d.ts +1 -0
- package/dist/source/tooltip/index.js +1 -0
- package/dist/source/tooltip/index.parts.d.ts +5 -0
- package/dist/source/tooltip/index.parts.js +5 -0
- package/dist/source/tooltip/popup/TooltipPopup.d.ts +31 -0
- package/dist/source/tooltip/popup/TooltipPopup.jsx +77 -0
- package/dist/source/tooltip/popup/TooltipPopupContext.d.ts +14 -0
- package/dist/source/tooltip/popup/TooltipPopupContext.js +11 -0
- package/dist/source/tooltip/root/TooltipRoot.d.ts +31 -0
- package/dist/source/tooltip/root/TooltipRoot.jsx +80 -0
- package/dist/source/tooltip/root/TooltipRootContext.d.ts +35 -0
- package/dist/source/tooltip/root/TooltipRootContext.js +13 -0
- package/dist/source/tooltip/trigger/TooltipTrigger.d.ts +12 -0
- package/dist/source/tooltip/trigger/TooltipTrigger.jsx +52 -0
- package/dist/tooltip/arrow/TooltipArrow.js +39 -0
- package/dist/tooltip/group/TooltipGroup.js +26 -0
- package/dist/tooltip/group/TooltipGroupContext.js +4 -0
- package/dist/tooltip/index.js +2 -0
- package/dist/tooltip/index.parts.js +6 -0
- package/dist/tooltip/popup/TooltipPopup.js +86 -0
- package/dist/tooltip/popup/TooltipPopupContext.js +10 -0
- package/dist/tooltip/root/TooltipRoot.js +79 -0
- package/dist/tooltip/root/TooltipRootContext.js +10 -0
- package/dist/tooltip/trigger/TooltipTrigger.js +54 -0
- package/package.json +28 -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,74 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
// src/floating/dismissal/popoverClose.ts
|
|
3
|
+
/**
|
|
4
|
+
* Reports an `auto` popover that the browser closes, while `open`, with the
|
|
5
|
+
* reason. The popup closes through its own state:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* createPopoverClose({
|
|
9
|
+
* get popup() { return popup; },
|
|
10
|
+
* get trigger() { return trigger; },
|
|
11
|
+
* get open() { return open(); },
|
|
12
|
+
* onDismiss: (details) => setOpen(false, details),
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The reason is the input event of the same task: an Escape key
|
|
17
|
+
* (`escape-key`), a pointer released outside the popover (`outside-press`,
|
|
18
|
+
* the browser's light dismiss) or a release or click on the trigger
|
|
19
|
+
* (`trigger-press`, its `popovertarget`); else `close-request`. The
|
|
20
|
+
* browser's close cannot be refused, so if the state still says open once
|
|
21
|
+
* it has settled, the popover is shown again. A close the popup made
|
|
22
|
+
* itself, after its state turned false, is not reported.
|
|
23
|
+
*/
|
|
24
|
+
function createPopoverClose(options) {
|
|
25
|
+
createEffect(() => options.open, (open) => {
|
|
26
|
+
const popup = options.popup;
|
|
27
|
+
if (!open || !popup) return;
|
|
28
|
+
let cause;
|
|
29
|
+
const note = (reason, event) => {
|
|
30
|
+
const noted = {
|
|
31
|
+
reason,
|
|
32
|
+
event
|
|
33
|
+
};
|
|
34
|
+
cause = noted;
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
if (cause === noted) cause = void 0;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const keydown = (event) => {
|
|
40
|
+
if (event.key === "Escape") note("escape-key", event);
|
|
41
|
+
};
|
|
42
|
+
const pointerup = (event) => {
|
|
43
|
+
const target = event.target;
|
|
44
|
+
if (options.trigger?.contains(target)) note("trigger-press", event);
|
|
45
|
+
else if (!popup.contains(target)) note("outside-press", event);
|
|
46
|
+
};
|
|
47
|
+
const click = (event) => {
|
|
48
|
+
if (options.trigger?.contains(event.target)) note("trigger-press", event);
|
|
49
|
+
};
|
|
50
|
+
const beforetoggle = (event) => {
|
|
51
|
+
if (event.newState !== "closed" || !options.open) return;
|
|
52
|
+
options.onDismiss(cause ?? {
|
|
53
|
+
reason: "close-request",
|
|
54
|
+
event
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const toggle = () => {
|
|
58
|
+
if (options.open && !popup.matches(":popover-open")) popup.showPopover();
|
|
59
|
+
};
|
|
60
|
+
document.addEventListener("keydown", keydown, true);
|
|
61
|
+
document.addEventListener("pointerup", pointerup, true);
|
|
62
|
+
document.addEventListener("click", click, true);
|
|
63
|
+
popup.addEventListener("beforetoggle", beforetoggle);
|
|
64
|
+
popup.addEventListener("toggle", toggle);
|
|
65
|
+
return () => {
|
|
66
|
+
document.removeEventListener("keydown", keydown, true);
|
|
67
|
+
document.removeEventListener("pointerup", pointerup, true);
|
|
68
|
+
document.removeEventListener("click", click, true);
|
|
69
|
+
popup.removeEventListener("beforetoggle", beforetoggle);
|
|
70
|
+
popup.removeEventListener("toggle", toggle);
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export { createPopoverClose };
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createEffect } from "solid-js";
|
|
2
|
+
// src/floating/focus/initialFocus.ts
|
|
3
|
+
/**
|
|
4
|
+
* Moves focus to `initialFocus` once the popup has opened, instead of where
|
|
5
|
+
* the browser puts it: the element with `autofocus`, else a dialog's first
|
|
6
|
+
* focusable element, while a popover leaves focus on its trigger. Without
|
|
7
|
+
* `initialFocus` the browser decides.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createInitialFocus({
|
|
11
|
+
* get popup() { return dialog; },
|
|
12
|
+
* get open() { return open(); },
|
|
13
|
+
* get initialFocus() { return props.initialFocus; },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A function is called on each opening with the element the browser focused
|
|
18
|
+
* inside the popup, or `null` when it focused none. The browser focuses
|
|
19
|
+
* first, so focus moves twice, in the same task, before anything is painted.
|
|
20
|
+
*/
|
|
21
|
+
function createInitialFocus(options) {
|
|
22
|
+
createEffect(() => options.open, (open) => {
|
|
23
|
+
const popup = options.popup;
|
|
24
|
+
if (!open || !popup) return;
|
|
25
|
+
queueMicrotask(() => {
|
|
26
|
+
if (!popup.matches("[open], :popover-open")) return;
|
|
27
|
+
const active = document.activeElement;
|
|
28
|
+
const target = options.initialFocus;
|
|
29
|
+
(typeof target === "function" ? target(popup.contains(active) ? active : null) : target)?.focus();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { createInitialFocus };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
|
+
// src/floating/focus/returnFocus.ts
|
|
3
|
+
/**
|
|
4
|
+
* Moves focus to `returnFocus` once the popup has closed, instead of where
|
|
5
|
+
* the browser puts it: the element focused before a dialog opened, or a
|
|
6
|
+
* popover's trigger when focus was inside it. Without `returnFocus` the
|
|
7
|
+
* browser decides.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createReturnFocus({
|
|
11
|
+
* get popup() { return dialog; },
|
|
12
|
+
* get open() { return open(); },
|
|
13
|
+
* get returnFocus() { return props.returnFocus; },
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A focus the user moved out of the popup while it was shown, such as a
|
|
18
|
+
* press on another button that closed a popover, stays where it is. Focus
|
|
19
|
+
* returns once the popup is closed, not when its state turns false: after
|
|
20
|
+
* the flush that closed it, or on its `close` or `toggle` event if it is
|
|
21
|
+
* still shown then, as while an exit animation runs. A popup disposed while
|
|
22
|
+
* open moves no focus.
|
|
23
|
+
*/
|
|
24
|
+
function createReturnFocus(options) {
|
|
25
|
+
let stop;
|
|
26
|
+
onCleanup(() => stop?.());
|
|
27
|
+
createEffect(() => options.open, (open) => {
|
|
28
|
+
const popup = options.popup;
|
|
29
|
+
if (!open || !popup) return;
|
|
30
|
+
stop?.();
|
|
31
|
+
let movedOut = false;
|
|
32
|
+
const focusin = (event) => {
|
|
33
|
+
if (isShown(popup)) movedOut = !popup.contains(event.target);
|
|
34
|
+
};
|
|
35
|
+
const finish = () => {
|
|
36
|
+
stop();
|
|
37
|
+
if (movedOut) return;
|
|
38
|
+
const active = document.activeElement;
|
|
39
|
+
const focused = active === document.body || popup.contains(active) ? null : active;
|
|
40
|
+
const target = options.returnFocus;
|
|
41
|
+
(typeof target === "function" ? target(focused) : target)?.focus();
|
|
42
|
+
};
|
|
43
|
+
const closed = (event) => {
|
|
44
|
+
if (event.newState !== "open") finish();
|
|
45
|
+
};
|
|
46
|
+
stop = () => {
|
|
47
|
+
stop = void 0;
|
|
48
|
+
document.removeEventListener("focusin", focusin);
|
|
49
|
+
popup.removeEventListener("close", closed);
|
|
50
|
+
popup.removeEventListener("toggle", closed);
|
|
51
|
+
};
|
|
52
|
+
document.addEventListener("focusin", focusin);
|
|
53
|
+
popup.addEventListener("close", closed);
|
|
54
|
+
popup.addEventListener("toggle", closed);
|
|
55
|
+
return () => {
|
|
56
|
+
queueMicrotask(() => {
|
|
57
|
+
if (stop && !isShown(popup)) finish();
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function isShown(popup) {
|
|
63
|
+
return popup.matches("[open], :popover-open");
|
|
64
|
+
}
|
|
65
|
+
export { createReturnFocus };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { isSameStop, tabStops } from "./tabbable.js";
|
|
2
|
+
import { createEffect } from "solid-js";
|
|
3
|
+
// src/floating/focus/tabWrap.ts
|
|
4
|
+
/**
|
|
5
|
+
* Tab and Shift+Tab cycle inside a modal `<dialog>` while `open`, as the
|
|
6
|
+
* WAI-ARIA modal dialog pattern asks. The browser lets them leave for its
|
|
7
|
+
* own UI.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createTabWrap({
|
|
11
|
+
* get dialog() { return dialog; },
|
|
12
|
+
* get open() { return open(); },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Tab from the last tab stop, or from an element after it, moves to the
|
|
17
|
+
* first; Shift+Tab from the first, from an element before it or from the
|
|
18
|
+
* dialog itself, to the last. Elsewhere the browser moves focus. Only the
|
|
19
|
+
* topmost dialog wraps, and a key already handled does not.
|
|
20
|
+
*/
|
|
21
|
+
function createTabWrap(options) {
|
|
22
|
+
createEffect(() => options.open, (open) => {
|
|
23
|
+
const dialog = options.dialog;
|
|
24
|
+
if (!open || !dialog) return;
|
|
25
|
+
const keydown = (event) => {
|
|
26
|
+
if (event.key !== "Tab" || event.defaultPrevented || dialogOf(event) !== dialog) return;
|
|
27
|
+
const stops = tabStops(dialog);
|
|
28
|
+
const forward = !event.shiftKey;
|
|
29
|
+
const edge = forward ? stops.at(-1) : stops[0];
|
|
30
|
+
let active = document.activeElement;
|
|
31
|
+
while (active?.shadowRoot?.activeElement) active = active.shadowRoot.activeElement;
|
|
32
|
+
if (!edge || isSameStop(active, edge) || !stops.some((stop) => isSameStop(active, stop)) && edge.compareDocumentPosition(active) & (forward ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING)) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
(forward ? stops[0] : stops.at(-1))?.focus();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
window.addEventListener("keydown", keydown);
|
|
38
|
+
return () => window.removeEventListener("keydown", keydown);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The nearest `<dialog>` around the key's target, across shadow roots: at
|
|
43
|
+
* the window, `target` is retargeted to the outermost shadow host.
|
|
44
|
+
*/
|
|
45
|
+
function dialogOf(event) {
|
|
46
|
+
let node = event.composedPath()[0];
|
|
47
|
+
let dialog;
|
|
48
|
+
while (!(dialog = node.closest("dialog"))) {
|
|
49
|
+
const root = node.getRootNode();
|
|
50
|
+
if (!(root instanceof ShadowRoot)) break;
|
|
51
|
+
node = root.host;
|
|
52
|
+
}
|
|
53
|
+
return dialog;
|
|
54
|
+
}
|
|
55
|
+
export { createTabWrap };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/floating/focus/tabbable.ts
|
|
2
|
+
/**
|
|
3
|
+
* The tab stops inside `root`, in the order Tab visits them. Framework-free;
|
|
4
|
+
* reads layout, so call it in the browser, not on the server.
|
|
5
|
+
*
|
|
6
|
+
* A stop is an element whose `tabIndex` is 0 or more, or a `contenteditable`
|
|
7
|
+
* editing host with no `tabindex`, that is not `:disabled`, is visible and
|
|
8
|
+
* is not in an `inert` subtree. A radio group is one stop: its checked
|
|
9
|
+
* radio, else its first. An open shadow root is searched in place of its
|
|
10
|
+
* host's children, and a slot by what is assigned to it, else its fallback.
|
|
11
|
+
* Positive `tabindex` values come first, in ascending order.
|
|
12
|
+
*/
|
|
13
|
+
function tabStops(root) {
|
|
14
|
+
const found = [];
|
|
15
|
+
const search = (parent) => {
|
|
16
|
+
const assigned = parent instanceof HTMLSlotElement ? parent.assignedElements() : [];
|
|
17
|
+
for (const element of parent.shadowRoot?.children ?? (assigned.length ? assigned : parent.children)) {
|
|
18
|
+
if (element.hasAttribute("inert")) continue;
|
|
19
|
+
if (isStop(element)) addStop(found, element);
|
|
20
|
+
search(element);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
search(root);
|
|
24
|
+
return found.sort((a, b) => order(a) - order(b));
|
|
25
|
+
}
|
|
26
|
+
/** Whether Tab stops at `element`, leaving radio groups aside. */
|
|
27
|
+
function isStop(element) {
|
|
28
|
+
const { tabIndex, isContentEditable } = element;
|
|
29
|
+
return (tabIndex >= 0 ? element.localName !== "a" || element.hasAttribute("href") : isContentEditable && !element.parentElement?.isContentEditable && !element.hasAttribute("tabindex")) && !element.matches(":disabled") && element.checkVisibility({ visibilityProperty: true });
|
|
30
|
+
}
|
|
31
|
+
/** Adds a stop, keeping one radio per group: the checked one, else the first. */
|
|
32
|
+
function addStop(found, element) {
|
|
33
|
+
const index = found.findIndex((stop) => isSameStop(stop, element));
|
|
34
|
+
if (index < 0) found.push(element);
|
|
35
|
+
else if (element.checked) found[index] = element;
|
|
36
|
+
}
|
|
37
|
+
/** Whether `a` and `b` are one tab stop: the same element, or one radio group. */
|
|
38
|
+
function isSameStop(a, b) {
|
|
39
|
+
return a === b || isGroupedRadio(a) && isGroupedRadio(b) && a.name === b.name && a.form === b.form;
|
|
40
|
+
}
|
|
41
|
+
function isGroupedRadio(element) {
|
|
42
|
+
return element instanceof HTMLInputElement && element.type === "radio" && element.name !== "";
|
|
43
|
+
}
|
|
44
|
+
/** Above any positive `tabindex`, for the stops in tree order. */
|
|
45
|
+
var IN_TREE_ORDER = 2 ** 31;
|
|
46
|
+
/** Positive `tabindex` values first, then the rest. */
|
|
47
|
+
function order(element) {
|
|
48
|
+
return element.tabIndex > 0 ? element.tabIndex : IN_TREE_ORDER;
|
|
49
|
+
}
|
|
50
|
+
export { isSameStop, tabStops };
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/floating/hover/group.ts
|
|
2
|
+
/**
|
|
3
|
+
* A group of hover popups, such as the tooltips of a toolbar: once one is
|
|
4
|
+
* open, hovering another opens it at once and closes the first. Created by
|
|
5
|
+
* the part that groups triggers, provided through its context, and passed
|
|
6
|
+
* to each popup's `createHover` as `group`:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* const group = createHoverGroup({
|
|
10
|
+
* get delay() { return props.delay; },
|
|
11
|
+
* get timeout() { return props.timeout; },
|
|
12
|
+
* });
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* The next member still opens at once within `timeout` milliseconds
|
|
16
|
+
* (default 400) of the last one closing. `delay` is the delay of members
|
|
17
|
+
* that set none. Only popups opened by hover count. It keeps the time of
|
|
18
|
+
* the last closing, not a timer, so it has nothing to clear.
|
|
19
|
+
*/
|
|
20
|
+
function createHoverGroup(options = {}) {
|
|
21
|
+
let current;
|
|
22
|
+
let closedAt = -Infinity;
|
|
23
|
+
return {
|
|
24
|
+
delay: (own) => current || Date.now() - closedAt < (options.timeout ?? 400) ? 0 : own ?? options.delay,
|
|
25
|
+
opened(member, event) {
|
|
26
|
+
if (current !== member) current?.close(event);
|
|
27
|
+
current = member;
|
|
28
|
+
},
|
|
29
|
+
closed(member) {
|
|
30
|
+
if (current !== member) return;
|
|
31
|
+
current = void 0;
|
|
32
|
+
closedAt = Date.now();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export { createHoverGroup };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { trackSafeArea } from "./safeArea.js";
|
|
2
|
+
import { createEffect, createSignal, onCleanup, onSettled } from "solid-js";
|
|
3
|
+
// src/floating/hover/hover.ts
|
|
4
|
+
/**
|
|
5
|
+
* Opens a popup when the pointer rests on its trigger for `delay`
|
|
6
|
+
* milliseconds (default 600), and closes it `closeDelay` milliseconds
|
|
7
|
+
* (default 0) after the pointer has left both the trigger and the popup:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* createHover({
|
|
11
|
+
* get trigger() { return trigger; },
|
|
12
|
+
* get popup() { return popup; },
|
|
13
|
+
* get open() { return open(); },
|
|
14
|
+
* get delay() { return props.delay; },
|
|
15
|
+
* onOpenChange: (open, details) => setOpen(open, details),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Both report `trigger-hover`. The pointer may cross from the trigger to the
|
|
20
|
+
* popup, and back, through the safe area between them (`trackSafeArea`).
|
|
21
|
+
* A mouse or a pen opens it; a touch does not. While `disabled`, hovering
|
|
22
|
+
* opens nothing. In a `group` (`createHoverGroup`), it opens at once while
|
|
23
|
+
* another member is open, and closes that one. A change of `open`, from
|
|
24
|
+
* here or elsewhere, and disposal clear a pending delay; disposal also
|
|
25
|
+
* takes the popup out of its group. Nothing runs on the server.
|
|
26
|
+
*/
|
|
27
|
+
function createHover(options) {
|
|
28
|
+
let timer;
|
|
29
|
+
let stopSafeArea;
|
|
30
|
+
let last;
|
|
31
|
+
const cancel = () => {
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
timer = void 0;
|
|
34
|
+
stopSafeArea?.();
|
|
35
|
+
stopSafeArea = void 0;
|
|
36
|
+
};
|
|
37
|
+
/** Opens or closes after `delay`, or now if it is 0. */
|
|
38
|
+
const schedule = (open, event, delay) => {
|
|
39
|
+
cancel();
|
|
40
|
+
const set = () => {
|
|
41
|
+
timer = void 0;
|
|
42
|
+
if (open && (options.disabled || !options.trigger?.isConnected)) return;
|
|
43
|
+
if (open) options.group?.opened(member, event);
|
|
44
|
+
options.onOpenChange(open, {
|
|
45
|
+
reason: "trigger-hover",
|
|
46
|
+
event
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
if (delay > 0) timer = setTimeout(set, delay);
|
|
50
|
+
else set();
|
|
51
|
+
};
|
|
52
|
+
const close = (event) => schedule(false, event, options.closeDelay ?? 0);
|
|
53
|
+
const member = { close: (event) => schedule(false, event, 0) };
|
|
54
|
+
onCleanup(() => {
|
|
55
|
+
cancel();
|
|
56
|
+
options.group?.closed(member);
|
|
57
|
+
});
|
|
58
|
+
const listen = (element, other, onEnter) => {
|
|
59
|
+
const enter = (event) => {
|
|
60
|
+
if (event.pointerType === "touch") return;
|
|
61
|
+
move(event);
|
|
62
|
+
cancel();
|
|
63
|
+
onEnter(event);
|
|
64
|
+
};
|
|
65
|
+
const move = (event) => {
|
|
66
|
+
if (event.pointerType !== "touch") last = event;
|
|
67
|
+
};
|
|
68
|
+
const leave = (event) => {
|
|
69
|
+
if (event.pointerType === "touch") return;
|
|
70
|
+
cancel();
|
|
71
|
+
if (!options.open) return;
|
|
72
|
+
const to = other();
|
|
73
|
+
if (to && event.relatedTarget && (event.clientX !== last?.clientX || event.clientY !== last.clientY)) stopSafeArea = trackSafeArea(event, to, close);
|
|
74
|
+
else close(event);
|
|
75
|
+
};
|
|
76
|
+
element.addEventListener("pointerenter", enter);
|
|
77
|
+
element.addEventListener("pointermove", move);
|
|
78
|
+
element.addEventListener("pointerleave", leave);
|
|
79
|
+
return () => {
|
|
80
|
+
element.removeEventListener("pointerenter", enter);
|
|
81
|
+
element.removeEventListener("pointermove", move);
|
|
82
|
+
element.removeEventListener("pointerleave", leave);
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
const [mounted, setMounted] = createSignal(false);
|
|
86
|
+
onSettled(() => {
|
|
87
|
+
setMounted(true);
|
|
88
|
+
});
|
|
89
|
+
createEffect(() => mounted() && options.trigger, (trigger) => {
|
|
90
|
+
if (!trigger) return;
|
|
91
|
+
return listen(trigger, () => options.popup, (event) => {
|
|
92
|
+
if (options.open || options.disabled) return;
|
|
93
|
+
const group = options.group;
|
|
94
|
+
schedule(true, event, (group ? group.delay(options.delay) : options.delay) ?? 600);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
createEffect(() => options.open, (open) => {
|
|
98
|
+
cancel();
|
|
99
|
+
if (!open) options.group?.closed(member);
|
|
100
|
+
const popup = options.popup;
|
|
101
|
+
if (!open || !popup) return;
|
|
102
|
+
return listen(popup, () => options.trigger, () => {});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export { createHover };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/floating/hover/safeArea.ts
|
|
2
|
+
/**
|
|
3
|
+
* Follows the pointer once it has left one element on its way to another,
|
|
4
|
+
* such as from a trigger to its popup across the gap between them, and
|
|
5
|
+
* calls `onLeave` with the event once it moves out of the way:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* trigger.addEventListener("pointerleave", (event) => {
|
|
9
|
+
* stop = trackSafeArea(event, popup, () => close());
|
|
10
|
+
* });
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* The safe area is every point on a line from `exit`, where the pointer
|
|
14
|
+
* left, to the box of `element`, read again on each move. A move outside
|
|
15
|
+
* it, or past the element, ends it, and so does the pointer leaving the
|
|
16
|
+
* window. A touch is ignored. Returns what stops following; call it when
|
|
17
|
+
* the pointer reaches the element. Plain DOM, with no timers and no Solid.
|
|
18
|
+
*/
|
|
19
|
+
function trackSafeArea(exit, element, onLeave) {
|
|
20
|
+
const check = (event) => {
|
|
21
|
+
if (event.pointerType === "touch" || (event.type === "pointerout" ? event.relatedTarget : inSafeArea(exit, event, element.getBoundingClientRect()))) return;
|
|
22
|
+
stop();
|
|
23
|
+
onLeave(event);
|
|
24
|
+
};
|
|
25
|
+
const stop = () => {
|
|
26
|
+
document.removeEventListener("pointermove", check);
|
|
27
|
+
document.removeEventListener("pointerout", check);
|
|
28
|
+
};
|
|
29
|
+
document.addEventListener("pointermove", check);
|
|
30
|
+
document.addEventListener("pointerout", check);
|
|
31
|
+
return stop;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether `point` is on a line from `exit` to `box`: whether the ray from
|
|
35
|
+
* `exit` through `point` meets the box at or beyond `point`. Each axis
|
|
36
|
+
* gives the stretch of the ray, in multiples of `exit` to `point`, that is
|
|
37
|
+
* within the box's extent on it; the point is inside if the stretches of
|
|
38
|
+
* both axes overlap beyond 1.
|
|
39
|
+
*/
|
|
40
|
+
function inSafeArea(exit, point, box) {
|
|
41
|
+
let from = 1;
|
|
42
|
+
let to = Infinity;
|
|
43
|
+
for (const [start, end, min, max] of [[
|
|
44
|
+
exit.clientX,
|
|
45
|
+
point.clientX,
|
|
46
|
+
box.left,
|
|
47
|
+
box.right
|
|
48
|
+
], [
|
|
49
|
+
exit.clientY,
|
|
50
|
+
point.clientY,
|
|
51
|
+
box.top,
|
|
52
|
+
box.bottom
|
|
53
|
+
]]) {
|
|
54
|
+
const step = end - start;
|
|
55
|
+
if (step) {
|
|
56
|
+
const a = (min - start) / step;
|
|
57
|
+
const b = (max - start) / step;
|
|
58
|
+
from = Math.max(from, Math.min(a, b));
|
|
59
|
+
to = Math.min(to, Math.max(a, b));
|
|
60
|
+
} else if (start < min || start > max) return point.clientX === exit.clientX && point.clientY === exit.clientY;
|
|
61
|
+
}
|
|
62
|
+
return from <= to;
|
|
63
|
+
}
|
|
64
|
+
export { trackSafeArea };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createListNavigation } from "./listNavigation.js";
|
|
2
|
+
// src/floating/list-navigation/activeDescendant.ts
|
|
3
|
+
/**
|
|
4
|
+
* List navigation where focus stays on another element, such as a
|
|
5
|
+
* combobox's input, which names the active item in `aria-activedescendant`.
|
|
6
|
+
* The item part takes `props.id ?? createUniqueId()` and registers once
|
|
7
|
+
* mounted, so the server HTML names no item:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const list = createActiveDescendantList<Entry>({
|
|
11
|
+
* get open() { return open(); },
|
|
12
|
+
* });
|
|
13
|
+
* // On the input:
|
|
14
|
+
* const inputProps = {
|
|
15
|
+
* get "aria-activedescendant"() { return list.activeId(); },
|
|
16
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
17
|
+
* };
|
|
18
|
+
* // In the item part:
|
|
19
|
+
* onSettled(() => list.register(item));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
function createActiveDescendantList(options) {
|
|
23
|
+
const list = createListNavigation(options);
|
|
24
|
+
return {
|
|
25
|
+
...list,
|
|
26
|
+
activeId: () => list.active()?.id
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export { createActiveDescendantList };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createEffect, createMemo, createSignal } from "solid-js";
|
|
2
|
+
// src/floating/list-navigation/listNavigation.ts
|
|
3
|
+
var byPosition = (a, b) => a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
4
|
+
/**
|
|
5
|
+
* The items of a list in document order, the active item, the keys and the
|
|
6
|
+
* pointer: what both ways of holding focus share. `focusItem` is the way's
|
|
7
|
+
* own: the roving form focuses the item. Nothing runs at import time, nor,
|
|
8
|
+
* until a key or the pointer, on the server.
|
|
9
|
+
*/
|
|
10
|
+
function createListNavigation(options, focusItem) {
|
|
11
|
+
const [registered, setRegistered] = createSignal([]);
|
|
12
|
+
const ordered = createMemo(() => [...registered()].sort(byPosition));
|
|
13
|
+
const reachable = (item) => options.reachable?.(item) ?? true;
|
|
14
|
+
const [active, setActive] = createSignal();
|
|
15
|
+
const activeSignals = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
const activeSignal = (item) => {
|
|
17
|
+
let signal = activeSignals.get(item);
|
|
18
|
+
if (!signal) {
|
|
19
|
+
const [read, write] = createSignal(false);
|
|
20
|
+
activeSignals.set(item, signal = [read, write]);
|
|
21
|
+
}
|
|
22
|
+
return signal;
|
|
23
|
+
};
|
|
24
|
+
let activeItem;
|
|
25
|
+
const activate = (item) => {
|
|
26
|
+
if (activeItem) activeSignal(activeItem)[1](false);
|
|
27
|
+
if (item) activeSignal(item)[1](true);
|
|
28
|
+
activeItem = item;
|
|
29
|
+
setActive(() => item);
|
|
30
|
+
};
|
|
31
|
+
const focusAndScroll = (item) => {
|
|
32
|
+
focusItem?.(item);
|
|
33
|
+
item.element.scrollIntoView({
|
|
34
|
+
block: "nearest",
|
|
35
|
+
inline: "nearest"
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const list = {
|
|
39
|
+
register: (item) => {
|
|
40
|
+
setRegistered((items) => [...items, item]);
|
|
41
|
+
return () => {
|
|
42
|
+
setRegistered((items) => items.filter((other) => other !== item));
|
|
43
|
+
if (activeItem === item) activate(void 0);
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
items: () => ordered().filter(reachable),
|
|
47
|
+
active,
|
|
48
|
+
isActive: (item) => activeSignal(item)[0](),
|
|
49
|
+
move: (item) => {
|
|
50
|
+
if (item && !reachable(item)) return;
|
|
51
|
+
activate(item);
|
|
52
|
+
if (item && options.open !== false) focusAndScroll(item);
|
|
53
|
+
},
|
|
54
|
+
onKeyDown: (event) => {
|
|
55
|
+
const { target } = event;
|
|
56
|
+
if (target !== event.currentTarget && !registered().some((item) => item.element === target)) return false;
|
|
57
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return false;
|
|
58
|
+
const items = list.items();
|
|
59
|
+
const itemCount = items.length;
|
|
60
|
+
const activeIndex = items.indexOf(activeItem);
|
|
61
|
+
const directionSource = (activeItem ?? items[0])?.element;
|
|
62
|
+
const [leftKey, rightKey] = directionSource && getComputedStyle(directionSource).direction === "rtl" ? ["ArrowRight", "ArrowLeft"] : ["ArrowLeft", "ArrowRight"];
|
|
63
|
+
const [backKey, forwardKey, outKey, intoKey] = options.orientation === "horizontal" ? [
|
|
64
|
+
leftKey,
|
|
65
|
+
rightKey,
|
|
66
|
+
"ArrowUp",
|
|
67
|
+
"ArrowDown"
|
|
68
|
+
] : [
|
|
69
|
+
"ArrowUp",
|
|
70
|
+
"ArrowDown",
|
|
71
|
+
leftKey,
|
|
72
|
+
rightKey
|
|
73
|
+
];
|
|
74
|
+
const { onArrowIn, onArrowOut } = options;
|
|
75
|
+
if (event.key === intoKey && activeItem && onArrowIn) {
|
|
76
|
+
onArrowIn(activeItem, event);
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
if (event.key === outKey && onArrowOut) {
|
|
80
|
+
onArrowOut(activeItem, event);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
const toIndex = event.key === backKey ? (activeIndex < 0 ? itemCount : activeIndex) - 1 : event.key === forwardKey ? activeIndex + 1 : event.key === "Home" ? 0 : event.key === "End" ? itemCount - 1 : void 0;
|
|
84
|
+
if (toIndex === void 0 || !itemCount) return false;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
list.move(items[options.wrap ? (toIndex + itemCount) % itemCount : Math.min(Math.max(toIndex, 0), itemCount - 1)]);
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
onPointerMove: (item, event) => {
|
|
90
|
+
if (options.open === false || event.pointerType === "touch") return;
|
|
91
|
+
if (activeItem === item) return;
|
|
92
|
+
if (!reachable(item)) return;
|
|
93
|
+
activate(item);
|
|
94
|
+
focusItem?.(item);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
createEffect(() => options.open, (open) => {
|
|
98
|
+
if (open === false) {
|
|
99
|
+
activate(void 0);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
queueMicrotask(() => {
|
|
103
|
+
if (activeItem) focusAndScroll(activeItem);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
return list;
|
|
107
|
+
}
|
|
108
|
+
export { createListNavigation };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createListNavigation } from "./listNavigation.js";
|
|
2
|
+
// src/floating/list-navigation/roving.ts
|
|
3
|
+
/**
|
|
4
|
+
* List navigation where focus moves to the active item (roving `tabindex`),
|
|
5
|
+
* as in a menu. The item part registers once mounted, sets `tabindex` to 0
|
|
6
|
+
* on the active item and -1 on the others, and hands its key and pointer
|
|
7
|
+
* events over:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const list = createRovingList<Entry>({
|
|
11
|
+
* get open() { return open(); },
|
|
12
|
+
* reachable: (item) => true,
|
|
13
|
+
* });
|
|
14
|
+
* // In the item part:
|
|
15
|
+
* onSettled(() => list.register(item));
|
|
16
|
+
* const ownProps = {
|
|
17
|
+
* get tabindex() { return list.isActive(item) ? 0 : -1; },
|
|
18
|
+
* get "data-active"() { return list.isActive(item) ? "" : undefined; },
|
|
19
|
+
* onKeyDown: (event) => list.onKeyDown(event),
|
|
20
|
+
* onPointerMove: (event) => list.onPointerMove(item, event),
|
|
21
|
+
* };
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function createRovingList(options) {
|
|
25
|
+
return createListNavigation(options, (item) => item.element.focus({ preventScroll: true }));
|
|
26
|
+
}
|
|
27
|
+
export { createRovingList };
|