diff --git a/webui/src/components/settings/SettingsSidebar.tsx b/webui/src/components/settings/SettingsSidebar.tsx index 0ecba8954..c54cb2b37 100644 --- a/webui/src/components/settings/SettingsSidebar.tsx +++ b/webui/src/components/settings/SettingsSidebar.tsx @@ -23,7 +23,13 @@ import { } from "@/components/SidebarSelectionHighlight"; import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts"; import { Button } from "@/components/ui/button"; -import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "@/components/ui/sheet"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; import { useMediaQuery } from "@/hooks/useMediaQuery"; import { cn } from "@/lib/utils"; @@ -184,7 +190,7 @@ export function SettingsSidebar(props: SettingsSidebarProps) { ); } -// Mount only on narrow screens so switching to desktop also releases the sheet's focus/pointer lock. +// Mount only on narrow screens so an open menu cannot survive a switch to desktop. function MobileSettingsNavigation({ navSection, activeLabel, @@ -202,16 +208,18 @@ function MobileSettingsNavigation({ }) { const { t } = useTranslation(); const [open, setOpen] = useState(false); + const restart = () => { setOpen(false); onRestart?.(); }; + const restartTone = restartPending && !isRestarting + ? "text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300" + : "text-muted-foreground hover:text-foreground"; + const restartIcon = isRestarting ? + : ; const restartAction = onRestart ? ( ) : null; @@ -227,49 +235,45 @@ function MobileSettingsNavigation({ > - - + + - - + -
- {t("settings.sidebar.title")} - -
-
- - {restartAction ?
{restartAction}
: null} -
-
-
+ {SETTINGS_NAV_ITEMS.map(({ key, icon: Icon, fallback }) => { + const active = key === navSection; + return ( + onSelectSection(key)} + className={cn("min-h-11 gap-3 text-sm font-normal", + active ? "bg-sidebar-accent text-foreground" : "text-sidebar-content")} + > + + + {t(`settings.nav.${key}`, { defaultValue: fallback })} + + {active ? : null} + + ); + })} + {onRestart ? <> + + {restartIcon}{restartLabel} + : null} + + {onRestart && (restartPending || isRestarting) ? (
diff --git a/webui/src/tests/settings-sidebar.test.tsx b/webui/src/tests/settings-sidebar.test.tsx index 071ea8ec6..8c281cf1a 100644 --- a/webui/src/tests/settings-sidebar.test.tsx +++ b/webui/src/tests/settings-sidebar.test.tsx @@ -38,7 +38,7 @@ function Sidebar(props: Partial>) { describe("Settings navigation on mobile", () => { installSettingsViewTestHooks(); - it("keeps only back and the current section in the header; selects sections in a sheet", async () => { + it("keeps the single-row header and opens a section menu beneath its title", async () => { mockMobileMedia(); const user = userEvent.setup(); const restart = vi.fn(); @@ -48,13 +48,16 @@ describe("Settings navigation on mobile", () => { expect(within(header).getAllByRole("button")).toHaveLength(2); const trigger = screen.getByRole("button", { name: "Settings: Models" }); await user.click(trigger); - const sheet = screen.getByRole("dialog", { name: "Settings" }); - expect(within(sheet).getByRole("button", { name: "Models", exact: true })) + const menu = screen.getByRole("menu", { name: "Settings sections" }); + expect(trigger).toHaveAttribute("aria-haspopup", "menu"); + expect(menu).toHaveAttribute("data-side", "bottom"); + expect(within(menu).getByRole("menuitem", { name: "Models", exact: true })) .toHaveAttribute("aria-current", "page"); - expect(within(sheet).getByRole("navigation", { name: "Settings sections" })).toBeVisible(); - expect(within(sheet).getByRole("button", { name: "Restart" })).toBeVisible(); - await user.click(within(sheet).getByRole("button", { name: "Appearance" })); - await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + expect(within(menu).getByRole("menuitem", { name: "Restart" })).toBeVisible(); + expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); + expect(screen.queryByRole("button", { name: "Close" })).not.toBeInTheDocument(); + await user.click(within(menu).getByRole("menuitem", { name: "Appearance" })); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); expect(screen.getByRole("button", { name: "Settings: Appearance" })).toHaveFocus(); expect(document.body.style.pointerEvents).not.toBe("none"); expect(restart).not.toHaveBeenCalled(); @@ -67,40 +70,74 @@ describe("Settings navigation on mobile", () => { const user = userEvent.setup(); render(); await user.click(screen.getByRole("button", { name: "Settings: Capabilities" })); - expect(screen.getByRole("button", { name: "Capabilities", exact: true })) + expect(screen.getByRole("menuitem", { name: "Capabilities", exact: true })) .toHaveAttribute("aria-current", "page"); - expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument(); + expect(screen.queryByRole("menuitem", { name: "Restart" })).not.toBeInTheDocument(); }); - it.each(["close", "escape", "outside"])("dismisses with %s and restores focus and pointer events", async (method) => { + it.each(["trigger", "escape"])("dismisses with %s and restores focus without locking the page", async (method) => { mockMobileMedia(); const user = userEvent.setup(); render(); const trigger = screen.getByRole("button", { name: "Settings: Models" }); await user.click(trigger); - if (method === "close") await user.click(screen.getByRole("button", { name: "Close" })); - else if (method === "escape") await user.keyboard("{Escape}"); - else { - // The real overlay is outside the modal content; ignore the locked page behind it. - const overlay = document.querySelector('[data-state="open"][aria-hidden="true"]'); - expect(overlay).not.toBeNull(); - await user.click(overlay!); - } - await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + expect(document.body.style.pointerEvents).not.toBe("none"); + if (method === "trigger") await user.click(trigger); + else await user.keyboard("{Escape}"); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); expect(trigger).toHaveFocus(); expect(document.body.style.pointerEvents).not.toBe("none"); }); - it("keeps manual restart in the sheet and closes it before handing off", async () => { + it("dismisses on an outside click without swallowing the back action", async () => { + mockMobileMedia(); + const user = userEvent.setup(); + const back = vi.fn(); + render(); + await user.click(screen.getByRole("button", { name: "Settings: Models" })); + const backButton = screen.getByRole("button", { name: "Back to chat" }); + await user.click(backButton); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); + expect(back).toHaveBeenCalledOnce(); + expect(backButton).toHaveFocus(); + expect(document.body.style.pointerEvents).not.toBe("none"); + }); + + it("supports keyboard section selection", async () => { + mockMobileMedia(); + const user = userEvent.setup(); + render(); + screen.getByRole("button", { name: "Settings: Models" }).focus(); + await user.keyboard("{ArrowDown}"); + expect(screen.getByRole("menuitem", { name: "Overview", exact: true })).toHaveFocus(); + await user.keyboard("{ArrowDown}{Enter}"); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); + expect(screen.getByRole("button", { name: "Settings: Appearance" })).toHaveFocus(); + }); + + it("opens and selects sections with touch taps", async () => { + mockMobileMedia(); + const user = userEvent.setup(); + render(); + const tap = (target: HTMLElement) => user.pointer([ + { keys: "[TouchA>]", target }, { keys: "[/TouchA]", target }, + ]); + await tap(screen.getByRole("button", { name: "Settings: Models" })); + await tap(screen.getByRole("menuitem", { name: "System", exact: true })); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); + expect(screen.getByRole("button", { name: "Settings: System" })).toBeVisible(); + }); + + it("keeps manual restart in the menu and closes it on selection", async () => { mockMobileMedia(); const user = userEvent.setup(); const restart = vi.fn(); render(); expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument(); await user.click(screen.getByRole("button", { name: "Settings: Models" })); - await user.click(screen.getByRole("button", { name: "Restart" })); + await user.click(screen.getByRole("menuitem", { name: "Restart" })); expect(restart).toHaveBeenCalledOnce(); - await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); expect(document.body.style.pointerEvents).not.toBe("none"); }); @@ -116,28 +153,29 @@ describe("Settings navigation on mobile", () => { const runningLabel = screen.getByRole("status").textContent!; expect(screen.getByRole("button", { name: runningLabel, exact: true })).toBeDisabled(); await user.click(screen.getByRole("button", { name: "Settings: Models" })); - expect(within(screen.getByRole("dialog")).getByRole("button", { name: runningLabel })).toBeDisabled(); + expect(within(screen.getByRole("menu")).getByRole("menuitem", { name: runningLabel })) + .toHaveAttribute("aria-disabled", "true"); await user.keyboard("{Escape}"); rerender(); expect(screen.queryByRole("status")).not.toBeInTheDocument(); expect(screen.queryByRole("button", { name: "Restart" })).not.toBeInTheDocument(); }); - it("releases the open sheet when crossing to desktop and does not reopen on return", async () => { + it("dismisses the open menu when crossing to desktop and does not reopen on return", async () => { const resize = mockMobileMedia(); const user = userEvent.setup(); const restart = vi.fn(); render(); await user.click(screen.getByRole("button", { name: "Settings: Models" })); resize(false); - await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + await waitFor(() => expect(screen.queryByRole("menu")).not.toBeInTheDocument()); expect(document.body.style.pointerEvents).not.toBe("none"); expect(screen.queryByRole("button", { name: "Settings: Models" })).not.toBeInTheDocument(); expect(screen.getByRole("button", { name: "Models", exact: true })).toBeVisible(); await user.click(screen.getByRole("button", { name: "Restart" })); expect(restart).toHaveBeenCalledOnce(); resize(true); - expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); + expect(screen.queryByRole("menu")).not.toBeInTheDocument(); expect(screen.getByRole("button", { name: "Settings: Models" })).toBeVisible(); }); @@ -149,7 +187,7 @@ describe("Settings navigation on mobile", () => { ...settingsPayload(), requires_restart: true, }, onBackToChat: back }); await user.click(screen.getByRole("button", { name: "Settings: Models" })); - await user.click(screen.getByRole("button", { name: "Appearance", exact: true })); + await user.click(screen.getByRole("menuitem", { name: "Appearance", exact: true })); await user.click(screen.getByRole("button", { name: "Back to chat" })); const dialog = screen.getByRole("dialog", { name: "Restart before leaving?" }); expect(back).not.toHaveBeenCalled();