@tamagui/select 3.0.0-beta.924.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Select.cjs +23 -25
- package/dist/cjs/Select.native.cjs +27 -26
- package/dist/cjs/Select.native.js +27 -26
- package/dist/cjs/Select.native.js.map +1 -1
- package/dist/cjs/SelectImpl.cjs +67 -63
- package/dist/cjs/SelectItem.cjs +49 -60
- package/dist/cjs/SelectItem.native.cjs +51 -79
- package/dist/cjs/SelectItem.native.js +51 -79
- package/dist/cjs/SelectItem.native.js.map +1 -1
- package/dist/cjs/SelectScrollButton.cjs +9 -25
- package/dist/cjs/SelectTrigger.cjs +22 -5
- package/dist/cjs/SelectTrigger.native.cjs +15 -5
- package/dist/cjs/SelectTrigger.native.js +15 -5
- package/dist/cjs/SelectTrigger.native.js.map +1 -1
- package/dist/cjs/SelectViewport.cjs +29 -32
- package/dist/cjs/SelectViewport.native.cjs +2 -2
- package/dist/cjs/SelectViewport.native.js +2 -2
- package/dist/cjs/SelectViewport.native.js.map +1 -1
- package/dist/cjs/selectionController.cjs +15 -5
- package/dist/cjs/selectionController.native.cjs +20 -15
- package/dist/cjs/selectionController.native.js +20 -15
- package/dist/cjs/selectionController.native.js.map +1 -1
- package/dist/esm/Select.mjs +27 -28
- package/dist/esm/Select.mjs.map +1 -1
- package/dist/esm/Select.native.js +31 -29
- package/dist/esm/Select.native.js.map +1 -1
- package/dist/esm/SelectImpl.mjs +68 -64
- package/dist/esm/SelectImpl.mjs.map +1 -1
- package/dist/esm/SelectItem.mjs +50 -61
- package/dist/esm/SelectItem.mjs.map +1 -1
- package/dist/esm/SelectItem.native.js +52 -80
- package/dist/esm/SelectItem.native.js.map +1 -1
- package/dist/esm/SelectScrollButton.mjs +10 -26
- package/dist/esm/SelectScrollButton.mjs.map +1 -1
- package/dist/esm/SelectTrigger.mjs +16 -5
- package/dist/esm/SelectTrigger.mjs.map +1 -1
- package/dist/esm/SelectTrigger.native.js +15 -4
- package/dist/esm/SelectTrigger.native.js.map +1 -1
- package/dist/esm/SelectViewport.mjs +30 -33
- package/dist/esm/SelectViewport.mjs.map +1 -1
- package/dist/esm/SelectViewport.native.js +3 -3
- package/dist/esm/SelectViewport.native.js.map +1 -1
- package/dist/esm/selectionController.mjs +15 -5
- package/dist/esm/selectionController.mjs.map +1 -1
- package/dist/esm/selectionController.native.js +20 -15
- package/dist/esm/selectionController.native.js.map +1 -1
- package/dist/jsx/Select.mjs +27 -28
- package/dist/jsx/Select.mjs.map +1 -1
- package/dist/jsx/Select.native.cjs +27 -26
- package/dist/jsx/Select.native.js +27 -26
- package/dist/jsx/Select.native.js.map +1 -1
- package/dist/jsx/SelectImpl.mjs +68 -64
- package/dist/jsx/SelectImpl.mjs.map +1 -1
- package/dist/jsx/SelectItem.mjs +50 -61
- package/dist/jsx/SelectItem.mjs.map +1 -1
- package/dist/jsx/SelectItem.native.cjs +51 -79
- package/dist/jsx/SelectItem.native.js +51 -79
- package/dist/jsx/SelectItem.native.js.map +1 -1
- package/dist/jsx/SelectScrollButton.mjs +10 -26
- package/dist/jsx/SelectScrollButton.mjs.map +1 -1
- package/dist/jsx/SelectTrigger.mjs +16 -5
- package/dist/jsx/SelectTrigger.mjs.map +1 -1
- package/dist/jsx/SelectTrigger.native.cjs +15 -5
- package/dist/jsx/SelectTrigger.native.js +15 -5
- package/dist/jsx/SelectTrigger.native.js.map +1 -1
- package/dist/jsx/SelectViewport.mjs +30 -33
- package/dist/jsx/SelectViewport.mjs.map +1 -1
- package/dist/jsx/SelectViewport.native.cjs +2 -2
- package/dist/jsx/SelectViewport.native.js +2 -2
- package/dist/jsx/SelectViewport.native.js.map +1 -1
- package/dist/jsx/selectionController.mjs +15 -5
- package/dist/jsx/selectionController.mjs.map +1 -1
- package/dist/jsx/selectionController.native.cjs +20 -15
- package/dist/jsx/selectionController.native.js +20 -15
- package/dist/jsx/selectionController.native.js.map +1 -1
- package/package.json +30 -29
- package/src/Select.tsx +41 -41
- package/src/SelectImpl.tsx +107 -95
- package/src/SelectItem.tsx +66 -91
- package/src/SelectScrollButton.tsx +14 -32
- package/src/SelectTrigger.tsx +19 -2
- package/src/SelectViewport.native.tsx +4 -4
- package/src/SelectViewport.tsx +34 -30
- package/src/selectionController.ts +20 -5
- package/src/types.tsx +26 -22
- package/types/Select.d.ts +42 -81
- package/types/Select.d.ts.map +1 -1
- package/types/SelectImpl.d.ts.map +1 -1
- package/types/SelectItem.d.ts +3 -5
- package/types/SelectItem.d.ts.map +1 -1
- package/types/SelectItemText.d.ts +3 -5
- package/types/SelectItemText.d.ts.map +1 -1
- package/types/SelectScrollButton.d.ts +5 -9
- package/types/SelectScrollButton.d.ts.map +1 -1
- package/types/SelectScrollButton.native.d.ts +5 -9
- package/types/SelectScrollButton.native.d.ts.map +1 -1
- package/types/SelectTrigger.d.ts +3 -5
- package/types/SelectTrigger.d.ts.map +1 -1
- package/types/SelectViewport.d.ts +4 -9
- package/types/SelectViewport.d.ts.map +1 -1
- package/types/SelectViewport.native.d.ts +4 -9
- package/types/SelectViewport.native.d.ts.map +1 -1
- package/types/selectionController.d.ts +2 -0
- package/types/selectionController.d.ts.map +1 -1
- package/types/types.d.ts +30 -22
- package/types/types.d.ts.map +1 -1
package/dist/cjs/SelectImpl.cjs
CHANGED
|
@@ -32,7 +32,6 @@ var import_constants = require("@tamagui/constants");
|
|
|
32
32
|
var import_core = require("@tamagui/core");
|
|
33
33
|
var import_helpers = require("@tamagui/helpers");
|
|
34
34
|
var React = __toESM(require("react"), 1);
|
|
35
|
-
var import_react_dom = require("react-dom");
|
|
36
35
|
var import_constants2 = require("./constants.cjs");
|
|
37
36
|
var import_context = require("./context.cjs");
|
|
38
37
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
@@ -41,8 +40,7 @@ const SelectInlineImpl = (props) => {
|
|
|
41
40
|
const selectContext = (0, import_context.useSelectContext)(scope);
|
|
42
41
|
const selectItemParentContext = (0, import_context.useSelectItemParentContext)(scope);
|
|
43
42
|
const { setActiveIndex, selectedIndex, activeIndexRef } = selectContext;
|
|
44
|
-
const { requestOpenChange, registry } = selectItemParentContext;
|
|
45
|
-
const [scrollTop, setScrollTop] = React.useState(0);
|
|
43
|
+
const { requestOpenChange, registry, lastPointerRef } = selectItemParentContext;
|
|
46
44
|
const touch = (0, import_core.useIsTouchDevice)();
|
|
47
45
|
const listItemsRef = selectItemParentContext.listRef;
|
|
48
46
|
const overflowRef = React.useRef(null);
|
|
@@ -58,12 +56,11 @@ const SelectInlineImpl = (props) => {
|
|
|
58
56
|
});
|
|
59
57
|
const [controlledScrolling, setControlledScrolling] = React.useState(false);
|
|
60
58
|
const [fallback, setFallback] = React.useState(false);
|
|
61
|
-
const [innerOffset, setInnerOffset] = React.useState(0);
|
|
62
59
|
const [blockSelection, setBlockSelection] = React.useState(false);
|
|
63
|
-
const floatingStyle = React.useRef({});
|
|
64
60
|
React.useEffect(() => {
|
|
65
61
|
if (!open) {
|
|
66
|
-
|
|
62
|
+
setCanScrollUp(false);
|
|
63
|
+
setCanScrollDown(false);
|
|
67
64
|
setFallback(false);
|
|
68
65
|
setControlledScrolling(false);
|
|
69
66
|
}
|
|
@@ -81,33 +78,38 @@ const SelectInlineImpl = (props) => {
|
|
|
81
78
|
const { x, y, strategy, refs, update, placement: computedPlacement } = (0, import_floating.useFloatingRaw)({
|
|
82
79
|
open,
|
|
83
80
|
placement: "bottom-start",
|
|
84
|
-
whileElementsMounted: import_floating.autoUpdate,
|
|
85
81
|
middleware: [
|
|
86
|
-
(0, import_floating.size)({ apply({ rects
|
|
87
|
-
|
|
88
|
-
if (refs.floating.current) Object.assign(refs.floating.current.style, floatingStyle.current);
|
|
82
|
+
(0, import_floating.size)({ apply({ rects, elements }) {
|
|
83
|
+
elements.floating.style.minWidth = `${rects.reference.width + 8}px`;
|
|
89
84
|
} }),
|
|
90
85
|
(0, import_floating.inner)({
|
|
91
86
|
listRef: listItemsRef,
|
|
92
87
|
overflowRef,
|
|
93
88
|
index: selectedIndex,
|
|
94
|
-
offset: innerOffset,
|
|
95
89
|
onFallbackChange: setFallback,
|
|
96
|
-
padding
|
|
90
|
+
get padding() {
|
|
91
|
+
return 10 + Math.max(upArrowRef.current?.offsetHeight ?? 0, downArrowRef.current?.offsetHeight ?? 0);
|
|
92
|
+
},
|
|
97
93
|
minItemsVisible: touch ? 10 : 4,
|
|
98
94
|
referenceOverflowThreshold: 20
|
|
99
95
|
}),
|
|
100
|
-
(0, import_floating.offset)({ crossAxis: -
|
|
96
|
+
(0, import_floating.offset)({ crossAxis: -4 })
|
|
101
97
|
]
|
|
102
98
|
});
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
99
|
+
const [canScrollUp, setCanScrollUp] = React.useState(false);
|
|
100
|
+
const [canScrollDown, setCanScrollDown] = React.useState(false);
|
|
101
|
+
const updateScrollArrows = React.useCallback(() => {
|
|
102
|
+
const el = refs.floating.current;
|
|
103
|
+
if (!el) return;
|
|
104
|
+
setCanScrollUp(el.scrollTop > import_constants2.SCROLL_ARROW_THRESHOLD);
|
|
105
|
+
setCanScrollDown(el.scrollTop < el.scrollHeight - el.clientHeight - import_constants2.SCROLL_ARROW_THRESHOLD);
|
|
106
|
+
}, [refs]);
|
|
107
|
+
const showUpArrow = open && canScrollUp;
|
|
108
|
+
const showDownArrow = open && canScrollDown;
|
|
107
109
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
108
|
-
if (
|
|
110
|
+
if (!open) return;
|
|
111
|
+
update();
|
|
109
112
|
window.addEventListener("resize", update);
|
|
110
|
-
if (open) update();
|
|
111
113
|
return () => window.removeEventListener("resize", update);
|
|
112
114
|
}, [update, open]);
|
|
113
115
|
const onMatch = (0, import_core.useEvent)((index) => {
|
|
@@ -121,38 +123,41 @@ const SelectInlineImpl = (props) => {
|
|
|
121
123
|
});
|
|
122
124
|
const dataRef = React.useRef({});
|
|
123
125
|
dataRef.current.placement = computedPlacement;
|
|
124
|
-
const
|
|
126
|
+
const onOpenChange = (0, import_core.useEvent)((nextOpen, event, reason) => {
|
|
127
|
+
requestOpenChange(nextOpen, (0, import_core.createChangeEventDetails)(reason === "list-navigation" ? "keyboard" : "trigger-press", event, refs.reference.current));
|
|
128
|
+
});
|
|
129
|
+
const referenceElement = refs.reference.current || null;
|
|
130
|
+
const floatingElement = refs.floating.current || null;
|
|
131
|
+
const interactionContext = React.useMemo(() => ({
|
|
125
132
|
open,
|
|
126
|
-
onOpenChange
|
|
127
|
-
requestOpenChange(nextOpen, (0, import_core.createChangeEventDetails)(reason === "list-navigation" ? "keyboard" : "trigger-press", event, refs.reference.current));
|
|
128
|
-
},
|
|
133
|
+
onOpenChange,
|
|
129
134
|
refs: {
|
|
130
135
|
reference: refs.reference,
|
|
131
136
|
floating: refs.floating,
|
|
132
137
|
domReference: refs.reference
|
|
133
138
|
},
|
|
134
139
|
elements: {
|
|
135
|
-
reference:
|
|
136
|
-
floating:
|
|
137
|
-
domReference:
|
|
140
|
+
reference: referenceElement,
|
|
141
|
+
floating: floatingElement,
|
|
142
|
+
domReference: referenceElement
|
|
138
143
|
},
|
|
139
144
|
dataRef
|
|
140
|
-
}
|
|
145
|
+
}), [
|
|
146
|
+
open,
|
|
147
|
+
onOpenChange,
|
|
148
|
+
refs,
|
|
149
|
+
referenceElement,
|
|
150
|
+
floatingElement
|
|
151
|
+
]);
|
|
141
152
|
const interactionsProps = [
|
|
142
153
|
(0, import_floating.useClick)(interactionContext, {
|
|
143
154
|
event: "mousedown",
|
|
144
155
|
keyboardHandlers: false
|
|
145
156
|
}),
|
|
146
157
|
(0, import_floating.useRole)(interactionContext, { role: "listbox" }),
|
|
147
|
-
(0, import_floating.useInnerOffset)(interactionContext, {
|
|
148
|
-
enabled: !fallback && isScrollable,
|
|
149
|
-
onChange: setInnerOffset,
|
|
150
|
-
overflowRef,
|
|
151
|
-
scrollRef: refs.floating
|
|
152
|
-
}),
|
|
153
158
|
(0, import_floating.useListNavigation)(interactionContext, {
|
|
154
159
|
listRef: listItemsRef,
|
|
155
|
-
activeIndex:
|
|
160
|
+
activeIndex: null,
|
|
156
161
|
selectedIndex,
|
|
157
162
|
onNavigate: (index) => {
|
|
158
163
|
if (index !== null) setActiveIndex(index, {
|
|
@@ -163,13 +168,14 @@ const SelectInlineImpl = (props) => {
|
|
|
163
168
|
});
|
|
164
169
|
},
|
|
165
170
|
disabledIndices: registry.getDisabledIndices(),
|
|
166
|
-
scrollItemIntoView: false
|
|
171
|
+
scrollItemIntoView: false,
|
|
172
|
+
focusItemOnHover: false
|
|
167
173
|
}),
|
|
168
174
|
(0, import_floating.useTypeahead)(interactionContext, {
|
|
169
175
|
listRef: listContentRef,
|
|
170
176
|
onMatch,
|
|
171
177
|
selectedIndex,
|
|
172
|
-
activeIndex:
|
|
178
|
+
activeIndex: null,
|
|
173
179
|
onTypingChange: (e) => {
|
|
174
180
|
state.current.isTyping = e;
|
|
175
181
|
}
|
|
@@ -180,10 +186,14 @@ const SelectInlineImpl = (props) => {
|
|
|
180
186
|
}, interactionsProps));
|
|
181
187
|
const interactionsContext = React.useMemo(() => {
|
|
182
188
|
return {
|
|
183
|
-
...interactions,
|
|
184
189
|
getReferenceProps(props2 = {}) {
|
|
185
190
|
return interactions.getReferenceProps({
|
|
186
191
|
...props2,
|
|
192
|
+
onMouseDown: (0, import_helpers.composeEventHandlers)(props2.onMouseDown, (event) => {
|
|
193
|
+
const last = lastPointerRef.current;
|
|
194
|
+
last.x = event.clientX;
|
|
195
|
+
last.y = event.clientY;
|
|
196
|
+
}),
|
|
187
197
|
onKeyDown: (0, import_helpers.composeEventHandlers)(props2.onKeyDown, (event) => {
|
|
188
198
|
latestKeyboardEventRef.current = event.nativeEvent || event;
|
|
189
199
|
if (event.key === "Enter" || event.code === "Space" || event.key === " " && !state.current.isTyping) {
|
|
@@ -196,17 +206,7 @@ const SelectInlineImpl = (props) => {
|
|
|
196
206
|
getFloatingProps(props2) {
|
|
197
207
|
return interactions.getFloatingProps({
|
|
198
208
|
ref: refs.floating,
|
|
199
|
-
className: "Select",
|
|
200
209
|
...props2,
|
|
201
|
-
style: {
|
|
202
|
-
position: strategy,
|
|
203
|
-
top: y ?? "",
|
|
204
|
-
left: x ?? "",
|
|
205
|
-
outline: 0,
|
|
206
|
-
scrollbarWidth: "none",
|
|
207
|
-
...floatingStyle.current,
|
|
208
|
-
...props2?.style
|
|
209
|
-
},
|
|
210
210
|
onPointerEnter() {
|
|
211
211
|
setControlledScrolling(false);
|
|
212
212
|
state.current.isMouseOutside = false;
|
|
@@ -225,20 +225,24 @@ const SelectInlineImpl = (props) => {
|
|
|
225
225
|
onContextMenu(e) {
|
|
226
226
|
e.preventDefault();
|
|
227
227
|
},
|
|
228
|
-
onScroll
|
|
229
|
-
(0, import_react_dom.flushSync)(() => {
|
|
230
|
-
setScrollTop(event.currentTarget.scrollTop);
|
|
231
|
-
});
|
|
232
|
-
}
|
|
228
|
+
onScroll: updateScrollArrows
|
|
233
229
|
});
|
|
234
230
|
}
|
|
235
231
|
};
|
|
236
232
|
}, [
|
|
237
|
-
refs
|
|
233
|
+
refs,
|
|
234
|
+
interactions,
|
|
235
|
+
requestOpenChange,
|
|
236
|
+
updateScrollArrows
|
|
237
|
+
]);
|
|
238
|
+
const floatingPosition = React.useMemo(() => ({
|
|
239
|
+
position: strategy,
|
|
240
|
+
top: y ?? "",
|
|
241
|
+
left: x ?? ""
|
|
242
|
+
}), [
|
|
243
|
+
strategy,
|
|
238
244
|
x,
|
|
239
|
-
y
|
|
240
|
-
refs.floating.current,
|
|
241
|
-
interactions
|
|
245
|
+
y
|
|
242
246
|
]);
|
|
243
247
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
244
248
|
if (open) {
|
|
@@ -253,7 +257,6 @@ const SelectInlineImpl = (props) => {
|
|
|
253
257
|
}
|
|
254
258
|
allowSelectRef.current = false;
|
|
255
259
|
allowMouseUpRef.current = true;
|
|
256
|
-
setInnerOffset(0);
|
|
257
260
|
setFallback(false);
|
|
258
261
|
setBlockSelection(false);
|
|
259
262
|
}, [open]);
|
|
@@ -264,15 +267,15 @@ const SelectInlineImpl = (props) => {
|
|
|
264
267
|
if (!open) return;
|
|
265
268
|
const scrollActiveIntoView = (index) => {
|
|
266
269
|
if (controlledScrolling && index != null) listItemsRef.current[index]?.scrollIntoView({ block: "nearest" });
|
|
267
|
-
|
|
270
|
+
updateScrollArrows();
|
|
268
271
|
};
|
|
269
272
|
scrollActiveIntoView(activeIndexRef.current);
|
|
270
273
|
return selectItemParentContext.activeIndexSubscribe(scrollActiveIntoView);
|
|
271
274
|
}, [
|
|
272
275
|
open,
|
|
273
|
-
refs,
|
|
274
276
|
controlledScrolling,
|
|
275
|
-
selectItemParentContext.activeIndexSubscribe
|
|
277
|
+
selectItemParentContext.activeIndexSubscribe,
|
|
278
|
+
updateScrollArrows
|
|
276
279
|
]);
|
|
277
280
|
React.useEffect(() => {
|
|
278
281
|
if (open && fallback) {
|
|
@@ -293,10 +296,11 @@ const SelectInlineImpl = (props) => {
|
|
|
293
296
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_context.SelectProvider, {
|
|
294
297
|
scope,
|
|
295
298
|
...selectContext,
|
|
296
|
-
|
|
297
|
-
setInnerOffset,
|
|
299
|
+
updateScrollArrows,
|
|
298
300
|
fallback,
|
|
299
301
|
floatingContext,
|
|
302
|
+
interactions: interactionsContext,
|
|
303
|
+
floatingPosition,
|
|
300
304
|
canScrollDown: !!showDownArrow,
|
|
301
305
|
canScrollUp: !!showUpArrow,
|
|
302
306
|
controlledScrolling,
|
|
@@ -310,7 +314,7 @@ const SelectInlineImpl = (props) => {
|
|
|
310
314
|
allowMouseUpRef,
|
|
311
315
|
allowSelectRef,
|
|
312
316
|
dataRef,
|
|
313
|
-
|
|
317
|
+
getItemProps: interactions.getItemProps,
|
|
314
318
|
listRef: listItemsRef,
|
|
315
319
|
selectTimeoutRef,
|
|
316
320
|
children
|
package/dist/cjs/SelectItem.cjs
CHANGED
|
@@ -52,34 +52,22 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
52
52
|
const { scope, value, disabled: disabledProp, "aria-disabled": ariaDisabled, textValue: textValueProp, ...restProps } = props;
|
|
53
53
|
const disabled = disabledProp ?? ariaDisabled === true;
|
|
54
54
|
const context = (0, import_context.useSelectItemParentContext)(scope);
|
|
55
|
-
const
|
|
56
|
-
const
|
|
57
|
-
const { listRef, registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, interactions, shouldRenderWebNative, setActiveIndexFast, moveActive, search } = context;
|
|
55
|
+
const isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
|
|
56
|
+
const { registry, mode, selectedValues, selectValue, activeIndexSubscribe, activeIndexRef, allowMouseUpRef, allowSelectRef, selectTimeoutRef, getItemProps, shouldRenderWebNative, setActiveIndex, lastPointerRef, moveActive, search } = context;
|
|
58
57
|
const isSelected = selectedValues.includes(value);
|
|
59
58
|
const pendingMouseUpSelectionRef = React.useRef(false);
|
|
60
59
|
const itemNodeRef = React.useRef(null);
|
|
61
|
-
const [, rerenderRegistry] = React.useReducer((version) => version + 1, 0);
|
|
62
60
|
const registrationRef = React.useRef(null);
|
|
63
61
|
const initialRegistration = React.useRef({
|
|
64
62
|
value,
|
|
65
63
|
disabled,
|
|
66
64
|
textValue: textValueProp
|
|
67
65
|
});
|
|
68
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => registry.subscribe(() => rerenderRegistry()), [registry]);
|
|
69
66
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
70
67
|
const registration = registry.registerItem(initialRegistration.current);
|
|
71
68
|
registrationRef.current = registration;
|
|
72
|
-
|
|
73
|
-
registration.setNode(registeredNode);
|
|
74
|
-
const registeredIndex = registry.getItems().findIndex((item) => item.id === registration.id);
|
|
75
|
-
if (import_constants.isWeb && listRef && registeredIndex >= 0 && registeredNode instanceof HTMLElement) {
|
|
76
|
-
listRef.current[registeredIndex] = registeredNode;
|
|
77
|
-
}
|
|
69
|
+
registration.setNode(itemNodeRef.current);
|
|
78
70
|
return () => {
|
|
79
|
-
const currentIndex = registry.getItems().findIndex((item) => item.id === registration.id);
|
|
80
|
-
if (listRef && currentIndex >= 0 && listRef.current[currentIndex] === registeredNode) {
|
|
81
|
-
listRef.current[currentIndex] = null;
|
|
82
|
-
}
|
|
83
71
|
registrationRef.current = null;
|
|
84
72
|
registration.unregister();
|
|
85
73
|
};
|
|
@@ -98,37 +86,34 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
98
86
|
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
99
87
|
registrationRef.current?.setNode(itemNodeRef.current);
|
|
100
88
|
});
|
|
101
|
-
const
|
|
89
|
+
const [isActive, setIsActive] = React.useState(false);
|
|
90
|
+
const isActiveRef = React.useRef(false);
|
|
102
91
|
React.useEffect(() => {
|
|
103
92
|
const handleActiveIndex = (i) => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
const next = i != null && registry.getIndex(value) === i;
|
|
94
|
+
if (next !== isActiveRef.current) {
|
|
95
|
+
isActiveRef.current = next;
|
|
96
|
+
setIsActive(next);
|
|
97
|
+
}
|
|
98
|
+
if (next && import_constants.isWeb) {
|
|
99
|
+
requestAnimationFrame(() => {
|
|
100
|
+
itemNodeRef.current?.focus?.();
|
|
101
|
+
});
|
|
110
102
|
}
|
|
111
103
|
};
|
|
112
|
-
|
|
113
|
-
if (currentActiveIndex !== null && currentActiveIndex !== void 0) {
|
|
114
|
-
handleActiveIndex(currentActiveIndex);
|
|
115
|
-
}
|
|
104
|
+
handleActiveIndex(activeIndexRef?.current ?? null);
|
|
116
105
|
return activeIndexSubscribe(handleActiveIndex);
|
|
117
106
|
}, [
|
|
118
107
|
activeIndexRef,
|
|
119
108
|
activeIndexSubscribe,
|
|
120
|
-
|
|
121
|
-
|
|
109
|
+
registry,
|
|
110
|
+
value
|
|
122
111
|
]);
|
|
123
112
|
const textId = React.useId();
|
|
124
113
|
const refCallback = React.useCallback((node) => {
|
|
125
114
|
itemNodeRef.current = node;
|
|
126
115
|
registrationRef.current?.setNode(node);
|
|
127
|
-
|
|
128
|
-
if (listRef && index >= 0) {
|
|
129
|
-
listRef.current[index] = node instanceof HTMLElement ? node : null;
|
|
130
|
-
}
|
|
131
|
-
}, [index, listRef]);
|
|
116
|
+
}, []);
|
|
132
117
|
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, refCallback);
|
|
133
118
|
const handleSelect = React.useCallback((event, reason = "item-press") => {
|
|
134
119
|
if (disabled) return;
|
|
@@ -139,6 +124,27 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
139
124
|
selectValue,
|
|
140
125
|
value
|
|
141
126
|
]);
|
|
127
|
+
const handleMouseMove = React.useCallback((event) => {
|
|
128
|
+
if (disabled) return;
|
|
129
|
+
const index = registry.getIndex(value);
|
|
130
|
+
if (index < 0) return;
|
|
131
|
+
const last = lastPointerRef.current;
|
|
132
|
+
if (event.clientX === last.x && event.clientY === last.y) return;
|
|
133
|
+
last.x = event.clientX;
|
|
134
|
+
last.y = event.clientY;
|
|
135
|
+
setActiveIndex(index, {
|
|
136
|
+
reason: "item-hover",
|
|
137
|
+
event: event.nativeEvent || event,
|
|
138
|
+
trigger: event.currentTarget,
|
|
139
|
+
index
|
|
140
|
+
});
|
|
141
|
+
}, [
|
|
142
|
+
disabled,
|
|
143
|
+
lastPointerRef,
|
|
144
|
+
registry,
|
|
145
|
+
setActiveIndex,
|
|
146
|
+
value
|
|
147
|
+
]);
|
|
142
148
|
const handleKeyDown = React.useCallback((event) => {
|
|
143
149
|
if (disabled) return;
|
|
144
150
|
if (event.key === "Enter" || event.key === " ") {
|
|
@@ -152,7 +158,7 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
152
158
|
moveActive(event.key === "ArrowDown" ? 1 : -1, event.nativeEvent || event);
|
|
153
159
|
return;
|
|
154
160
|
}
|
|
155
|
-
if (!
|
|
161
|
+
if (!getItemProps && event.key?.length === 1 && !event.metaKey && !event.ctrlKey) {
|
|
156
162
|
search(event.key, event.nativeEvent || event);
|
|
157
163
|
}
|
|
158
164
|
if (allowSelectRef) {
|
|
@@ -162,14 +168,14 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
162
168
|
allowSelectRef,
|
|
163
169
|
disabled,
|
|
164
170
|
handleSelect,
|
|
165
|
-
|
|
171
|
+
getItemProps,
|
|
166
172
|
moveActive,
|
|
167
173
|
search
|
|
168
174
|
]);
|
|
169
175
|
const selectItemProps = React.useMemo(() => {
|
|
170
|
-
if (
|
|
176
|
+
if (getItemProps) {
|
|
171
177
|
const { onTouchMove, onTouchEnd, onKeyDown, onClick, onMouseUp, onMouseMove, onPress, ...itemProps } = restProps;
|
|
172
|
-
const interactionProps =
|
|
178
|
+
const interactionProps = getItemProps({
|
|
173
179
|
...itemProps,
|
|
174
180
|
onTouchMove() {
|
|
175
181
|
allowSelectRef.current = true;
|
|
@@ -179,15 +185,7 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
179
185
|
allowSelectRef.current = false;
|
|
180
186
|
allowMouseUpRef.current = true;
|
|
181
187
|
},
|
|
182
|
-
onMouseMove
|
|
183
|
-
if (disabled || index < 0) return;
|
|
184
|
-
setActiveIndexFast?.(index, {
|
|
185
|
-
reason: "item-hover",
|
|
186
|
-
event: event.nativeEvent || event,
|
|
187
|
-
trigger: event.currentTarget,
|
|
188
|
-
index
|
|
189
|
-
});
|
|
190
|
-
},
|
|
188
|
+
onMouseMove: handleMouseMove,
|
|
191
189
|
onKeyDown: handleKeyDown,
|
|
192
190
|
onClick(event) {
|
|
193
191
|
if (disabled) return;
|
|
@@ -240,15 +238,7 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
240
238
|
return {
|
|
241
239
|
...restProps,
|
|
242
240
|
onKeyDown: (0, import_helpers.composeEventHandlers)(restProps.onKeyDown, handleKeyDown),
|
|
243
|
-
onMouseMove: (0, import_helpers.composeEventHandlers)(restProps.onMouseMove,
|
|
244
|
-
if (disabled || index < 0) return;
|
|
245
|
-
setActiveIndexFast?.(index, {
|
|
246
|
-
reason: "item-hover",
|
|
247
|
-
event: event.nativeEvent || event,
|
|
248
|
-
trigger: event.currentTarget,
|
|
249
|
-
index
|
|
250
|
-
});
|
|
251
|
-
}),
|
|
241
|
+
onMouseMove: (0, import_helpers.composeEventHandlers)(restProps.onMouseMove, handleMouseMove),
|
|
252
242
|
onPress: (0, import_helpers.composeEventHandlers)(restProps.onPress, handleSelect)
|
|
253
243
|
};
|
|
254
244
|
}, [
|
|
@@ -256,12 +246,11 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
256
246
|
allowSelectRef,
|
|
257
247
|
disabled,
|
|
258
248
|
handleKeyDown,
|
|
249
|
+
handleMouseMove,
|
|
259
250
|
handleSelect,
|
|
260
|
-
|
|
261
|
-
interactions,
|
|
251
|
+
getItemProps,
|
|
262
252
|
restProps,
|
|
263
|
-
selectTimeoutRef
|
|
264
|
-
setActiveIndexFast
|
|
253
|
+
selectTimeoutRef
|
|
265
254
|
]);
|
|
266
255
|
const accessibilityProps = (0, import_selectionController.getSelectOptionProps)(mode, isSelected, disabled, import_constants.isWeb ? "web" : "native");
|
|
267
256
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SelectItemContextProvider, {
|
|
@@ -280,7 +269,7 @@ const SelectItem = (0, import_core.createStyledHOC)(SelectItemFrame, function Se
|
|
|
280
269
|
"aria-labelledby": textId,
|
|
281
270
|
"data-state": isSelected ? "active" : "inactive",
|
|
282
271
|
"data-disabled": disabled ? "" : void 0,
|
|
283
|
-
tabIndex: disabled ? void 0 : import_constants.isWeb && isAdapted
|
|
272
|
+
tabIndex: disabled ? void 0 : import_constants.isWeb && isAdapted && (isActive || activeIndexRef?.current == null && isSelected) ? 0 : -1,
|
|
284
273
|
zIndex: 100,
|
|
285
274
|
...selectItemProps,
|
|
286
275
|
...accessibilityProps
|