@radix-ui/react-select 0.1.2-rc.20 → 0.1.2-rc.21
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 +46 -15
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +46 -15
- package/dist/index.module.js.map +1 -1
- package/package.json +16 -16
package/dist/index.module.js
CHANGED
|
@@ -106,7 +106,7 @@ const $cc7e05a45900e73f$export$ef9b1a59e592288f = (props)=>{
|
|
|
106
106
|
defaultProp: defaultOpen,
|
|
107
107
|
onChange: onOpenChange
|
|
108
108
|
});
|
|
109
|
-
const [value
|
|
109
|
+
const [value, setValue] = $01b9c$useControllableState({
|
|
110
110
|
prop: valueProp,
|
|
111
111
|
defaultProp: defaultValue,
|
|
112
112
|
onChange: onValueChange
|
|
@@ -263,8 +263,7 @@ const $cc7e05a45900e73f$export$c973a4b3cb86a03d = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
263
263
|
}, []);
|
|
264
264
|
return context.open ? /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentImpl, $01b9c$babelruntimehelpersesmextends({}, props, {
|
|
265
265
|
ref: forwardedRef
|
|
266
|
-
})) : fragment ? /*#__PURE__*/ $01b9c$createPortal(/*#__PURE__*/
|
|
267
|
-
$01b9c$createElement($cc7e05a45900e73f$var$SelectContentContextProvider, {
|
|
266
|
+
})) : fragment ? /*#__PURE__*/ $01b9c$createPortal(/*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentContextProvider, {
|
|
268
267
|
scope: props.__scopeSelect
|
|
269
268
|
}, /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$Collection.Slot, {
|
|
270
269
|
scope: props.__scopeSelect
|
|
@@ -285,7 +284,8 @@ const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef(
|
|
|
285
284
|
const getItems = $cc7e05a45900e73f$var$useCollection(__scopeSelect);
|
|
286
285
|
const [isPositioned, setIsPositioned] = $01b9c$useState(false);
|
|
287
286
|
const shouldRepositionRef = $01b9c$useRef(true);
|
|
288
|
-
const shouldExpandOnScrollRef = $01b9c$useRef(false);
|
|
287
|
+
const shouldExpandOnScrollRef = $01b9c$useRef(false);
|
|
288
|
+
const firstValidItemFoundRef = $01b9c$useRef(false); // aria-hide everything except the content (better supported equivalent to setting aria-modal)
|
|
289
289
|
$01b9c$useEffect(()=>{
|
|
290
290
|
if (content) return $01b9c$hideOthers(content);
|
|
291
291
|
}, [
|
|
@@ -501,22 +501,39 @@ const $cc7e05a45900e73f$var$SelectContentImpl = /*#__PURE__*/ $01b9c$forwardRef(
|
|
|
501
501
|
*/ setTimeout(()=>nextItem.ref.current.focus()
|
|
502
502
|
);
|
|
503
503
|
});
|
|
504
|
+
const itemRefCallback = $01b9c$useCallback((node, value, disabled)=>{
|
|
505
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
506
|
+
const isSelectedItem = context.value !== undefined && context.value === value;
|
|
507
|
+
if (isSelectedItem || isFirstValidItem) {
|
|
508
|
+
setSelectedItem(node);
|
|
509
|
+
if (isFirstValidItem) firstValidItemFoundRef.current = true;
|
|
510
|
+
}
|
|
511
|
+
}, [
|
|
512
|
+
context.value
|
|
513
|
+
]);
|
|
504
514
|
const handleItemLeave = $01b9c$useCallback(()=>content === null || content === void 0 ? void 0 : content.focus()
|
|
505
515
|
, [
|
|
506
516
|
content
|
|
507
517
|
]);
|
|
518
|
+
const itemTextRefCallback = $01b9c$useCallback((node, value, disabled)=>{
|
|
519
|
+
const isFirstValidItem = !firstValidItemFoundRef.current && !disabled;
|
|
520
|
+
const isSelectedItem = context.value !== undefined && context.value === value;
|
|
521
|
+
if (isSelectedItem || isFirstValidItem) setSelectedItemText(node);
|
|
522
|
+
}, [
|
|
523
|
+
context.value
|
|
524
|
+
]);
|
|
508
525
|
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectContentContextProvider, {
|
|
509
526
|
scope: __scopeSelect,
|
|
510
527
|
contentWrapper: contentWrapper,
|
|
511
528
|
content: content,
|
|
512
529
|
viewport: viewport,
|
|
513
530
|
onViewportChange: setViewport,
|
|
531
|
+
itemRefCallback: itemRefCallback,
|
|
514
532
|
selectedItem: selectedItem,
|
|
515
|
-
|
|
533
|
+
onItemLeave: handleItemLeave,
|
|
534
|
+
itemTextRefCallback: itemTextRefCallback,
|
|
516
535
|
selectedItemText: selectedItemText,
|
|
517
|
-
onSelectedItemTextChange: setSelectedItemText,
|
|
518
536
|
onScrollButtonChange: handleScrollButtonChange,
|
|
519
|
-
onItemLeave: handleItemLeave,
|
|
520
537
|
isPositioned: isPositioned,
|
|
521
538
|
shouldExpandOnScrollRef: shouldExpandOnScrollRef,
|
|
522
539
|
searchRef: searchRef
|
|
@@ -637,7 +654,7 @@ const $cc7e05a45900e73f$export$9ed6e7b40248d36d = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
637
654
|
onScroll: $01b9c$composeEventHandlers(viewportProps.onScroll, (event)=>{
|
|
638
655
|
const viewport = event.currentTarget;
|
|
639
656
|
const { contentWrapper: contentWrapper , shouldExpandOnScrollRef: shouldExpandOnScrollRef } = contentContext;
|
|
640
|
-
if (shouldExpandOnScrollRef.current && contentWrapper) {
|
|
657
|
+
if (shouldExpandOnScrollRef !== null && shouldExpandOnScrollRef !== void 0 && shouldExpandOnScrollRef.current && contentWrapper) {
|
|
641
658
|
const scrolledBy = Math.abs(prevScrollTopRef.current - viewport.scrollTop);
|
|
642
659
|
if (scrolledBy > 0) {
|
|
643
660
|
const availableHeight = window.innerHeight - $cc7e05a45900e73f$var$CONTENT_MARGIN * 2;
|
|
@@ -709,7 +726,10 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
709
726
|
const isSelected = context.value === value;
|
|
710
727
|
const [textValue, setTextValue] = $01b9c$useState(textValueProp !== null && textValueProp !== void 0 ? textValueProp : '');
|
|
711
728
|
const [isFocused, setIsFocused] = $01b9c$useState(false);
|
|
712
|
-
const composedRefs = $01b9c$useComposedRefs(forwardedRef,
|
|
729
|
+
const composedRefs = $01b9c$useComposedRefs(forwardedRef, (node)=>{
|
|
730
|
+
var _contentContext$itemR;
|
|
731
|
+
return (_contentContext$itemR = contentContext.itemRefCallback) === null || _contentContext$itemR === void 0 ? void 0 : _contentContext$itemR.call(contentContext, node, value, disabled);
|
|
732
|
+
});
|
|
713
733
|
const textId = $01b9c$useId();
|
|
714
734
|
const handleSelect = ()=>{
|
|
715
735
|
if (!disabled) {
|
|
@@ -720,6 +740,7 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
720
740
|
return /*#__PURE__*/ $01b9c$createElement($cc7e05a45900e73f$var$SelectItemContextProvider, {
|
|
721
741
|
scope: __scopeSelect,
|
|
722
742
|
value: value,
|
|
743
|
+
disabled: disabled,
|
|
723
744
|
textId: textId,
|
|
724
745
|
isSelected: isSelected,
|
|
725
746
|
onItemTextChange: $01b9c$useCallback((node)=>{
|
|
@@ -750,18 +771,24 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
750
771
|
),
|
|
751
772
|
onPointerUp: $01b9c$composeEventHandlers(itemProps.onPointerUp, handleSelect),
|
|
752
773
|
onPointerMove: $01b9c$composeEventHandlers(itemProps.onPointerMove, (event)=>{
|
|
753
|
-
if (disabled)
|
|
754
|
-
|
|
774
|
+
if (disabled) {
|
|
775
|
+
var _contentContext$onIte;
|
|
776
|
+
(_contentContext$onIte = contentContext.onItemLeave) === null || _contentContext$onIte === void 0 || _contentContext$onIte.call(contentContext);
|
|
777
|
+
} else // even though safari doesn't support this option, it's acceptable
|
|
755
778
|
// as it only means it might scroll a few pixels when using the pointer.
|
|
756
779
|
event.currentTarget.focus({
|
|
757
780
|
preventScroll: true
|
|
758
781
|
});
|
|
759
782
|
}),
|
|
760
783
|
onPointerLeave: $01b9c$composeEventHandlers(itemProps.onPointerLeave, (event)=>{
|
|
761
|
-
if (event.currentTarget === document.activeElement)
|
|
784
|
+
if (event.currentTarget === document.activeElement) {
|
|
785
|
+
var _contentContext$onIte2;
|
|
786
|
+
(_contentContext$onIte2 = contentContext.onItemLeave) === null || _contentContext$onIte2 === void 0 || _contentContext$onIte2.call(contentContext);
|
|
787
|
+
}
|
|
762
788
|
}),
|
|
763
789
|
onKeyDown: $01b9c$composeEventHandlers(itemProps.onKeyDown, (event)=>{
|
|
764
|
-
|
|
790
|
+
var _contentContext$searc;
|
|
791
|
+
const isTypingAhead = ((_contentContext$searc = contentContext.searchRef) === null || _contentContext$searc === void 0 ? void 0 : _contentContext$searc.current) !== '';
|
|
765
792
|
if (isTypingAhead && event.key === ' ') return;
|
|
766
793
|
if ($cc7e05a45900e73f$var$SELECTION_KEYS.includes(event.key)) handleSelect(); // prevent page scroll if using the space key to select an item
|
|
767
794
|
if (event.key === ' ') event.preventDefault();
|
|
@@ -782,7 +809,10 @@ const $cc7e05a45900e73f$export$3572fb0fb821ff49 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
782
809
|
const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
783
810
|
const itemContext = $cc7e05a45900e73f$var$useSelectItemContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
784
811
|
const ref = $01b9c$useRef(null);
|
|
785
|
-
const composedRefs = $01b9c$useComposedRefs(forwardedRef, ref, itemContext.onItemTextChange,
|
|
812
|
+
const composedRefs = $01b9c$useComposedRefs(forwardedRef, ref, itemContext.onItemTextChange, (node)=>{
|
|
813
|
+
var _contentContext$itemT;
|
|
814
|
+
return (_contentContext$itemT = contentContext.itemTextRefCallback) === null || _contentContext$itemT === void 0 ? void 0 : _contentContext$itemT.call(contentContext, node, itemContext.value, itemContext.disabled);
|
|
815
|
+
});
|
|
786
816
|
return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
|
|
787
817
|
id: itemContext.textId
|
|
788
818
|
}, itemTextProps, {
|
|
@@ -919,7 +949,8 @@ const $cc7e05a45900e73f$var$SelectScrollButtonImpl = /*#__PURE__*/ $01b9c$forwar
|
|
|
919
949
|
...scrollIndicatorProps.style
|
|
920
950
|
},
|
|
921
951
|
onPointerMove: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerMove, ()=>{
|
|
922
|
-
|
|
952
|
+
var _contentContext$onIte3;
|
|
953
|
+
(_contentContext$onIte3 = contentContext.onItemLeave) === null || _contentContext$onIte3 === void 0 || _contentContext$onIte3.call(contentContext);
|
|
923
954
|
if (autoScrollTimerRef.current === null) autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
924
955
|
}),
|
|
925
956
|
onPointerLeave: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerLeave, ()=>{
|