@choice-ui/react 1.8.6 → 1.8.7
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.
|
@@ -7,6 +7,12 @@ export interface DropdownProps {
|
|
|
7
7
|
* @default true
|
|
8
8
|
*/
|
|
9
9
|
autoSelectFirstItem?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to avoid collisions by flipping or shifting the dropdown position.
|
|
12
|
+
* When false, the dropdown will strictly follow the placement direction.
|
|
13
|
+
* @default true
|
|
14
|
+
*/
|
|
15
|
+
avoidCollisions?: boolean;
|
|
10
16
|
children?: React.ReactNode;
|
|
11
17
|
disabledNested?: boolean;
|
|
12
18
|
focusManagerProps?: Partial<FloatingFocusManagerProps>;
|
|
@@ -13,6 +13,7 @@ const DropdownComponent = memo(function DropdownComponent2(props) {
|
|
|
13
13
|
const {
|
|
14
14
|
children,
|
|
15
15
|
autoSelectFirstItem = true,
|
|
16
|
+
avoidCollisions = true,
|
|
16
17
|
disabledNested = false,
|
|
17
18
|
offset: offsetDistance = DEFAULT_OFFSET,
|
|
18
19
|
placement = "bottom-start",
|
|
@@ -77,11 +78,14 @@ const DropdownComponent = memo(function DropdownComponent2(props) {
|
|
|
77
78
|
});
|
|
78
79
|
});
|
|
79
80
|
const lastPositionRef = useRef(null);
|
|
80
|
-
const middleware = useMemo(
|
|
81
|
-
|
|
82
|
-
offset({ mainAxis: isNested ? 10 : offsetDistance, alignmentAxis: isNested ? -4 : 0 })
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
const middleware = useMemo(() => {
|
|
82
|
+
const baseMiddleware = [
|
|
83
|
+
offset({ mainAxis: isNested ? 10 : offsetDistance, alignmentAxis: isNested ? -4 : 0 })
|
|
84
|
+
];
|
|
85
|
+
if (avoidCollisions) {
|
|
86
|
+
baseMiddleware.push(flip(), shift());
|
|
87
|
+
}
|
|
88
|
+
baseMiddleware.push(
|
|
85
89
|
size({
|
|
86
90
|
padding: 4,
|
|
87
91
|
apply({ elements, availableHeight, rects }) {
|
|
@@ -104,9 +108,9 @@ const DropdownComponent = memo(function DropdownComponent2(props) {
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
})
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
);
|
|
111
|
+
);
|
|
112
|
+
return baseMiddleware;
|
|
113
|
+
}, [isNested, offsetDistance, matchTriggerWidth, scrollRef, avoidCollisions]);
|
|
110
114
|
const { refs, floatingStyles, context, isPositioned } = useFloating({
|
|
111
115
|
nodeId,
|
|
112
116
|
open: isControlledOpen,
|
|
@@ -6,9 +6,13 @@ import { MenuScrollArrowTv } from "../tv.js";
|
|
|
6
6
|
import { useIsomorphicLayoutEffect } from "../../../../shared/hooks/use-isomorphic-layout-effect/use-isomorphic-layout-effect.js";
|
|
7
7
|
import { tcx } from "../../../../shared/utils/tcx/tcx.js";
|
|
8
8
|
const SCROLL_ARROW_PADDING = 16;
|
|
9
|
+
const MIN_HEIGHT_FOR_ARROWS = 48;
|
|
9
10
|
const shouldShowArrow = (scrollRef, dir) => {
|
|
10
11
|
if (scrollRef.current) {
|
|
11
12
|
const { scrollTop, scrollHeight, clientHeight } = scrollRef.current;
|
|
13
|
+
if (clientHeight < MIN_HEIGHT_FOR_ARROWS) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
12
16
|
if (dir === "up") {
|
|
13
17
|
return scrollTop >= SCROLL_ARROW_PADDING;
|
|
14
18
|
}
|
package/package.json
CHANGED