@tamagui/floating 2.0.0-rc.4 → 2.0.0-rc.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Floating.cjs +7 -5
- package/dist/cjs/Floating.native.js +19 -13
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +46 -13
- package/dist/cjs/index.native.js +46 -13
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/cjs/interactions/safePolygon.cjs +273 -0
- package/dist/cjs/interactions/safePolygon.native.js +284 -0
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
- package/dist/cjs/interactions/types.cjs +18 -0
- package/dist/cjs/interactions/types.native.js +21 -0
- package/dist/cjs/interactions/types.native.js.map +1 -0
- package/dist/cjs/interactions/useClick.cjs +124 -0
- package/dist/cjs/interactions/useClick.native.js +132 -0
- package/dist/cjs/interactions/useClick.native.js.map +1 -0
- package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/cjs/interactions/useFocus.cjs +130 -0
- package/dist/cjs/interactions/useFocus.native.js +139 -0
- package/dist/cjs/interactions/useFocus.native.js.map +1 -0
- package/dist/cjs/interactions/useHover.cjs +357 -0
- package/dist/cjs/interactions/useHover.native.js +373 -0
- package/dist/cjs/interactions/useHover.native.js.map +1 -0
- package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/cjs/interactions/useInteractions.cjs +105 -0
- package/dist/cjs/interactions/useInteractions.native.js +216 -0
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
- package/dist/cjs/interactions/useListNavigation.cjs +418 -0
- package/dist/cjs/interactions/useListNavigation.native.js +433 -0
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
- package/dist/cjs/interactions/useRole.cjs +122 -0
- package/dist/cjs/interactions/useRole.native.js +136 -0
- package/dist/cjs/interactions/useRole.native.js.map +1 -0
- package/dist/cjs/interactions/useTypeahead.cjs +143 -0
- package/dist/cjs/interactions/useTypeahead.native.js +159 -0
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
- package/dist/cjs/interactions/utils.cjs +208 -0
- package/dist/cjs/interactions/utils.native.js +227 -0
- package/dist/cjs/interactions/utils.native.js.map +1 -0
- package/dist/cjs/middleware/inner.cjs +118 -0
- package/dist/cjs/middleware/inner.native.js +130 -0
- package/dist/cjs/middleware/inner.native.js.map +1 -0
- package/dist/cjs/useFloating.cjs +35 -28
- package/dist/cjs/useFloating.native.js +51 -47
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +6 -3
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/index.js +17 -34
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +16 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +16 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/esm/interactions/safePolygon.mjs +248 -0
- package/dist/esm/interactions/safePolygon.mjs.map +1 -0
- package/dist/esm/interactions/safePolygon.native.js +256 -0
- package/dist/esm/interactions/safePolygon.native.js.map +1 -0
- package/dist/esm/interactions/types.mjs +2 -0
- package/dist/esm/interactions/types.mjs.map +1 -0
- package/dist/esm/interactions/types.native.js +2 -0
- package/dist/esm/interactions/types.native.js.map +1 -0
- package/dist/esm/interactions/useClick.mjs +99 -0
- package/dist/esm/interactions/useClick.mjs.map +1 -0
- package/dist/esm/interactions/useClick.native.js +104 -0
- package/dist/esm/interactions/useClick.native.js.map +1 -0
- package/dist/esm/interactions/useDelayGroup.mjs +77 -0
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
- package/dist/esm/interactions/useDelayGroup.native.js +84 -0
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/esm/interactions/useFocus.mjs +105 -0
- package/dist/esm/interactions/useFocus.mjs.map +1 -0
- package/dist/esm/interactions/useFocus.native.js +111 -0
- package/dist/esm/interactions/useFocus.native.js.map +1 -0
- package/dist/esm/interactions/useHover.mjs +320 -0
- package/dist/esm/interactions/useHover.mjs.map +1 -0
- package/dist/esm/interactions/useHover.native.js +333 -0
- package/dist/esm/interactions/useHover.native.js.map +1 -0
- package/dist/esm/interactions/useInnerOffset.mjs +92 -0
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
- package/dist/esm/interactions/useInnerOffset.native.js +102 -0
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/esm/interactions/useInteractions.mjs +80 -0
- package/dist/esm/interactions/useInteractions.mjs.map +1 -0
- package/dist/esm/interactions/useInteractions.native.js +188 -0
- package/dist/esm/interactions/useInteractions.native.js.map +1 -0
- package/dist/esm/interactions/useListNavigation.mjs +393 -0
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
- package/dist/esm/interactions/useListNavigation.native.js +405 -0
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
- package/dist/esm/interactions/useRole.mjs +86 -0
- package/dist/esm/interactions/useRole.mjs.map +1 -0
- package/dist/esm/interactions/useRole.native.js +97 -0
- package/dist/esm/interactions/useRole.native.js.map +1 -0
- package/dist/esm/interactions/useTypeahead.mjs +118 -0
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
- package/dist/esm/interactions/useTypeahead.native.js +131 -0
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
- package/dist/esm/interactions/utils.mjs +162 -0
- package/dist/esm/interactions/utils.mjs.map +1 -0
- package/dist/esm/interactions/utils.native.js +178 -0
- package/dist/esm/interactions/utils.native.js.map +1 -0
- package/dist/esm/middleware/inner.mjs +82 -0
- package/dist/esm/middleware/inner.mjs.map +1 -0
- package/dist/esm/middleware/inner.native.js +91 -0
- package/dist/esm/middleware/inner.native.js.map +1 -0
- package/dist/esm/useFloating.mjs +8 -3
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +25 -23
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +8 -10
- package/src/Floating.native.tsx +1 -0
- package/src/index.ts +49 -0
- package/src/interactions/PopupTriggerMap.ts +30 -0
- package/src/interactions/createFloatingEvents.ts +34 -0
- package/src/interactions/safePolygon.ts +500 -0
- package/src/interactions/types.ts +165 -0
- package/src/interactions/useClick.ts +148 -0
- package/src/interactions/useDelayGroup.ts +114 -0
- package/src/interactions/useFocus.ts +164 -0
- package/src/interactions/useHover.ts +453 -0
- package/src/interactions/useInnerOffset.ts +116 -0
- package/src/interactions/useInteractions.ts +101 -0
- package/src/interactions/useListNavigation.ts +578 -0
- package/src/interactions/useRole.ts +103 -0
- package/src/interactions/useTypeahead.ts +173 -0
- package/src/interactions/utils.ts +234 -0
- package/src/middleware/inner.ts +141 -0
- package/src/useFloating.tsx +13 -1
- package/types/Floating.native.d.ts +1 -0
- package/types/Floating.native.d.ts.map +1 -1
- package/types/index.d.ts +17 -2
- package/types/index.d.ts.map +1 -1
- package/types/interactions/PopupTriggerMap.d.ts +8 -0
- package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
- package/types/interactions/createFloatingEvents.d.ts +7 -0
- package/types/interactions/createFloatingEvents.d.ts.map +1 -0
- package/types/interactions/safePolygon.d.ts +4 -0
- package/types/interactions/safePolygon.d.ts.map +1 -0
- package/types/interactions/types.d.ts +123 -0
- package/types/interactions/types.d.ts.map +1 -0
- package/types/interactions/useClick.d.ts +3 -0
- package/types/interactions/useClick.d.ts.map +1 -0
- package/types/interactions/useDelayGroup.d.ts +23 -0
- package/types/interactions/useDelayGroup.d.ts.map +1 -0
- package/types/interactions/useFocus.d.ts +3 -0
- package/types/interactions/useFocus.d.ts.map +1 -0
- package/types/interactions/useHover.d.ts +6 -0
- package/types/interactions/useHover.d.ts.map +1 -0
- package/types/interactions/useInnerOffset.d.ts +3 -0
- package/types/interactions/useInnerOffset.d.ts.map +1 -0
- package/types/interactions/useInteractions.d.ts +8 -0
- package/types/interactions/useInteractions.d.ts.map +1 -0
- package/types/interactions/useListNavigation.d.ts +3 -0
- package/types/interactions/useListNavigation.d.ts.map +1 -0
- package/types/interactions/useRole.d.ts +3 -0
- package/types/interactions/useRole.d.ts.map +1 -0
- package/types/interactions/useTypeahead.d.ts +3 -0
- package/types/interactions/useTypeahead.d.ts.map +1 -0
- package/types/interactions/utils.d.ts +46 -0
- package/types/interactions/utils.d.ts.map +1 -0
- package/types/middleware/inner.d.ts +14 -0
- package/types/middleware/inner.d.ts.map +1 -0
- package/types/useFloating.d.ts +7 -1
- package/types/useFloating.d.ts.map +1 -1
- package/dist/cjs/Floating.js +0 -15
- package/dist/cjs/Floating.js.map +0 -6
- package/dist/cjs/index.js +0 -34
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useFloating.js +0 -46
- package/dist/cjs/useFloating.js.map +0 -6
- package/dist/esm/Floating.js +0 -2
- package/dist/esm/Floating.js.map +0 -6
- package/dist/esm/useFloating.js +0 -23
- package/dist/esm/useFloating.js.map +0 -6
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var useListNavigation_exports = {};
|
|
24
|
+
__export(useListNavigation_exports, {
|
|
25
|
+
useListNavigation: () => useListNavigation
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useListNavigation_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_use_event = require("@tamagui/use-event");
|
|
30
|
+
var import_utils = require("./utils.cjs");
|
|
31
|
+
const ARROW_UP = "ArrowUp";
|
|
32
|
+
const ARROW_DOWN = "ArrowDown";
|
|
33
|
+
const ARROW_LEFT = "ArrowLeft";
|
|
34
|
+
const ARROW_RIGHT = "ArrowRight";
|
|
35
|
+
function doSwitch(orientation, vertical, horizontal) {
|
|
36
|
+
switch (orientation) {
|
|
37
|
+
case "vertical":
|
|
38
|
+
return vertical;
|
|
39
|
+
case "horizontal":
|
|
40
|
+
return horizontal;
|
|
41
|
+
default:
|
|
42
|
+
return vertical || horizontal;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function isMainOrientationKey(key, orientation) {
|
|
46
|
+
const vertical = key === ARROW_UP || key === ARROW_DOWN;
|
|
47
|
+
const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
|
|
48
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
49
|
+
}
|
|
50
|
+
function isMainOrientationToEndKey(key, orientation, rtl) {
|
|
51
|
+
const vertical = key === ARROW_DOWN;
|
|
52
|
+
const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
|
|
53
|
+
return doSwitch(orientation, vertical, horizontal) || key === "Enter" || key === " " || key === "";
|
|
54
|
+
}
|
|
55
|
+
function isCrossOrientationOpenKey(key, orientation, rtl) {
|
|
56
|
+
const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
|
|
57
|
+
const horizontal = key === ARROW_DOWN;
|
|
58
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
59
|
+
}
|
|
60
|
+
function isCrossOrientationCloseKey(key, orientation, rtl) {
|
|
61
|
+
const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
|
|
62
|
+
const horizontal = key === ARROW_UP;
|
|
63
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
64
|
+
}
|
|
65
|
+
function useListNavigation(context, props) {
|
|
66
|
+
const {
|
|
67
|
+
open,
|
|
68
|
+
onOpenChange,
|
|
69
|
+
elements
|
|
70
|
+
} = context;
|
|
71
|
+
const {
|
|
72
|
+
listRef,
|
|
73
|
+
activeIndex,
|
|
74
|
+
onNavigate: unstable_onNavigate = () => {},
|
|
75
|
+
enabled = true,
|
|
76
|
+
selectedIndex = null,
|
|
77
|
+
allowEscape = false,
|
|
78
|
+
loop = false,
|
|
79
|
+
nested = false,
|
|
80
|
+
rtl = false,
|
|
81
|
+
virtual = false,
|
|
82
|
+
focusItemOnOpen = "auto",
|
|
83
|
+
focusItemOnHover = true,
|
|
84
|
+
openOnArrowKeyDown = true,
|
|
85
|
+
disabledIndices = void 0,
|
|
86
|
+
orientation = "vertical",
|
|
87
|
+
scrollItemIntoView = true
|
|
88
|
+
} = props;
|
|
89
|
+
const typeableComboboxReference = (0, import_utils.isTypeableCombobox)(elements.domReference);
|
|
90
|
+
const focusItemOnOpenRef = (0, import_react.useRef)(focusItemOnOpen);
|
|
91
|
+
const indexRef = (0, import_react.useRef)(selectedIndex ?? -1);
|
|
92
|
+
const keyRef = (0, import_react.useRef)(null);
|
|
93
|
+
const isPointerModalityRef = (0, import_react.useRef)(true);
|
|
94
|
+
const previousMountedRef = (0, import_react.useRef)(!!elements.floating);
|
|
95
|
+
const previousOpenRef = (0, import_react.useRef)(open);
|
|
96
|
+
const forceSyncFocusRef = (0, import_react.useRef)(false);
|
|
97
|
+
const forceScrollIntoViewRef = (0, import_react.useRef)(false);
|
|
98
|
+
const disabledIndicesRef = (0, import_react.useRef)(disabledIndices);
|
|
99
|
+
disabledIndicesRef.current = disabledIndices;
|
|
100
|
+
const latestOpenRef = (0, import_react.useRef)(open);
|
|
101
|
+
latestOpenRef.current = open;
|
|
102
|
+
const scrollItemIntoViewRef = (0, import_react.useRef)(scrollItemIntoView);
|
|
103
|
+
scrollItemIntoViewRef.current = scrollItemIntoView;
|
|
104
|
+
const selectedIndexRef = (0, import_react.useRef)(selectedIndex);
|
|
105
|
+
selectedIndexRef.current = selectedIndex;
|
|
106
|
+
const stableOnNavigate = (0, import_use_event.useEvent)(unstable_onNavigate);
|
|
107
|
+
const [activeId, setActiveId] = (0, import_react.useState)();
|
|
108
|
+
const onNavigate = (0, import_use_event.useEvent)(() => {
|
|
109
|
+
stableOnNavigate(indexRef.current === -1 ? null : indexRef.current);
|
|
110
|
+
});
|
|
111
|
+
const previousOnNavigateRef = (0, import_react.useRef)(onNavigate);
|
|
112
|
+
const focusItem = (0, import_use_event.useEvent)(() => {
|
|
113
|
+
function runFocus(item2) {
|
|
114
|
+
if (virtual) {
|
|
115
|
+
setActiveId(item2.id);
|
|
116
|
+
} else {
|
|
117
|
+
(0, import_utils.enqueueFocus)(item2, {
|
|
118
|
+
sync: forceSyncFocusRef.current,
|
|
119
|
+
preventScroll: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const initialItem = listRef.current[indexRef.current];
|
|
124
|
+
const forceScrollIntoView = forceScrollIntoViewRef.current;
|
|
125
|
+
if (initialItem) {
|
|
126
|
+
runFocus(initialItem);
|
|
127
|
+
}
|
|
128
|
+
const scheduler = forceSyncFocusRef.current ? v => v() : requestAnimationFrame;
|
|
129
|
+
scheduler(() => {
|
|
130
|
+
const waitedItem = listRef.current[indexRef.current] || initialItem;
|
|
131
|
+
if (!waitedItem) return;
|
|
132
|
+
if (!initialItem) {
|
|
133
|
+
runFocus(waitedItem);
|
|
134
|
+
}
|
|
135
|
+
const scrollIntoViewOptions = scrollItemIntoViewRef.current;
|
|
136
|
+
const shouldScrollIntoView = scrollIntoViewOptions && waitedItem && (forceScrollIntoView || !isPointerModalityRef.current);
|
|
137
|
+
if (shouldScrollIntoView) {
|
|
138
|
+
waitedItem.scrollIntoView?.(typeof scrollIntoViewOptions === "boolean" ? {
|
|
139
|
+
block: "nearest",
|
|
140
|
+
inline: "nearest"
|
|
141
|
+
} : scrollIntoViewOptions);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
146
|
+
if (!enabled) return;
|
|
147
|
+
if (open && elements.floating) {
|
|
148
|
+
if (focusItemOnOpenRef.current && selectedIndex != null) {
|
|
149
|
+
forceScrollIntoViewRef.current = true;
|
|
150
|
+
indexRef.current = selectedIndex;
|
|
151
|
+
onNavigate();
|
|
152
|
+
}
|
|
153
|
+
} else if (previousMountedRef.current) {
|
|
154
|
+
indexRef.current = -1;
|
|
155
|
+
previousOnNavigateRef.current();
|
|
156
|
+
}
|
|
157
|
+
}, [enabled, open, elements.floating, selectedIndex, onNavigate]);
|
|
158
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
159
|
+
if (!enabled) return;
|
|
160
|
+
if (!open) return;
|
|
161
|
+
if (!elements.floating) return;
|
|
162
|
+
if (activeIndex == null) {
|
|
163
|
+
forceSyncFocusRef.current = false;
|
|
164
|
+
if (selectedIndexRef.current != null) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (previousMountedRef.current) {
|
|
168
|
+
indexRef.current = -1;
|
|
169
|
+
focusItem();
|
|
170
|
+
}
|
|
171
|
+
if ((!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {
|
|
172
|
+
let runs = 0;
|
|
173
|
+
const waitForListPopulated = () => {
|
|
174
|
+
if (listRef.current[0] == null) {
|
|
175
|
+
if (runs < 2) {
|
|
176
|
+
const scheduler = runs ? requestAnimationFrame : queueMicrotask;
|
|
177
|
+
scheduler(waitForListPopulated);
|
|
178
|
+
}
|
|
179
|
+
runs++;
|
|
180
|
+
} else {
|
|
181
|
+
indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current) : (0, import_utils.getMaxListIndex)(listRef, disabledIndicesRef.current);
|
|
182
|
+
keyRef.current = null;
|
|
183
|
+
onNavigate();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
waitForListPopulated();
|
|
187
|
+
}
|
|
188
|
+
} else if (!(0, import_utils.isIndexOutOfListBounds)(listRef, activeIndex)) {
|
|
189
|
+
indexRef.current = activeIndex;
|
|
190
|
+
focusItem();
|
|
191
|
+
forceScrollIntoViewRef.current = false;
|
|
192
|
+
}
|
|
193
|
+
}, [enabled, open, elements.floating, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]);
|
|
194
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
195
|
+
previousOnNavigateRef.current = onNavigate;
|
|
196
|
+
previousOpenRef.current = open;
|
|
197
|
+
previousMountedRef.current = !!elements.floating;
|
|
198
|
+
});
|
|
199
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
200
|
+
if (!open) {
|
|
201
|
+
keyRef.current = null;
|
|
202
|
+
focusItemOnOpenRef.current = focusItemOnOpen;
|
|
203
|
+
}
|
|
204
|
+
}, [open, focusItemOnOpen]);
|
|
205
|
+
const hasActiveIndex = activeIndex != null;
|
|
206
|
+
const commonOnKeyDown = (0, import_use_event.useEvent)(event => {
|
|
207
|
+
isPointerModalityRef.current = false;
|
|
208
|
+
forceSyncFocusRef.current = true;
|
|
209
|
+
if (event.which === 229) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!latestOpenRef.current && event.currentTarget === elements.floating) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {
|
|
216
|
+
(0, import_utils.stopEvent)(event);
|
|
217
|
+
onOpenChange(false, event.nativeEvent, "list-navigation");
|
|
218
|
+
if ((0, import_utils.isHTMLElement)(elements.domReference)) {
|
|
219
|
+
elements.domReference.focus();
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const currentIndex = indexRef.current;
|
|
224
|
+
const minIndex = (0, import_utils.getMinListIndex)(listRef, disabledIndices);
|
|
225
|
+
const maxIndex = (0, import_utils.getMaxListIndex)(listRef, disabledIndices);
|
|
226
|
+
if (!typeableComboboxReference) {
|
|
227
|
+
if (event.key === "Home") {
|
|
228
|
+
(0, import_utils.stopEvent)(event);
|
|
229
|
+
indexRef.current = minIndex;
|
|
230
|
+
onNavigate();
|
|
231
|
+
}
|
|
232
|
+
if (event.key === "End") {
|
|
233
|
+
(0, import_utils.stopEvent)(event);
|
|
234
|
+
indexRef.current = maxIndex;
|
|
235
|
+
onNavigate();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if (isMainOrientationKey(event.key, orientation)) {
|
|
239
|
+
(0, import_utils.stopEvent)(event);
|
|
240
|
+
if (open && !virtual && (0, import_utils.activeElement)(event.currentTarget.ownerDocument) === event.currentTarget) {
|
|
241
|
+
indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;
|
|
242
|
+
onNavigate();
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (isMainOrientationToEndKey(event.key, orientation, rtl)) {
|
|
246
|
+
if (loop) {
|
|
247
|
+
indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
248
|
+
startingIndex: currentIndex,
|
|
249
|
+
disabledIndices
|
|
250
|
+
});
|
|
251
|
+
} else {
|
|
252
|
+
indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
253
|
+
startingIndex: currentIndex,
|
|
254
|
+
disabledIndices
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
if (loop) {
|
|
259
|
+
indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
260
|
+
startingIndex: currentIndex,
|
|
261
|
+
decrement: true,
|
|
262
|
+
disabledIndices
|
|
263
|
+
});
|
|
264
|
+
} else {
|
|
265
|
+
indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
266
|
+
startingIndex: currentIndex,
|
|
267
|
+
decrement: true,
|
|
268
|
+
disabledIndices
|
|
269
|
+
}));
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if ((0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current)) {
|
|
273
|
+
indexRef.current = -1;
|
|
274
|
+
}
|
|
275
|
+
onNavigate();
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
const ariaActiveDescendantProp = (0, import_react.useMemo)(() => {
|
|
279
|
+
return virtual && open && hasActiveIndex && {
|
|
280
|
+
"aria-activedescendant": activeId
|
|
281
|
+
};
|
|
282
|
+
}, [virtual, open, hasActiveIndex, activeId]);
|
|
283
|
+
const floating = (0, import_react.useMemo)(() => {
|
|
284
|
+
return {
|
|
285
|
+
"aria-orientation": orientation === "both" ? void 0 : orientation,
|
|
286
|
+
...(!typeableComboboxReference ? ariaActiveDescendantProp : {}),
|
|
287
|
+
onKeyDown: commonOnKeyDown,
|
|
288
|
+
onPointerMove() {
|
|
289
|
+
isPointerModalityRef.current = true;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}, [ariaActiveDescendantProp, commonOnKeyDown, orientation, typeableComboboxReference]);
|
|
293
|
+
const reference = (0, import_react.useMemo)(() => {
|
|
294
|
+
function checkVirtualMouse(event) {
|
|
295
|
+
if (focusItemOnOpen === "auto" && (0, import_utils.isVirtualClick)(event.nativeEvent)) {
|
|
296
|
+
focusItemOnOpenRef.current = true;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
function checkVirtualPointer(event) {
|
|
300
|
+
focusItemOnOpenRef.current = focusItemOnOpen;
|
|
301
|
+
if (focusItemOnOpen === "auto" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent)) {
|
|
302
|
+
focusItemOnOpenRef.current = true;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
...ariaActiveDescendantProp,
|
|
307
|
+
onKeyDown(event) {
|
|
308
|
+
isPointerModalityRef.current = false;
|
|
309
|
+
const isArrowKey = event.key.startsWith("Arrow");
|
|
310
|
+
const isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl);
|
|
311
|
+
const isMainKey = isMainOrientationKey(event.key, orientation);
|
|
312
|
+
const isNavigationKey = (nested ? isCrossOpenKey : isMainKey) || event.key === "Enter" || event.key.trim() === "";
|
|
313
|
+
if (virtual && open) {
|
|
314
|
+
return commonOnKeyDown(event);
|
|
315
|
+
}
|
|
316
|
+
if (!open && !openOnArrowKeyDown && isArrowKey) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
if (isNavigationKey) {
|
|
320
|
+
keyRef.current = event.key;
|
|
321
|
+
}
|
|
322
|
+
if (nested) {
|
|
323
|
+
if (isCrossOpenKey) {
|
|
324
|
+
(0, import_utils.stopEvent)(event);
|
|
325
|
+
if (open) {
|
|
326
|
+
indexRef.current = (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current);
|
|
327
|
+
onNavigate();
|
|
328
|
+
} else {
|
|
329
|
+
onOpenChange(true, event.nativeEvent, "list-navigation");
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (isMainKey) {
|
|
335
|
+
if (selectedIndex != null) {
|
|
336
|
+
indexRef.current = selectedIndex;
|
|
337
|
+
}
|
|
338
|
+
(0, import_utils.stopEvent)(event);
|
|
339
|
+
if (!open && openOnArrowKeyDown) {
|
|
340
|
+
onOpenChange(true, event.nativeEvent, "list-navigation");
|
|
341
|
+
} else {
|
|
342
|
+
commonOnKeyDown(event);
|
|
343
|
+
}
|
|
344
|
+
if (open) {
|
|
345
|
+
onNavigate();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
onFocus() {
|
|
350
|
+
if (open && !virtual) {
|
|
351
|
+
indexRef.current = -1;
|
|
352
|
+
onNavigate();
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
onPointerDown: checkVirtualPointer,
|
|
356
|
+
onPointerEnter: checkVirtualPointer,
|
|
357
|
+
onMouseDown: checkVirtualMouse,
|
|
358
|
+
onClick: checkVirtualMouse
|
|
359
|
+
};
|
|
360
|
+
}, [ariaActiveDescendantProp, commonOnKeyDown, disabledIndicesRef, focusItemOnOpen, listRef, nested, onNavigate, onOpenChange, open, openOnArrowKeyDown, orientation, rtl, selectedIndex, virtual]);
|
|
361
|
+
const item = (0, import_react.useMemo)(() => {
|
|
362
|
+
function syncCurrentTarget(currentTarget) {
|
|
363
|
+
if (!latestOpenRef.current) return;
|
|
364
|
+
const index = listRef.current.indexOf(currentTarget);
|
|
365
|
+
if (index !== -1 && indexRef.current !== index) {
|
|
366
|
+
indexRef.current = index;
|
|
367
|
+
onNavigate();
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const itemProps = {
|
|
371
|
+
onFocus({
|
|
372
|
+
currentTarget
|
|
373
|
+
}) {
|
|
374
|
+
forceSyncFocusRef.current = true;
|
|
375
|
+
syncCurrentTarget(currentTarget);
|
|
376
|
+
},
|
|
377
|
+
onClick: ({
|
|
378
|
+
currentTarget
|
|
379
|
+
}) => currentTarget.focus({
|
|
380
|
+
preventScroll: true
|
|
381
|
+
}),
|
|
382
|
+
// safari
|
|
383
|
+
onMouseMove({
|
|
384
|
+
currentTarget
|
|
385
|
+
}) {
|
|
386
|
+
forceSyncFocusRef.current = true;
|
|
387
|
+
forceScrollIntoViewRef.current = false;
|
|
388
|
+
if (focusItemOnHover) {
|
|
389
|
+
syncCurrentTarget(currentTarget);
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
onPointerLeave({
|
|
393
|
+
pointerType
|
|
394
|
+
}) {
|
|
395
|
+
if (!isPointerModalityRef.current || pointerType === "touch") {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
forceSyncFocusRef.current = true;
|
|
399
|
+
if (!focusItemOnHover) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
indexRef.current = -1;
|
|
403
|
+
onNavigate();
|
|
404
|
+
if (!virtual) {
|
|
405
|
+
elements.floating?.focus({
|
|
406
|
+
preventScroll: true
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
return itemProps;
|
|
412
|
+
}, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
|
|
413
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
414
|
+
reference,
|
|
415
|
+
floating,
|
|
416
|
+
item
|
|
417
|
+
} : {}, [enabled, reference, floating, item]);
|
|
418
|
+
}
|