From 207686a0d99aff877594c54a3106989f050a4c91 Mon Sep 17 00:00:00 2001 From: Oleg Isonen Date: Sun, 15 Nov 2026 16:01:53 +0000 Subject: [PATCH] fix: Keep checkbox size stable on hover (#6698) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The checkbox’s hover border becomes visible over its transparent resting border, making it look larger. This PR removes that hover border change while preserving fixed dimensions, the dark-mode fill from #6697, and the keyboard focus indicator. - [x] Remove the hover border color change from the shared Checkbox. - [x] Add a focused browser check that measures unchanged dimensions on real hover. - [x] Update the existing contrast test to expect the unchanged transparent hover border; keep the focus indicator check. - [x] Verify the old hover-border expectation fails and the updated tests pass. Full design-system browser suite passes (288 tests). - [x] Run focused browser tests, typecheck, lint, formatting, and diff checks. - [x] Review `docs/`; this internal visual adjustment needs no documentation update. --- .../src/components/checkbox.browser.test.tsx | 26 +++++++++++++++++++ .../design-system/src/components/checkbox.tsx | 4 --- .../form-control-contrast.browser.test.ts | 7 +++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/design-system/src/components/checkbox.browser.test.tsx b/packages/design-system/src/components/checkbox.browser.test.tsx index c71c8f5cff..3d0cf6b144 100644 --- a/packages/design-system/src/components/checkbox.browser.test.tsx +++ b/packages/design-system/src/components/checkbox.browser.test.tsx @@ -1,3 +1,4 @@ +import { page } from "@vitest/browser/context"; import { createRoot, type Root } from "react-dom/client"; import { act } from "react-dom/test-utils"; import { afterEach, expect, test } from "vitest"; @@ -52,3 +53,28 @@ test("consent checkboxes keep their size beside wrapped labels", () => { expect(top).toBe(rowTop); } }); + +test("checkbox keeps its size on hover", async () => { + const container = document.createElement("div"); + container.style.padding = "20px"; + document.body.append(container); + root = createRoot(container); + + act(() => { + root?.render(); + }); + + const checkbox = container.querySelector("button")!; + const restRect = checkbox.getBoundingClientRect(); + expect({ width: restRect.width, height: restRect.height }).toEqual({ + width: 14, + height: 14, + }); + + await page.elementLocator(checkbox).hover(); + const hoverRect = checkbox.getBoundingClientRect(); + expect({ width: hoverRect.width, height: hoverRect.height }).toEqual({ + width: restRect.width, + height: restRect.height, + }); +}); diff --git a/packages/design-system/src/components/checkbox.tsx b/packages/design-system/src/components/checkbox.tsx index e9613a23c2..c6e003ca6a 100644 --- a/packages/design-system/src/components/checkbox.tsx +++ b/packages/design-system/src/components/checkbox.tsx @@ -27,10 +27,6 @@ const checkboxStyle = css({ )})`, border: "1px solid transparent", - "&:hover": { - borderColor: cssVar("--border-default"), - }, - "&:focus-visible": { borderColor: cssVar("--border-focus"), }, diff --git a/packages/design-system/src/components/form-control-contrast.browser.test.ts b/packages/design-system/src/components/form-control-contrast.browser.test.ts index d48eae6b6b..c32b1fd174 100644 --- a/packages/design-system/src/components/form-control-contrast.browser.test.ts +++ b/packages/design-system/src/components/form-control-contrast.browser.test.ts @@ -158,7 +158,10 @@ test("compact form controls keep their intended contrast", async () => { await page.getByText("Neutral").hover(); expect(checkbox.matches(":hover, :focus-visible")).toBe(false); expectCheckboxBackground(checkbox, mode, "resting checkbox"); - expect(readColor(getComputedStyle(checkbox).borderColor)[3]).toBe(0); + const restingBorderColor = readColor( + getComputedStyle(checkbox).borderColor + ); + expect(restingBorderColor[3]).toBe(0); const checkedCheckbox = container.querySelector( '[aria-label="Checked checkbox"]' ); @@ -204,7 +207,7 @@ test("compact form controls keep their intended contrast", async () => { expect(checkbox.matches(":hover")).toBe(true); expectCheckboxBackground(checkbox, mode, "hovered checkbox"); expect(readColor(getComputedStyle(checkbox).borderColor)).toEqual( - readTokenColor("--border-default") + restingBorderColor ); act(() => checkedCheckbox.focus()); await act(async () => userEvent.keyboard("{Shift>}{Tab}{/Shift}"));