Repository navigation
fix(core): announce CodeBlock copy success to screen readers - #3709
Conversation
|
@bhamodi is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
Copy success was conveyed only by swapping the copy button's aria-label
(Copy code -> Copied), which assistive tech does not reliably announce.
Add a polite useAnnounce("Copied") on successful copy.
Test plan:
- pnpm -F @astryxdesign/core exec vitest run src/CodeBlock/CodeBlock.test.tsx
(10 pass, incl. new 'announces "Copied" to a polite live region after copying')
- core typecheck + eslint on changed files: clean
ea69915 to
ef2fb92
Compare
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for this — clean fix. announce('Copied') fires imperatively inside the copy click handler, so it's one announcement per explicit user action, with no effect and no mount-time behavior to worry about. Swapping the button's aria-label alone is indeed unreliable across screen readers, so the polite live region is the right call.
This is the pattern I'd point the other announcement PRs at: announce at the interaction site, not from an effect watching derived state.
Approving.
PR: #3709 — fix(core): announce CodeBlock copy success to screen readers · Author: @bhamodi · What it does: confirms a successful copy via a polite live region · Recommendation: approve
Summary
CodeBlock's copy button signalled success only by swapping its accessible name (aria-label:Copy code→Copied) and a local timeout. Changing a focused element'saria-labelis not reliably announced by screen readers, so blind users got no confirmation the copy happened.This adds a polite
useAnnounce("Copied")on successful copy — the same live-region primitivePaginationand others use. Additive; the visual/label behavior is unchanged.Changes
CodeBlock/CodeBlock.tsx: importuseAnnounce; announce"Copied"afternavigator.clipboard.writeTextsucceeds; addannounceto thehandleCopydependency array.Test plan
pnpm -F @astryxdesign/core exec vitest run src/CodeBlock/CodeBlock.test.tsx— 10 pass, including a new test:announces "Copied" to a polite live region after copying— clicks copy andwaitFors the polite live region ([data-astryx-live-region="polite"]) to contain "Copied". Uses__resetLiveRegionsForTestinafterEach.tsc --project packages/core/tsconfig.json --noEmit— clean.eslinton changed files — clean (no exhaustive-deps warning).Notes
Found during a broader a11y audit of core components. One fix per PR.