mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-12-01 21:05:42 +09:00
fix: Keep checkbox size stable on hover (#6698)
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.
This commit is contained in:
1 parent
2969494b1e
commit
207686a0d9
3 files changed
+31
-6
No files matched your search
@@ -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(<Checkbox aria-label="Selection" />);
|
||||
});
|
||||
|
||||
const checkbox = container.querySelector<HTMLButtonElement>("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,
|
||||
});
|
||||
});
|
||||
@@ -27,10 +27,6 @@ const checkboxStyle = css({
|
||||
)})`,
|
||||
border: "1px solid transparent",
|
||||
|
||||
"&:hover": {
|
||||
borderColor: cssVar("--border-default"),
|
||||
},
|
||||
|
||||
"&:focus-visible": {
|
||||
borderColor: cssVar("--border-focus"),
|
||||
},
|
||||
|
||||
@@ -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<HTMLButtonElement>(
|
||||
'[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}"));
|
||||
|
||||
Reference in new issue
Block a user