@radix-ui/react-select 0.1.2-rc.20 → 0.1.2-rc.23
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 +49 -17
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +49 -17
- 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)=>{
|
|
@@ -735,10 +756,11 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
735
756
|
textValue: textValue
|
|
736
757
|
}, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.div, $01b9c$babelruntimehelpersesmextends({
|
|
737
758
|
role: "option",
|
|
738
|
-
"aria-labelledby": textId
|
|
759
|
+
"aria-labelledby": textId,
|
|
760
|
+
"data-highlighted": isFocused ? '' : undefined // `isFocused` caveat fixes stuttering in VoiceOver
|
|
739
761
|
,
|
|
740
762
|
"aria-selected": isSelected && isFocused,
|
|
741
|
-
"data-state": isSelected ? '
|
|
763
|
+
"data-state": isSelected ? 'checked' : 'unchecked',
|
|
742
764
|
"aria-disabled": disabled || undefined,
|
|
743
765
|
"data-disabled": disabled ? '' : undefined,
|
|
744
766
|
tabIndex: disabled ? undefined : -1
|
|
@@ -750,18 +772,24 @@ const $cc7e05a45900e73f$export$13ef48a934230896 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
750
772
|
),
|
|
751
773
|
onPointerUp: $01b9c$composeEventHandlers(itemProps.onPointerUp, handleSelect),
|
|
752
774
|
onPointerMove: $01b9c$composeEventHandlers(itemProps.onPointerMove, (event)=>{
|
|
753
|
-
if (disabled)
|
|
754
|
-
|
|
775
|
+
if (disabled) {
|
|
776
|
+
var _contentContext$onIte;
|
|
777
|
+
(_contentContext$onIte = contentContext.onItemLeave) === null || _contentContext$onIte === void 0 || _contentContext$onIte.call(contentContext);
|
|
778
|
+
} else // even though safari doesn't support this option, it's acceptable
|
|
755
779
|
// as it only means it might scroll a few pixels when using the pointer.
|
|
756
780
|
event.currentTarget.focus({
|
|
757
781
|
preventScroll: true
|
|
758
782
|
});
|
|
759
783
|
}),
|
|
760
784
|
onPointerLeave: $01b9c$composeEventHandlers(itemProps.onPointerLeave, (event)=>{
|
|
761
|
-
if (event.currentTarget === document.activeElement)
|
|
785
|
+
if (event.currentTarget === document.activeElement) {
|
|
786
|
+
var _contentContext$onIte2;
|
|
787
|
+
(_contentContext$onIte2 = contentContext.onItemLeave) === null || _contentContext$onIte2 === void 0 || _contentContext$onIte2.call(contentContext);
|
|
788
|
+
}
|
|
762
789
|
}),
|
|
763
790
|
onKeyDown: $01b9c$composeEventHandlers(itemProps.onKeyDown, (event)=>{
|
|
764
|
-
|
|
791
|
+
var _contentContext$searc;
|
|
792
|
+
const isTypingAhead = ((_contentContext$searc = contentContext.searchRef) === null || _contentContext$searc === void 0 ? void 0 : _contentContext$searc.current) !== '';
|
|
765
793
|
if (isTypingAhead && event.key === ' ') return;
|
|
766
794
|
if ($cc7e05a45900e73f$var$SELECTION_KEYS.includes(event.key)) handleSelect(); // prevent page scroll if using the space key to select an item
|
|
767
795
|
if (event.key === ' ') event.preventDefault();
|
|
@@ -782,7 +810,10 @@ const $cc7e05a45900e73f$export$3572fb0fb821ff49 = /*#__PURE__*/ $01b9c$forwardRe
|
|
|
782
810
|
const contentContext = $cc7e05a45900e73f$var$useSelectContentContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
783
811
|
const itemContext = $cc7e05a45900e73f$var$useSelectItemContext($cc7e05a45900e73f$var$ITEM_TEXT_NAME, __scopeSelect);
|
|
784
812
|
const ref = $01b9c$useRef(null);
|
|
785
|
-
const composedRefs = $01b9c$useComposedRefs(forwardedRef, ref, itemContext.onItemTextChange,
|
|
813
|
+
const composedRefs = $01b9c$useComposedRefs(forwardedRef, ref, itemContext.onItemTextChange, (node)=>{
|
|
814
|
+
var _contentContext$itemT;
|
|
815
|
+
return (_contentContext$itemT = contentContext.itemTextRefCallback) === null || _contentContext$itemT === void 0 ? void 0 : _contentContext$itemT.call(contentContext, node, itemContext.value, itemContext.disabled);
|
|
816
|
+
});
|
|
786
817
|
return /*#__PURE__*/ $01b9c$createElement($01b9c$Fragment, null, /*#__PURE__*/ $01b9c$createElement($01b9c$Primitive.span, $01b9c$babelruntimehelpersesmextends({
|
|
787
818
|
id: itemContext.textId
|
|
788
819
|
}, itemTextProps, {
|
|
@@ -919,7 +950,8 @@ const $cc7e05a45900e73f$var$SelectScrollButtonImpl = /*#__PURE__*/ $01b9c$forwar
|
|
|
919
950
|
...scrollIndicatorProps.style
|
|
920
951
|
},
|
|
921
952
|
onPointerMove: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerMove, ()=>{
|
|
922
|
-
|
|
953
|
+
var _contentContext$onIte3;
|
|
954
|
+
(_contentContext$onIte3 = contentContext.onItemLeave) === null || _contentContext$onIte3 === void 0 || _contentContext$onIte3.call(contentContext);
|
|
923
955
|
if (autoScrollTimerRef.current === null) autoScrollTimerRef.current = window.setInterval(onAutoScroll, 50);
|
|
924
956
|
}),
|
|
925
957
|
onPointerLeave: $01b9c$composeEventHandlers(scrollIndicatorProps.onPointerLeave, ()=>{
|