Skip to content

Commit fe84cf9

Browse files
authored
fix: ensure submenu is aligned correctly in reference to the parent menu with floating-ui/react (#2868)
1 parent cf3ad0f commit fe84cf9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/components/Dialog/DialogAnchor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function useDialogAnchor<T extends HTMLElement>({
4242
// update is non-null only if popperElement is non-null
4343
update?.();
4444
}
45-
}, [open, popperElement, update]);
45+
}, [open, placement, popperElement, update]);
4646

4747
if (popperElement && !open) {
4848
setPopperElement(null);

src/components/Dialog/hooks/usePopoverPosition.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ export function usePopoverPosition({
6969
}: UsePopoverParams) {
7070
const autoMw = autoMiddlewareFor(placement);
7171
const offsetMiddleware = toOffsetMw(offset);
72+
const isSidePlacement = placement.startsWith('left') || placement.startsWith('right');
7273

7374
const middleware = [
7475
// offset first (mirrors common Popper setups)
7576
...(offsetMiddleware ? [offsetMiddleware] : []),
7677

7778
// choose between autoPlacement (Popper's "auto*") OR flip()
78-
...(autoMw ? [autoMw] : allowFlip ? [flipMw()] : []),
79+
// only allow flip when not explicitly 'left*' or 'right*'
80+
...(autoMw ? [autoMw] : allowFlip && !isSidePlacement ? [flipMw()] : []),
7981

8082
// viewport collision adjustments
8183
...(allowShift ? [shiftMw({ padding: 8 })] : []),
@@ -93,6 +95,7 @@ export function usePopoverPosition({
9395
return useFloating({
9496
middleware,
9597
placement: seedPlacement,
98+
strategy: 'fixed',
9699
whileElementsMounted: freeze
97100
? undefined
98101
: (reference, floating, update) =>

0 commit comments

Comments
 (0)