File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,33 @@ describe("AppRouteModal", () => {
7979 await expect . element ( openerButton ) . toHaveFocus ( ) ;
8080 } ) ;
8181
82+ it ( "closes a menu the page left open when a shortcut opens it" , async ( ) => {
83+ const pageMenu = (
84+ < Menu >
85+ < MenuTrigger > Branch</ MenuTrigger >
86+ < MenuPopup >
87+ < MenuItem > main</ MenuItem >
88+ </ MenuPopup >
89+ </ Menu >
90+ ) ;
91+ await using screen = await render ( pageMenu , { router : "/" } ) ;
92+ await userEvent . click ( page . getByRole ( "button" , { name : "Branch" } ) ) ;
93+ await expect . element ( page . getByRole ( "menu" ) ) . toBeVisible ( ) ;
94+
95+ await screen . rerender (
96+ < >
97+ { pageMenu }
98+ < AppRouteModal label = "Usage" >
99+ < p > Usage</ p >
100+ </ AppRouteModal >
101+ </ > ,
102+ ) ;
103+
104+ await expect . element ( page . getByRole ( "dialog" , { name : "Usage" } ) ) . toHaveFocus ( ) ;
105+ // The modal hides the page from role queries, so look for the menu in the DOM.
106+ await expect . poll ( ( ) => document . querySelector ( '[data-slot="menu-popup"]' ) ) . toBeNull ( ) ;
107+ } ) ;
108+
82109 it ( "stays open when Esc belongs to a modal outside Base UI" , async ( ) => {
83110 await using _screen = await render (
84111 < AppRouteModal label = "Settings" >
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import { useCloseAppModal } from "./sidebar/mainAppLocation";
1818import { GlobalVoiceInputIndicator } from "./chat/GlobalVoiceInputIndicator" ;
1919import { Button } from "./ui/button" ;
2020import { DialogBackdrop } from "./ui/dialog" ;
21+ import { closeOpenPopups } from "./ui/open-popups" ;
2122import { SharedTooltipTrigger } from "./ui/shared-tooltip" ;
2223
2324/**
@@ -52,6 +53,8 @@ export function AppRouteModal({
5253 // 1.5rem inset is shorter than the strip.
5354 const nativeTitlebarHeight = useNativeTitlebarHeight ( ) ;
5455 const router = useRouter ( ) ;
56+ // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- popups opened before a keyboard shortcut opened the modal would stay drawn above it
57+ useEffect ( closeOpenPopups , [ ] ) ;
5558 // Leaving the page without closing (Navigation: Back) unmounts a focused field during a
5659 // commit, when React no longer delivers its blur, so commit-on-blur rows would drop what was
5760 // typed. Blur text fields before the navigation renders; other controls keep their focus.
You can’t perform that action at this time.
0 commit comments