Skip to content

Commit e31be39

Browse files
fix(web): opening Settings or Usage from the keyboard closes an open picker (#45435)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
1 parent bf9e985 commit e31be39

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎apps/web/src/components/AppRouteModal.browser.test.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff 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">

‎apps/web/src/components/AppRouteModal.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useCloseAppModal } from "./sidebar/mainAppLocation";
1818
import { GlobalVoiceInputIndicator } from "./chat/GlobalVoiceInputIndicator";
1919
import { Button } from "./ui/button";
2020
import { DialogBackdrop } from "./ui/dialog";
21+
import { closeOpenPopups } from "./ui/open-popups";
2122
import { 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.

0 commit comments

Comments
 (0)