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}"));