@radix-ui/react-select 2.1.2-rc.2 → 2.1.2-rc.20
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +48 -14
- package/dist/index.js.map +2 -2
- package/dist/index.mjs +48 -14
- package/dist/index.mjs.map +2 -2
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -118,7 +118,8 @@ var Select = (props) => {
|
|
|
118
118
|
name,
|
|
119
119
|
autoComplete,
|
|
120
120
|
disabled,
|
|
121
|
-
required
|
|
121
|
+
required,
|
|
122
|
+
form
|
|
122
123
|
} = props;
|
|
123
124
|
const popperScope = usePopperScope(__scopeSelect);
|
|
124
125
|
const [trigger, setTrigger] = React.useState(null);
|
|
@@ -136,7 +137,7 @@ var Select = (props) => {
|
|
|
136
137
|
onChange: onValueChange
|
|
137
138
|
});
|
|
138
139
|
const triggerPointerDownPosRef = React.useRef(null);
|
|
139
|
-
const isFormControl = trigger ? Boolean(trigger.closest("form")) : true;
|
|
140
|
+
const isFormControl = trigger ? Boolean(trigger.closest("form")) || form : true;
|
|
140
141
|
const [nativeOptionsSet, setNativeOptionsSet] = React.useState(/* @__PURE__ */ new Set());
|
|
141
142
|
const nativeSelectKey = Array.from(nativeOptionsSet).map((option) => option.props.value).join(";");
|
|
142
143
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.Root, { ...popperScope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
@@ -187,6 +188,7 @@ var Select = (props) => {
|
|
|
187
188
|
value,
|
|
188
189
|
onChange: (event) => setValue(event.target.value),
|
|
189
190
|
disabled,
|
|
191
|
+
form,
|
|
190
192
|
children: [
|
|
191
193
|
value === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "" }) : null,
|
|
192
194
|
Array.from(nativeOptionsSet)
|
|
@@ -208,6 +210,7 @@ var SelectTrigger = React.forwardRef(
|
|
|
208
210
|
const isDisabled = context.disabled || disabled;
|
|
209
211
|
const composedRefs = (0, import_react_compose_refs.useComposedRefs)(forwardedRef, context.onTriggerChange);
|
|
210
212
|
const getItems = useCollection(__scopeSelect);
|
|
213
|
+
const pointerTypeRef = React.useRef("touch");
|
|
211
214
|
const [searchRef, handleTypeaheadSearch, resetTypeahead] = useTypeaheadSearch((search) => {
|
|
212
215
|
const enabledItems = getItems().filter((item) => !item.disabled);
|
|
213
216
|
const currentItem = enabledItems.find((item) => item.value === context.value);
|
|
@@ -216,11 +219,17 @@ var SelectTrigger = React.forwardRef(
|
|
|
216
219
|
context.onValueChange(nextItem.value);
|
|
217
220
|
}
|
|
218
221
|
});
|
|
219
|
-
const handleOpen = () => {
|
|
222
|
+
const handleOpen = (pointerEvent) => {
|
|
220
223
|
if (!isDisabled) {
|
|
221
224
|
context.onOpenChange(true);
|
|
222
225
|
resetTypeahead();
|
|
223
226
|
}
|
|
227
|
+
if (pointerEvent) {
|
|
228
|
+
context.triggerPointerDownPosRef.current = {
|
|
229
|
+
x: Math.round(pointerEvent.pageX),
|
|
230
|
+
y: Math.round(pointerEvent.pageY)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
224
233
|
};
|
|
225
234
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperPrimitive.Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
226
235
|
import_react_primitive.Primitive.button,
|
|
@@ -240,18 +249,18 @@ var SelectTrigger = React.forwardRef(
|
|
|
240
249
|
ref: composedRefs,
|
|
241
250
|
onClick: (0, import_primitive.composeEventHandlers)(triggerProps.onClick, (event) => {
|
|
242
251
|
event.currentTarget.focus();
|
|
252
|
+
if (pointerTypeRef.current !== "mouse") {
|
|
253
|
+
handleOpen(event);
|
|
254
|
+
}
|
|
243
255
|
}),
|
|
244
256
|
onPointerDown: (0, import_primitive.composeEventHandlers)(triggerProps.onPointerDown, (event) => {
|
|
257
|
+
pointerTypeRef.current = event.pointerType;
|
|
245
258
|
const target = event.target;
|
|
246
259
|
if (target.hasPointerCapture(event.pointerId)) {
|
|
247
260
|
target.releasePointerCapture(event.pointerId);
|
|
248
261
|
}
|
|
249
|
-
if (event.button === 0 && event.ctrlKey === false) {
|
|
250
|
-
handleOpen();
|
|
251
|
-
context.triggerPointerDownPosRef.current = {
|
|
252
|
-
x: Math.round(event.pageX),
|
|
253
|
-
y: Math.round(event.pageY)
|
|
254
|
-
};
|
|
262
|
+
if (event.button === 0 && event.ctrlKey === false && event.pointerType === "mouse") {
|
|
263
|
+
handleOpen(event);
|
|
255
264
|
event.preventDefault();
|
|
256
265
|
}
|
|
257
266
|
}),
|
|
@@ -586,7 +595,15 @@ var SelectItemAlignedPosition = React.forwardRef((props, forwardedRef) => {
|
|
|
586
595
|
const minContentWidth = triggerRect.width + leftDelta;
|
|
587
596
|
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
588
597
|
const rightEdge = window.innerWidth - CONTENT_MARGIN;
|
|
589
|
-
const clampedLeft = (0, import_number.clamp)(left, [
|
|
598
|
+
const clampedLeft = (0, import_number.clamp)(left, [
|
|
599
|
+
CONTENT_MARGIN,
|
|
600
|
+
// Prevents the content from going off the starting edge of the
|
|
601
|
+
// viewport. It may still go off the ending edge, but this can be
|
|
602
|
+
// controlled by the user since they may want to manage overflow in a
|
|
603
|
+
// specific way.
|
|
604
|
+
// https://github.com/radix-ui/primitives/issues/2049
|
|
605
|
+
Math.max(CONTENT_MARGIN, rightEdge - contentWidth)
|
|
606
|
+
]);
|
|
590
607
|
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
591
608
|
contentWrapper.style.left = clampedLeft + "px";
|
|
592
609
|
} else {
|
|
@@ -596,7 +613,10 @@ var SelectItemAlignedPosition = React.forwardRef((props, forwardedRef) => {
|
|
|
596
613
|
const minContentWidth = triggerRect.width + rightDelta;
|
|
597
614
|
const contentWidth = Math.max(minContentWidth, contentRect.width);
|
|
598
615
|
const leftEdge = window.innerWidth - CONTENT_MARGIN;
|
|
599
|
-
const clampedRight = (0, import_number.clamp)(right, [
|
|
616
|
+
const clampedRight = (0, import_number.clamp)(right, [
|
|
617
|
+
CONTENT_MARGIN,
|
|
618
|
+
Math.max(CONTENT_MARGIN, leftEdge - contentWidth)
|
|
619
|
+
]);
|
|
600
620
|
contentWrapper.style.minWidth = minContentWidth + "px";
|
|
601
621
|
contentWrapper.style.right = clampedRight + "px";
|
|
602
622
|
}
|
|
@@ -780,7 +800,11 @@ var SelectViewport = React.forwardRef(
|
|
|
780
800
|
// (independent of the scrollUpButton).
|
|
781
801
|
position: "relative",
|
|
782
802
|
flex: 1,
|
|
783
|
-
|
|
803
|
+
// Viewport should only be scrollable in the vertical direction.
|
|
804
|
+
// This won't work in vertical writing modes, so we'll need to
|
|
805
|
+
// revisit this if/when that is supported
|
|
806
|
+
// https://developer.chrome.com/blog/vertical-form-controls
|
|
807
|
+
overflow: "hidden auto",
|
|
784
808
|
...viewportProps.style
|
|
785
809
|
},
|
|
786
810
|
onScroll: (0, import_primitive.composeEventHandlers)(viewportProps.onScroll, (event) => {
|
|
@@ -853,6 +877,7 @@ var SelectItem = React.forwardRef(
|
|
|
853
877
|
(node) => contentContext.itemRefCallback?.(node, value, disabled)
|
|
854
878
|
);
|
|
855
879
|
const textId = (0, import_react_id.useId)();
|
|
880
|
+
const pointerTypeRef = React.useRef("touch");
|
|
856
881
|
const handleSelect = () => {
|
|
857
882
|
if (!disabled) {
|
|
858
883
|
context.onValueChange(value);
|
|
@@ -897,11 +922,20 @@ var SelectItem = React.forwardRef(
|
|
|
897
922
|
ref: composedRefs,
|
|
898
923
|
onFocus: (0, import_primitive.composeEventHandlers)(itemProps.onFocus, () => setIsFocused(true)),
|
|
899
924
|
onBlur: (0, import_primitive.composeEventHandlers)(itemProps.onBlur, () => setIsFocused(false)),
|
|
900
|
-
|
|
925
|
+
onClick: (0, import_primitive.composeEventHandlers)(itemProps.onClick, () => {
|
|
926
|
+
if (pointerTypeRef.current !== "mouse") handleSelect();
|
|
927
|
+
}),
|
|
928
|
+
onPointerUp: (0, import_primitive.composeEventHandlers)(itemProps.onPointerUp, () => {
|
|
929
|
+
if (pointerTypeRef.current === "mouse") handleSelect();
|
|
930
|
+
}),
|
|
931
|
+
onPointerDown: (0, import_primitive.composeEventHandlers)(itemProps.onPointerDown, (event) => {
|
|
932
|
+
pointerTypeRef.current = event.pointerType;
|
|
933
|
+
}),
|
|
901
934
|
onPointerMove: (0, import_primitive.composeEventHandlers)(itemProps.onPointerMove, (event) => {
|
|
935
|
+
pointerTypeRef.current = event.pointerType;
|
|
902
936
|
if (disabled) {
|
|
903
937
|
contentContext.onItemLeave?.();
|
|
904
|
-
} else {
|
|
938
|
+
} else if (pointerTypeRef.current === "mouse") {
|
|
905
939
|
event.currentTarget.focus({ preventScroll: true });
|
|
906
940
|
}
|
|
907
941
|
}),
|