Skip to content

Commit 53f4d39

Browse files
authored
fix(Menu): prevent sub-menu focus fight when it opens on top of trigger (#2745)
When a sub-menu opens above the parent trigger (constrained viewport), the pointer is now over the sub-content but the parent's highlightedElement becomes undefined because no parent item is being hovered. Previously this would close the sub-menu, causing a cycle where it reopenes and closes again. Now when highlightedElement becomes undefined while a sub-menu is active, the sub-menu stays open. It only closes when the highlight moves to a different parent item. Closes #2446
1 parent faf27e7 commit 53f4d39

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/core/src/Menu/MenuContentImpl.vue‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ const activeSubmenuContext = ref<{ onOpenChange: (open: boolean) => void, trigge
170170
171171
watch(highlightedElement, (el) => {
172172
if (activeSubmenuContext.value && (el === undefined || el !== activeSubmenuContext.value.trigger.value)) {
173+
// Don't close the submenu when the highlight disappears (pointer left
174+
// all parent items, likely because the submenu opened on top of the
175+
// trigger in a constrained viewport). Only close when highlight moves
176+
// to a different parent item.
177+
if (el === undefined)
178+
return
173179
activeSubmenuContext.value.onOpenChange(false)
174180
activeSubmenuContext.value = undefined
175181
}

0 commit comments

Comments
 (0)