From 7e6972a191ee4957cad49ddce0e076870a51372b Mon Sep 17 00:00:00 2001 From: iris Date: Sat, 28 Nov 2026 02:20:23 +0100 Subject: [PATCH] shared: a busy button keeps its accessible name The busy state hid the label with visibility: hidden, which takes it out of the accessibility tree, so axe reports a button with no name while it works. The label is opacity: 0 now; the button stays aria-busy and disabled. --- frontend/packages/shared/src/button/Button.css | 6 ++++-- .../swarm-ui/test/button-busy.test.mjs | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 frontend/packages/swarm-ui/test/button-busy.test.mjs diff --git a/frontend/packages/shared/src/button/Button.css b/frontend/packages/shared/src/button/Button.css index 0d0e7cb5e..fe30b8f11 100644 --- a/frontend/packages/shared/src/button/Button.css +++ b/frontend/packages/shared/src/button/Button.css @@ -32,9 +32,11 @@ .ui-button { position: relative; } -/* Busy: the label keeps its space, hidden, and the spinner sits over it. */ +/* Busy: the label keeps its space, invisible, and the spinner sits over it. + `opacity`, not `visibility`: the label stays in the accessibility tree, so the + button keeps its name (the button is `aria-busy` and disabled). */ .ui-button-busy .ui-button-label { - visibility: hidden; + opacity: 0; } .ui-button-spinner { position: absolute; diff --git a/frontend/packages/swarm-ui/test/button-busy.test.mjs b/frontend/packages/swarm-ui/test/button-busy.test.mjs new file mode 100644 index 000000000..62bae6ccb --- /dev/null +++ b/frontend/packages/swarm-ui/test/button-busy.test.mjs @@ -0,0 +1,18 @@ +// A busy button hides its label under the spinner. Run by `npm test`. The label +// has to stay in the accessibility tree (`visibility: hidden` and `display: none` +// take it out), or a busy button has no name. +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", +); + +test("a busy button's label stays in the accessibility tree", () => { + const rule = /\.ui-button-busy \.ui-button-label \{([^}]*)\}/.exec(css); + assert.ok(rule, "no rule for the busy label"); + assert.match(rule[1], /opacity:\s*0/); + assert.doesNotMatch(rule[1], /visibility:\s*hidden|display:\s*none/); +});