Skip to content

Commit 1c2091f

Browse files
committed
fix(FilterPicker): popover flip
1 parent 8b2400a commit 1c2091f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.changeset/pretty-turtles-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cube-dev/ui-kit": patch
3+
---
4+
5+
Fix popover of FilterPicker to corretly flip on opening.

src/components/fields/FilterPicker/FilterPicker.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
895895
);
896896
};
897897

898-
const [shouldUpdatePosition, setShouldUpdatePosition] = useState(false);
898+
const [shouldUpdatePosition, setShouldUpdatePosition] = useState(true);
899899

900900
// The trigger is rendered as a function so we can access the dialog state
901901
const renderTrigger = (state) => {
@@ -943,8 +943,14 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
943943
});
944944

945945
useEffect(() => {
946-
// Disable the update of the position while the popover is open (with a delay) to avoid jumping
947-
setShouldUpdatePosition(!state.isOpen);
946+
// Allow initial positioning & flipping when opening, then lock placement after first frame
947+
if (state.isOpen) {
948+
setShouldUpdatePosition(true);
949+
const id = requestAnimationFrame(() => setShouldUpdatePosition(false));
950+
return () => cancelAnimationFrame(id);
951+
} else {
952+
setShouldUpdatePosition(true);
953+
}
948954
}, [state.isOpen]);
949955

950956
// Clear button logic
@@ -1032,7 +1038,7 @@ export const FilterPicker = forwardRef(function FilterPicker<T extends object>(
10321038
placement="bottom start"
10331039
styles={triggerStyles}
10341040
shouldUpdatePosition={shouldUpdatePosition}
1035-
shouldFlip={shouldFlip}
1041+
shouldFlip={shouldFlip && !isPopoverOpen}
10361042
isDismissable={true}
10371043
shouldCloseOnInteractOutside={(el) => {
10381044
const menuTriggerEl = el.closest('[data-popover-trigger]');

0 commit comments

Comments
 (0)