@radix-ui/react-select 2.4.0-rc.1791509415276 → 2.4.0-rc.1791763750187
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/index.js +47 -27
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +47 -27
- package/dist/index.mjs.map +2 -2
- package/package.json +18 -18
package/dist/index.js
CHANGED
|
@@ -155,10 +155,14 @@ function SelectProvider(props) {
|
|
|
155
155
|
});
|
|
156
156
|
const triggerPointerDownPosRef = React.useRef(null);
|
|
157
157
|
const hasConsumerStoppedPropagationRef = React.useRef(false);
|
|
158
|
-
const [
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
158
|
+
const [userSelection, setUserSelection] = React.useState(null);
|
|
159
|
+
const handleUserSelect = /* @__PURE__ */ __name((nextValue) => {
|
|
160
|
+
setUserSelection({
|
|
161
|
+
value: nextValue,
|
|
162
|
+
hasConsumerStoppedPropagation: hasConsumerStoppedPropagationRef.current
|
|
163
|
+
});
|
|
164
|
+
setValue(nextValue);
|
|
165
|
+
}, "handleUserSelect");
|
|
162
166
|
const initialValueRef = React.useRef(value);
|
|
163
167
|
React.useEffect(() => {
|
|
164
168
|
const associatedForm = form ? trigger?.ownerDocument.getElementById(form) : trigger?.form;
|
|
@@ -194,8 +198,8 @@ function SelectProvider(props) {
|
|
|
194
198
|
value,
|
|
195
199
|
onValueChange: setValue,
|
|
196
200
|
hasConsumerStoppedPropagationRef,
|
|
197
|
-
|
|
198
|
-
|
|
201
|
+
userSelection,
|
|
202
|
+
onUserSelect: handleUserSelect,
|
|
199
203
|
open,
|
|
200
204
|
onOpenChange: setOpen,
|
|
201
205
|
dir: direction,
|
|
@@ -253,8 +257,7 @@ var SelectTrigger = /* @__PURE__ */ React.forwardRef(
|
|
|
253
257
|
const currentItem = enabledItems.find((item) => item.value === context.value);
|
|
254
258
|
const nextItem = findNextItem(enabledItems, search, currentItem);
|
|
255
259
|
if (nextItem !== void 0) {
|
|
256
|
-
context.
|
|
257
|
-
context.onValueChange(nextItem.value);
|
|
260
|
+
context.onUserSelect(nextItem.value);
|
|
258
261
|
}
|
|
259
262
|
});
|
|
260
263
|
const handleOpen = /* @__PURE__ */ __name((pointerEvent) => {
|
|
@@ -416,6 +419,8 @@ var SelectContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
416
419
|
const getItems = useCollection(__scopeSelect);
|
|
417
420
|
const [isPositioned, setIsPositioned] = React.useState(false);
|
|
418
421
|
const firstValidItemFoundRef = React.useRef(false);
|
|
422
|
+
const firstItemFoundRef = React.useRef(false);
|
|
423
|
+
const firstItemTextFoundRef = React.useRef(false);
|
|
419
424
|
React.useEffect(() => {
|
|
420
425
|
if (content) return (0, import_aria_hidden.hideOthers)(content);
|
|
421
426
|
}, [content]);
|
|
@@ -495,11 +500,15 @@ var SelectContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
495
500
|
});
|
|
496
501
|
const itemRefCallback = React.useCallback(
|
|
497
502
|
(node, value, disabled) => {
|
|
503
|
+
const isFirstItem = !firstItemFoundRef.current;
|
|
504
|
+
if (isFirstItem) firstItemFoundRef.current = true;
|
|
498
505
|
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
499
506
|
const isSelectedItem = context.value !== void 0 && context.value === value;
|
|
500
507
|
if (isSelectedItem || isFirstValidItem) {
|
|
501
508
|
setSelectedItem(node);
|
|
502
509
|
if (isFirstValidItem) firstValidItemFoundRef.current = true;
|
|
510
|
+
} else if (isFirstItem) {
|
|
511
|
+
setSelectedItem(node);
|
|
503
512
|
}
|
|
504
513
|
},
|
|
505
514
|
[context.value]
|
|
@@ -507,10 +516,15 @@ var SelectContentImpl = /* @__PURE__ */ React.forwardRef(
|
|
|
507
516
|
const handleItemLeave = React.useCallback(() => content?.focus(), [content]);
|
|
508
517
|
const itemTextRefCallback = React.useCallback(
|
|
509
518
|
(node, value, disabled) => {
|
|
519
|
+
if (!node) return;
|
|
520
|
+
const isFirstItem = !firstItemTextFoundRef.current;
|
|
521
|
+
if (isFirstItem) firstItemTextFoundRef.current = true;
|
|
510
522
|
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
511
523
|
const isSelectedItem = context.value !== void 0 && context.value === value;
|
|
512
524
|
if (isSelectedItem || isFirstValidItem) {
|
|
513
525
|
setSelectedItemText(node);
|
|
526
|
+
} else if (isFirstItem) {
|
|
527
|
+
setSelectedItemText(node);
|
|
514
528
|
}
|
|
515
529
|
},
|
|
516
530
|
[context.value]
|
|
@@ -917,8 +931,7 @@ var SelectItem = /* @__PURE__ */ React.forwardRef(
|
|
|
917
931
|
const pointerTypeRef = React.useRef("touch");
|
|
918
932
|
function handleSelect(event) {
|
|
919
933
|
context.hasConsumerStoppedPropagationRef.current = event.isPropagationStopped();
|
|
920
|
-
context.
|
|
921
|
-
context.onValueChange(value);
|
|
934
|
+
context.onUserSelect(value);
|
|
922
935
|
context.onOpenChange(false);
|
|
923
936
|
}
|
|
924
937
|
__name(handleSelect, "handleSelect");
|
|
@@ -1185,23 +1198,14 @@ var SelectBubbleInput = /* @__PURE__ */ React.forwardRef(
|
|
|
1185
1198
|
// blank line to reduce diff noise
|
|
1186
1199
|
/* @__PURE__ */ __name(function SelectBubbleInput2({ __scopeSelect, ...props }, forwardedRef) {
|
|
1187
1200
|
const context = useSelectContext(BUBBLE_INPUT_NAME, __scopeSelect);
|
|
1188
|
-
const {
|
|
1189
|
-
value,
|
|
1190
|
-
onValueChange,
|
|
1191
|
-
required,
|
|
1192
|
-
disabled,
|
|
1193
|
-
name,
|
|
1194
|
-
autoComplete,
|
|
1195
|
-
form,
|
|
1196
|
-
hasConsumerStoppedPropagationRef,
|
|
1197
|
-
userInteractionCount
|
|
1198
|
-
} = context;
|
|
1201
|
+
const { value, onValueChange, required, disabled, name, autoComplete, form, userSelection } = context;
|
|
1199
1202
|
const { nativeOptions, nativeSelectKey } = context;
|
|
1200
1203
|
const ref = React.useRef(null);
|
|
1201
1204
|
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
1202
1205
|
const selectValue = value ?? "";
|
|
1203
1206
|
const prevValueRef = React.useRef(selectValue);
|
|
1204
|
-
const
|
|
1207
|
+
const handledUserSelectionRef = React.useRef(userSelection);
|
|
1208
|
+
const isDispatchingUserSelectionRef = React.useRef(false);
|
|
1205
1209
|
const hasEmptyValueOption = Array.from(nativeOptions).some(
|
|
1206
1210
|
(option) => (option.props.value ?? "") === ""
|
|
1207
1211
|
);
|
|
@@ -1214,17 +1218,29 @@ var SelectBubbleInput = /* @__PURE__ */ React.forwardRef(
|
|
|
1214
1218
|
"value"
|
|
1215
1219
|
);
|
|
1216
1220
|
const setValue = descriptor.set;
|
|
1217
|
-
const
|
|
1218
|
-
|
|
1221
|
+
const isNewUserSelection = userSelection !== null && userSelection !== handledUserSelectionRef.current;
|
|
1222
|
+
handledUserSelectionRef.current = userSelection;
|
|
1219
1223
|
const valueChanged = prevValueRef.current !== selectValue;
|
|
1220
1224
|
prevValueRef.current = selectValue;
|
|
1221
|
-
const
|
|
1225
|
+
const isUserInteraction = isNewUserSelection && valueChanged;
|
|
1226
|
+
if (isNewUserSelection && !valueChanged && userSelection.value !== selectValue && !userSelection.hasConsumerStoppedPropagation && setValue) {
|
|
1227
|
+
isDispatchingUserSelectionRef.current = true;
|
|
1228
|
+
try {
|
|
1229
|
+
setValue.call(select, userSelection.value);
|
|
1230
|
+
select.dispatchEvent(new Event("change", { bubbles: true }));
|
|
1231
|
+
} finally {
|
|
1232
|
+
isDispatchingUserSelectionRef.current = false;
|
|
1233
|
+
setValue.call(select, selectValue);
|
|
1234
|
+
}
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
const bubbles = isUserInteraction && !userSelection.hasConsumerStoppedPropagation;
|
|
1222
1238
|
if (valueChanged && setValue) {
|
|
1223
1239
|
const event = new Event("change", { bubbles });
|
|
1224
1240
|
setValue.call(select, selectValue);
|
|
1225
1241
|
select.dispatchEvent(event);
|
|
1226
1242
|
}
|
|
1227
|
-
}, [
|
|
1243
|
+
}, [selectValue, userSelection]);
|
|
1228
1244
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
1229
1245
|
import_react_primitive.Primitive.select,
|
|
1230
1246
|
{
|
|
@@ -1235,7 +1251,11 @@ var SelectBubbleInput = /* @__PURE__ */ React.forwardRef(
|
|
|
1235
1251
|
autoComplete,
|
|
1236
1252
|
disabled,
|
|
1237
1253
|
form,
|
|
1238
|
-
onChange: (event) =>
|
|
1254
|
+
onChange: (event) => {
|
|
1255
|
+
if (!isDispatchingUserSelectionRef.current) {
|
|
1256
|
+
onValueChange(event.target.value);
|
|
1257
|
+
}
|
|
1258
|
+
},
|
|
1239
1259
|
...props,
|
|
1240
1260
|
style: { ...import_react_visually_hidden.VISUALLY_HIDDEN_STYLES, ...props.style },
|
|
1241
1261
|
ref: composedRefs,
|