@radix-ui/react-select 0.1.2-rc.32 → 0.1.2-rc.35
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.ts.map +1 -1
- package/dist/index.js +71 -30
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +72 -31
- package/dist/index.module.js.map +1 -1
- package/package.json +16 -16
package/dist/index.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $01b9c$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import {useState as $01b9c$useState, useRef as $01b9c$useRef, createElement as $01b9c$createElement, forwardRef as $01b9c$forwardRef, useEffect as $01b9c$useEffect,
|
|
2
|
+
import {useState as $01b9c$useState, useRef as $01b9c$useRef, createElement as $01b9c$createElement, forwardRef as $01b9c$forwardRef, useCallback as $01b9c$useCallback, useEffect as $01b9c$useEffect, Fragment as $01b9c$Fragment, useMemo as $01b9c$useMemo} from "react";
|
|
3
3
|
import {createPortal as $01b9c$createPortal} from "react-dom";
|
|
4
4
|
import {clamp as $01b9c$clamp} from "@radix-ui/number";
|
|
5
5
|
import {composeEventHandlers as $01b9c$composeEventHandlers} from "@radix-ui/primitive";
|
|
@@ -110,9 +110,7 @@ const $cc7e05a45900e73f$export$ef9b1a59e592288f = (props)=>{
|
|
|
110
110
|
prop: valueProp,
|
|
111
111
|
defaultProp: defaultValue,
|
|
112
112
|
onChange: onValueChange
|
|
113
|
-
});
|
|
114
|
-
const isFormControl = trigger ? Boolean(trigger.closest('form')) : true;
|
|
115
|
-
const [bubbleSelect, setBubbleSelect] = $01b9c$useState(null);
|
|
113
|
+
});
|
|
116
114
|
const triggerPointerDownPosRef = $01b9c$useRef(null);
|
|
117
115
|
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectProvider, {
|
|
118
116
|
scope: __scopeSelect,
|
|
@@ -128,20 +126,12 @@ const $cc7e05a45900e73f$export$ef9b1a59e592288f = (props)=>{
|
|
|
128
126
|
open: open,
|
|
129
127
|
onOpenChange: setOpen,
|
|
130
128
|
dir: direction,
|
|
131
|
-
|
|
129
|
+
name: name,
|
|
130
|
+
autoComplete: autoComplete,
|
|
132
131
|
triggerPointerDownPosRef: triggerPointerDownPosRef
|
|
133
132
|
}, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Provider, {
|
|
134
133
|
scope: __scopeSelect
|
|
135
|
-
}, children)
|
|
136
|
-
ref: setBubbleSelect,
|
|
137
|
-
"aria-hidden": true,
|
|
138
|
-
tabIndex: -1,
|
|
139
|
-
name: name,
|
|
140
|
-
autoComplete: autoComplete,
|
|
141
|
-
value: value // enable form autofill
|
|
142
|
-
,
|
|
143
|
-
onChange: (event)=>setValue(event.target.value)
|
|
144
|
-
}) : null);
|
|
134
|
+
}, children));
|
|
145
135
|
};
|
|
146
136
|
/*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$ef9b1a59e592288f, {
|
|
147
137
|
displayName: $cc7e05a45900e73f$var$SELECT_NAME
|
|
@@ -257,22 +247,56 @@ const $cc7e05a45900e73f$export$99b400cabb58c515 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
257
247
|
/* -------------------------------------------------------------------------------------------------
|
|
258
248
|
* SelectContent
|
|
259
249
|
* -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$CONTENT_NAME = 'SelectContent';
|
|
250
|
+
const [$cc7e05a45900e73f$var$SelectNativeOptionsProvider, $cc7e05a45900e73f$var$useSelectNativeOptionsContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$CONTENT_NAME);
|
|
260
251
|
const $cc7e05a45900e73f$export$c973a4b3cb86a03d = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
|
|
261
252
|
const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$CONTENT_NAME, props.__scopeSelect);
|
|
262
|
-
const [fragment, setFragment] = $01b9c$useState(); //
|
|
253
|
+
const [fragment, setFragment] = $01b9c$useState(); // We set this to true by default so that events bubble to forms without JS (SSR)
|
|
254
|
+
const isFormControl = context.trigger ? Boolean(context.trigger.closest('form')) : true;
|
|
255
|
+
const [nativeOptionsSet, setNativeOptionsSet] = $01b9c$useState(new Set()); // The native `select` only associates the correct default value if the corresponding
|
|
256
|
+
// `option` is rendered as a child **at the same time** as itself.
|
|
257
|
+
// Because it might take a few renders for our items to gather the information to build
|
|
258
|
+
// the native `option`(s), we generate a key on the `select` to make sure React re-builds it
|
|
259
|
+
// each time the options change.
|
|
260
|
+
const nativeSelectKey = Array.from(nativeOptionsSet).map((option)=>option.props.value
|
|
261
|
+
).join(';'); // setting the fragment in `useLayoutEffect` as `DocumentFragment` doesn't exist on the server
|
|
263
262
|
$01b9c$useLayoutEffect(()=>{
|
|
264
263
|
setFragment(new DocumentFragment());
|
|
265
264
|
}, []);
|
|
266
|
-
return
|
|
265
|
+
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectNativeOptionsProvider, {
|
|
266
|
+
scope: props.__scopeSelect,
|
|
267
|
+
onNativeOptionAdd: $01b9c$useCallback((option)=>{
|
|
268
|
+
setNativeOptionsSet((prev)=>new Set(prev).add(option)
|
|
269
|
+
);
|
|
270
|
+
}, []),
|
|
271
|
+
onNativeOptionRemove: $01b9c$useCallback((option)=>{
|
|
272
|
+
setNativeOptionsSet((prev)=>{
|
|
273
|
+
const optionsSet = new Set(prev);
|
|
274
|
+
optionsSet.delete(option);
|
|
275
|
+
return optionsSet;
|
|
276
|
+
});
|
|
277
|
+
}, [])
|
|
278
|
+
}, isFormControl ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$BubbleSelect, {
|
|
279
|
+
key: nativeSelectKey,
|
|
280
|
+
"aria-hidden": true,
|
|
281
|
+
tabIndex: -1,
|
|
282
|
+
name: context.name,
|
|
283
|
+
autoComplete: context.autoComplete,
|
|
284
|
+
value: context.value // enable form autofill
|
|
285
|
+
,
|
|
286
|
+
onChange: (event)=>context.onValueChange(event.target.value)
|
|
287
|
+
}, Array.from(nativeOptionsSet)) : null, context.open ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentImpl, $01b9c$babelruntimehelpersesmextends({}, props, {
|
|
267
288
|
ref: forwardedRef
|
|
268
|
-
})) : fragment ? /*#__PURE__*/ $01b9c$createPortal(/*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$
|
|
289
|
+
})) : fragment ? /*#__PURE__*/ $01b9c$createPortal(/*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentProvider, {
|
|
269
290
|
scope: props.__scopeSelect
|
|
270
291
|
}, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Slot, {
|
|
271
292
|
scope: props.__scopeSelect
|
|
272
|
-
}, /*#__PURE__*/ $01b9c$createElement("div", null, props.children))), fragment) : null;
|
|
293
|
+
}, /*#__PURE__*/ $01b9c$createElement("div", null, props.children))), fragment) : null);
|
|
294
|
+
});
|
|
295
|
+
/*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$c973a4b3cb86a03d, {
|
|
296
|
+
displayName: $cc7e05a45900e73f$var$CONTENT_NAME
|
|
273
297
|
});
|
|
274
298
|
const $cc7e05a45900e73f$var$CONTENT_MARGIN = 10;
|
|
275
|
-
const [$cc7e05a45900e73f$var$
|
|
299
|
+
const [$cc7e05a45900e73f$var$SelectContentProvider, $cc7e05a45900e73f$var$useSelectContentContext] = $cc7e05a45900e73f$var$createSelectContext($cc7e05a45900e73f$var$CONTENT_NAME);
|
|
276
300
|
const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
|
|
277
301
|
const { __scopeSelect: __scopeSelect , onCloseAutoFocus: onCloseAutoFocus , ...contentProps } = props;
|
|
278
302
|
const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$CONTENT_NAME, __scopeSelect);
|
|
@@ -524,7 +548,7 @@ const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef(
|
|
|
524
548
|
}, [
|
|
525
549
|
context.value
|
|
526
550
|
]);
|
|
527
|
-
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$
|
|
551
|
+
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentProvider, {
|
|
528
552
|
scope: __scopeSelect,
|
|
529
553
|
contentWrapper: contentWrapper,
|
|
530
554
|
content: content,
|
|
@@ -622,9 +646,6 @@ const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef(
|
|
|
622
646
|
})
|
|
623
647
|
})))))));
|
|
624
648
|
});
|
|
625
|
-
/*#__PURE__*/ Object.assign($cc7e05a45900e73f$var$SelectContentImpl, {
|
|
626
|
-
displayName: $cc7e05a45900e73f$var$CONTENT_NAME
|
|
627
|
-
});
|
|
628
649
|
/* -------------------------------------------------------------------------------------------------
|
|
629
650
|
* SelectViewport
|
|
630
651
|
* -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$VIEWPORT_NAME = 'SelectViewport';
|
|
@@ -805,25 +826,44 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
805
826
|
* SelectItemText
|
|
806
827
|
* -----------------------------------------------------------------------------------------------*/ const $cc7e05a45900e73f$var$ITEM_TEXT_NAME = 'SelectItemText';
|
|
807
828
|
const $cc7e05a45900e73f$export$3572fb0fb821ff49 = /*#__PURE__*/ $01b9c$forwardRef((props, forwardedRef)=>{
|
|
808
|
-
var _ref$current;
|
|
809
829
|
// We ignore `className` and `style` as this part shouldn't be styled.
|
|
810
830
|
const { __scopeSelect: __scopeSelect , className: className , style: style , ...itemTextProps } = props;
|
|
811
831
|
const context = $cc7e05a45900e73f$var$useSelectContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
812
832
|
const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
813
833
|
const itemContext = $cc7e05a45900e73f$var$useSelectItemContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
814
|
-
const
|
|
815
|
-
const
|
|
834
|
+
const nativeOptionsContext = $cc7e05a45900e73f$var$useSelectNativeOptionsContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
835
|
+
const [itemTextNode, setItemTextNode] = $01b9c$useState(null);
|
|
836
|
+
const composedRefs = $01b9c$useComposedRefs(forwardedRef, (node)=>setItemTextNode(node)
|
|
837
|
+
, itemContext.onItemTextChange, (node)=>{
|
|
816
838
|
var _contentContext$itemT;
|
|
817
839
|
return (_contentContext$itemT = contentContext.itemTextRefCallback) === null || _contentContext$itemT === void 0 ? void 0 : _contentContext$itemT.call(contentContext, node, itemContext.value, itemContext.disabled);
|
|
818
840
|
});
|
|
841
|
+
const textContent = itemTextNode === null || itemTextNode === void 0 ? void 0 : itemTextNode.textContent;
|
|
842
|
+
const nativeOption = $01b9c$useMemo(()=>/*#__PURE__*/ $01b9c$createElement("option", {
|
|
843
|
+
key: itemContext.value,
|
|
844
|
+
value: itemContext.value,
|
|
845
|
+
disabled: itemContext.disabled
|
|
846
|
+
}, textContent)
|
|
847
|
+
, [
|
|
848
|
+
itemContext.disabled,
|
|
849
|
+
itemContext.value,
|
|
850
|
+
textContent
|
|
851
|
+
]);
|
|
852
|
+
const { onNativeOptionAdd: onNativeOptionAdd , onNativeOptionRemove: onNativeOptionRemove } = nativeOptionsContext;
|
|
853
|
+
$01b9c$useLayoutEffect(()=>{
|
|
854
|
+
onNativeOptionAdd(nativeOption);
|
|
855
|
+
return ()=>onNativeOptionRemove(nativeOption)
|
|
856
|
+
;
|
|
857
|
+
}, [
|
|
858
|
+
onNativeOptionAdd,
|
|
859
|
+
onNativeOptionRemove,
|
|
860
|
+
nativeOption
|
|
861
|
+
]);
|
|
819
862
|
return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
|
|
820
863
|
id: itemContext.textId
|
|
821
864
|
}, itemTextProps, {
|
|
822
865
|
ref: composedRefs
|
|
823
|
-
})), itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? /*#__PURE__*/ $01b9c$createPortal(itemTextProps.children, context.valueNode) : null
|
|
824
|
-
$01b9c$createElement("option", {
|
|
825
|
-
value: itemContext.value
|
|
826
|
-
}, (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.textContent), context.bubbleSelect) : null);
|
|
866
|
+
})), itemContext.isSelected && context.valueNode && !context.valueNodeHasChildren ? /*#__PURE__*/ $01b9c$createPortal(itemTextProps.children, context.valueNode) : null);
|
|
827
867
|
});
|
|
828
868
|
/*#__PURE__*/ Object.assign($cc7e05a45900e73f$export$3572fb0fb821ff49, {
|
|
829
869
|
displayName: $cc7e05a45900e73f$var$ITEM_TEXT_NAME
|
|
@@ -1014,6 +1054,7 @@ const $cc7e05a45900e73f$export$eba4b1df07cb1d3 = /*#__PURE__*/ $01b9c$forwardRef
|
|
|
1014
1054
|
defaultValue: value
|
|
1015
1055
|
})));
|
|
1016
1056
|
});
|
|
1057
|
+
$cc7e05a45900e73f$var$BubbleSelect.displayName = 'BubbleSelect';
|
|
1017
1058
|
function $cc7e05a45900e73f$var$useTypeaheadSearch(onSearchChange) {
|
|
1018
1059
|
const handleSearchChange = $01b9c$useCallbackRef(onSearchChange);
|
|
1019
1060
|
const searchRef = $01b9c$useRef('');
|