shared: buttons answer hover, press and keyboard focus
.ui-button had a pointer cursor and nothing else: no hover, no pressed state and no focus style of its own. Each variant gets a hover fill, a press nudge and a purple focus ring, with the transition off under reduced motion.
This commit is contained in:
parent
76d2c5e788
commit
fdeb95a61b
1 changed files with 74 additions and 0 deletions
36
frontend/packages/swarm-ui/test/button-states.test.mjs
Normal file
36
frontend/packages/swarm-ui/test/button-states.test.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
// A button answers the pointer and the keyboard. Run by `npm test`. The shared
|
||||
// stylesheet must give every variant a hover, a pressed and a keyboard focus
|
||||
// state, and switch its transition off under reduced motion.
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { test } from "node:test";
|
||||
|
||||
const css = readFileSync(
|
||||
new URL("../../shared/src/button/Button.css", import.meta.url),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
for (const variant of ["default", "primary", "danger"]) {
|
||||
test(`the ${variant} button has a hover state`, () => {
|
||||
assert.match(
|
||||
css,
|
||||
new RegExp(`\\.ui-button-${variant}:hover:not\\(:disabled\\)`),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
test("a button has a pressed and a keyboard focus state", () => {
|
||||
assert.match(css, /\.ui-button:active:not\(:disabled\)/);
|
||||
assert.match(css, /\.ui-button:focus-visible\s*\{[^}]*outline:/);
|
||||
});
|
||||
|
||||
test("the transition is off under reduced motion", () => {
|
||||
assert.match(
|
||||
css,
|
||||
/prefers-reduced-motion: reduce\)\s*\{\s*\.ui-button\s*\{\s*transition:\s*none/,
|
||||
);
|
||||
assert.match(
|
||||
css,
|
||||
/:root\[data-motion="reduce"\] \.ui-button\s*\{\s*transition:\s*none/,
|
||||
);
|
||||
});
|
||||
Loading…
Reference in a new issue