Skip to content

Commit f886178

Browse files
LFDanLudannify
andauthored
fixing combobox menu flipping with picker code (#2069)
Co-authored-by: Danni <[email protected]>
1 parent 53f3197 commit f886178

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/@react-spectrum/combobox/src/ComboBox.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const ComboBoxBase = React.forwardRef(function ComboBoxBase<T extends object>(pr
108108
state
109109
);
110110

111-
let {overlayProps, placement} = useOverlayPosition({
111+
let {overlayProps, placement, updatePosition} = useOverlayPosition({
112112
targetRef: unwrappedButtonRef,
113113
overlayRef: unwrappedPopoverRef,
114114
scrollRef: listBoxRef,
@@ -137,6 +137,17 @@ const ComboBoxBase = React.forwardRef(function ComboBoxBase<T extends object>(pr
137137

138138
useLayoutEffect(onResize, [scale, onResize]);
139139

140+
// Update position once the ListBox has rendered. This ensures that
141+
// it flips properly when it doesn't fit in the available space.
142+
// TODO: add ResizeObserver to useOverlayPosition so we don't need this.
143+
useLayoutEffect(() => {
144+
if (state.isOpen) {
145+
requestAnimationFrame(() => {
146+
updatePosition();
147+
});
148+
}
149+
}, [state.isOpen, updatePosition]);
150+
140151
let style = {
141152
...overlayProps.style,
142153
width: isQuiet ? null : menuWidth,

0 commit comments

Comments
 (0)