diff --git a/webui/src/components/settings/SkillsCatalogSettings.tsx b/webui/src/components/settings/SkillsCatalogSettings.tsx index 1bdf7643f..9a95d5e63 100644 --- a/webui/src/components/settings/SkillsCatalogSettings.tsx +++ b/webui/src/components/settings/SkillsCatalogSettings.tsx @@ -31,6 +31,7 @@ import { Input } from "@/components/ui/input"; import { SegmentedControl } from "@/components/ui/segmented-control"; import { Sheet, SheetContent, SheetDescription, SheetTitle } from "@/components/ui/sheet"; import { SkillsMarketplace } from "@/components/settings/SkillsMarketplace"; +import { ToggleButton } from "@/components/settings/ToggleButton"; import { deleteSkill, fetchSkillDetail, updateSkillEnabled } from "@/lib/api"; import { notifySkillsChanged } from "@/lib/skill-events"; import type { SkillDetail, SkillSummary } from "@/lib/types"; @@ -447,15 +448,13 @@ function SkillDetailSheet({ ) : (
-
+

{t("settings.skills.enabledControl", { defaultValue: "Use this skill" })}

- + onChange={() => void toggleEnabled()} + />
{actionError ? ( diff --git a/webui/src/components/settings/ToggleButton.tsx b/webui/src/components/settings/ToggleButton.tsx index 77fdd7875..3aed093a7 100644 --- a/webui/src/components/settings/ToggleButton.tsx +++ b/webui/src/components/settings/ToggleButton.tsx @@ -27,21 +27,21 @@ export function ToggleButton({ if (!disabled) onChange(!checked); }} className={cn( - "relative inline-flex h-[22px] w-[38px] shrink-0 items-center rounded-full p-[2px]", - "transition-colors duration-200 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", + "relative inline-flex h-5 w-9 shrink-0 items-center rounded-full p-0.5", + "after:absolute after:left-1/2 after:top-1/2 after:h-11 after:w-11 after:-translate-x-1/2 after:-translate-y-1/2 after:content-['']", + "transition-colors duration-200 ease-out motion-reduce:transition-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2", checked - ? "bg-[#2997FF]" - : "bg-muted-foreground/20 hover:bg-muted-foreground/25", + ? "bg-foreground" + : "bg-muted-foreground/25 hover:bg-muted-foreground/30", disabled && "cursor-default opacity-60", - disabled && checked && "hover:bg-[#2997FF]", - disabled && !checked && "hover:bg-muted-foreground/20", + disabled && !checked && "hover:bg-muted-foreground/25", )} > diff --git a/webui/src/components/settings/models/ModelsSettings.tsx b/webui/src/components/settings/models/ModelsSettings.tsx index 1e83f09e7..66578e170 100644 --- a/webui/src/components/settings/models/ModelsSettings.tsx +++ b/webui/src/components/settings/models/ModelsSettings.tsx @@ -1,4 +1,5 @@ import { ProviderIcon } from "@/components/settings/models/ProviderSettings"; +import { ToggleButton } from "@/components/settings/ToggleButton"; import { useAutoSave } from "@/components/settings/shared/useAutoSave"; import { useEffect, useId, useRef, useState, type Dispatch, type SetStateAction } from "react"; import { DisclosureContent } from "@/components/ui/disclosure"; @@ -794,36 +795,22 @@ export function ModelsSettings({ ) : ( )} - + />
); return ( diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx index 2ccd99949..856ce4dd7 100644 --- a/webui/src/tests/app-layout.test.tsx +++ b/webui/src/tests/app-layout.test.tsx @@ -1204,6 +1204,7 @@ describe("App layout", () => { expect(screen.getByText(/Use GitHub CLI/)).toBeInTheDocument(); const enabledSwitch = screen.getByRole("switch", { name: "Disable github" }); expect(enabledSwitch).toHaveAttribute("aria-checked", "true"); + expect(enabledSwitch).toHaveClass("h-5", "w-9", "bg-foreground"); fireEvent.click(enabledSwitch); await waitFor(() => { expect(screen.getByRole("switch", { name: "Enable github" })).toHaveAttribute( @@ -1211,6 +1212,7 @@ describe("App layout", () => { "false", ); }); + expect(screen.getByRole("switch", { name: "Enable github" })).toHaveClass("h-5", "w-9", "bg-muted-foreground/25"); }); it("deletes a custom skill from its detail sheet", async () => { diff --git a/webui/src/tests/settings-capabilities.test.tsx b/webui/src/tests/settings-capabilities.test.tsx index 75628da86..1d7823891 100644 --- a/webui/src/tests/settings-capabilities.test.tsx +++ b/webui/src/tests/settings-capabilities.test.tsx @@ -36,6 +36,8 @@ describe("Settings capabilities", () => { renderSettingsView({ initialSection: "capabilities", initialSettings: payload }); const memory = screen.getByRole("switch", { name: "Memory consolidation" }); const web = screen.getByRole("switch", { name: "Web access" }); + expect(memory).toHaveClass("h-5", "w-9", "bg-foreground"); + expect(web).toHaveClass("h-5", "w-9", "bg-foreground"); const webStyle = web.className; fireEvent.click(memory); await waitFor(() => expect(memory).toBeDisabled()); @@ -44,6 +46,7 @@ describe("Settings capabilities", () => { expect(web.className).toBe(webStyle); fireEvent.click(web); expect(web).not.toBeChecked(); + expect(web).toHaveClass("bg-muted-foreground/25"); await act(async () => finishMemory(memorySaved)); await waitFor(() => expect(requestMutationMock).toHaveBeenLastCalledWith( "settings.runtime_config.update", { values: { "tools.web.enable": false } }, 20_000, diff --git a/webui/src/tests/settings-models.test.tsx b/webui/src/tests/settings-models.test.tsx index 6366103e6..245ed5ec7 100644 --- a/webui/src/tests/settings-models.test.tsx +++ b/webui/src/tests/settings-models.test.tsx @@ -502,6 +502,7 @@ describe("Settings models", () => { const enableSwitch = within(codexRow).getByRole("switch", { name: "Enable preset" }); expect(enableSwitch).not.toBeChecked(); + expect(enableSwitch).toHaveClass("h-5", "w-9", "bg-muted-foreground/25"); fireEvent.click(enableSwitch); await waitFor(() => { @@ -516,6 +517,16 @@ describe("Settings models", () => { expect( within(enabledCodexRow).getByRole("switch", { name: "Disable preset" }), ).toBeChecked(); + expect(within(enabledCodexRow).getByRole("switch")).toHaveClass("h-5", "w-9", "bg-foreground"); + }); + + it("does not allow disabling the last preset", () => { + renderSettingsView({ initialSection: "models", initialSettings: settingsPayload() }); + const toggle = screen.getByRole("switch", { name: "Disable preset" }); + expect(toggle).toBeChecked(); + expect(toggle).toBeDisabled(); + fireEvent.click(toggle); + expect(requestMutationMock).not.toHaveBeenCalled(); }); it("appends a new model preset to the call order immediately", async () => { diff --git a/webui/src/tests/toggle-button.test.tsx b/webui/src/tests/toggle-button.test.tsx new file mode 100644 index 000000000..df15100ea --- /dev/null +++ b/webui/src/tests/toggle-button.test.tsx @@ -0,0 +1,68 @@ +import { fireEvent, render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { describe, expect, it, vi } from "vitest"; + +import { ToggleButton } from "@/components/settings/ToggleButton"; + +describe("ToggleButton", () => { + it("uses shared theme colors and compact dimensions in both states", () => { + const onChange = vi.fn(); + const { rerender } = render( + , + ); + const toggle = screen.getByRole("switch", { name: "Feature" }); + expect(toggle).toBeChecked(); + expect(toggle).toHaveClass("h-5", "w-9", "bg-foreground", "after:h-11", "after:w-11"); + expect(toggle.firstElementChild).toHaveClass("h-4", "w-4", "bg-background", "translate-x-[16px]"); + + fireEvent.click(toggle); + expect(onChange).toHaveBeenLastCalledWith(false); + rerender(); + expect(toggle).not.toBeChecked(); + expect(toggle).toHaveClass("h-5", "w-9", "bg-muted-foreground/25"); + expect(toggle).not.toHaveClass("bg-foreground"); + expect(toggle.firstElementChild).toHaveClass("translate-x-0"); + fireEvent.click(toggle); + expect(onChange).toHaveBeenLastCalledWith(true); + }); + + it.each([false, true])("does not toggle while disabled (checked=%s)", (checked) => { + const onChange = vi.fn(); + render(); + const toggle = screen.getByRole("switch", { name: "Feature" }); + expect(toggle).toBeDisabled(); + expect(toggle).toHaveClass(checked ? "bg-foreground" : "bg-muted-foreground/25", "opacity-60"); + fireEvent.click(toggle); + expect(onChange).not.toHaveBeenCalled(); + }); + + it("keeps accessible labeling, keyboard activation, and button semantics", async () => { + const user = userEvent.setup(); + const onChange = vi.fn(); + const onSubmit = vi.fn((event) => event.preventDefault()); + render( +
+

Enable this feature.

+ + , + ); + const toggle = screen.getByRole("switch", { name: "Enable feature" }); + expect(toggle).toHaveAttribute("id", "feature-toggle"); + expect(toggle).toHaveAccessibleDescription("Enable this feature."); + expect(toggle).toHaveAttribute("aria-invalid", "true"); + await user.tab(); + expect(toggle).toHaveFocus(); + await user.keyboard(" "); + await user.keyboard("{Enter}"); + expect(onChange.mock.calls).toEqual([[true], [true]]); + expect(onSubmit).not.toHaveBeenCalled(); + }); +});