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