Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkbox): add WCAG AA recommended minimum 24px square hotspot optimized for touch users #7773

Merged
merged 9 commits into from
Sep 20, 2023
111 changes: 111 additions & 0 deletions packages/calcite-components/src/components/checkbox/checkbox.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
labelable,
hidden,
} from "../../tests/commonTests";
import { html } from "../../../support/formatting";

describe("calcite-checkbox", () => {
describe("honors hidden attribute", () => {
Expand Down Expand Up @@ -167,4 +168,114 @@ describe("calcite-checkbox", () => {
shadowFocusTargetSelector: ".toggle",
});
});

describe("WCAG AA recommended minimum 24px click area", () => {
it("small checkbox allows clicks 5px around all sides", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-checkbox scale="s"></calcite-checkbox>`);
const checkbox = await page.find("calcite-checkbox");
const { left, top, right, bottom } = await page.evaluate(() =>
document.querySelector("calcite-checkbox").getBoundingClientRect().toJSON()
);

const maxExtraPixels = 5;

await page.mouse.click(left - maxExtraPixels, top - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, top + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(left - maxExtraPixels, bottom - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, bottom + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(right + maxExtraPixels + 1, bottom + maxExtraPixels + 1);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);
});

it("medium checkbox allows clicks 4px around all sides", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-checkbox scale="m"></calcite-checkbox>`);
const checkbox = await page.find("calcite-checkbox");
const { left, top, right, bottom } = await page.evaluate(() =>
document.querySelector("calcite-checkbox").getBoundingClientRect().toJSON()
);

const maxExtraPixels = 4;

await page.mouse.click(left - maxExtraPixels, top - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, top + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(left - maxExtraPixels, bottom - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, bottom + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(right + maxExtraPixels + 1, bottom + maxExtraPixels + 1);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);
});

it("large checkbox allows clicks 3px around all sides", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-checkbox scale="l"></calcite-checkbox>`);
const checkbox = await page.find("calcite-checkbox");
const { left, top, right, bottom } = await page.evaluate(() =>
document.querySelector("calcite-checkbox").getBoundingClientRect().toJSON()
);

const maxExtraPixels = 3;

await page.mouse.click(left - maxExtraPixels, top - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, top + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(left - maxExtraPixels, bottom - maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(true);

await page.mouse.click(right + maxExtraPixels, bottom + maxExtraPixels);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);

await page.mouse.click(right + maxExtraPixels + 1, bottom + maxExtraPixels + 1);
await page.waitForChanges();

expect(await checkbox.getProperty("checked")).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,23 @@
}

.toggle {
@apply focus-base;
@apply focus-base relative;

&:active,
&:focus,
&:focus-visible {
@apply focus-outset;
}

&::after {
content: "";
inset-block-start: 50%;
inset-inline-start: 50%;
min-block-size: theme("width.6");
min-inline-size: theme("width.6");
position: absolute;
transform: translateX(-50%) translateY(-50%);
}
}

@include disabled();
Expand Down
Loading