fix(Switch): persistently mount busy live region and localize loading announcement (#6114) - #6125
fix(Switch): persistently mount busy live region and localize loading announcement (#6114)#6125Geervan wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsSwitch (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual RegressionStatus: No visual change across 2 compared shot(s). Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for this fix! This is very close. We'll likely want to use the useAnnounce pattern here over visually hidden.
| <VisuallyHidden role="status" aria-live="polite"> | ||
| {isBusy ? t('@astryx.switch.loading') : ''} | ||
| </VisuallyHidden> |
There was a problem hiding this comment.
We likely want to be using useAnnounce instead of VisuallyHidden which is the older pattern. The useAnnounce hook will include a stable live region and bypass the issue without introducing a permanent DOM element per switch.
|
Updated to use the Announcements now route through the shared singleton live region without introducing per-switch DOM nodes, let me know if I still missed any corners |
Fixes #6114.
Previously,
Switchrendered its busy announcement live region dynamically only whileisBusywas true ({isBusy && <VisuallyHidden role="status">Loading</VisuallyHidden>}). This caused two defects:"Loading"was hardcoded in English instead of going through theuseTranslatori18n system.This PR aligns
Switchwith the persistent live-region pattern used byButton:<VisuallyHidden role="status" aria-live="polite">so the container is always mounted.""when idle and dynamically updates it tot('@astryx.switch.loading')whenisBusyis true.@astryx.switch.loadingkey topackages/core/locales/en.json.Changes
packages/core/src/Switch/Switch.tsx: HookeduseTranslatorand converted the live region to be persistently mounted with dynamic translated text.packages/core/locales/en.json: Added@astryx.switch.loadingtranslation entry.packages/core/src/Switch/Switch.test.tsx: Added regression unit tests for:"Loading"whenisLoadingis enabled.InternationalizationProvideroverrides."Loading"during asyncchangeActiontransitions and clearing on resolution..changeset/switch-busy-announcement.md: Added changeset entry for patch release.Verification
npx vitest run packages/core/src/Switch/Switch.test.tsx(58/58 passed)node scripts/check-i18n-catalog.mjs(passed with 0 errors)npx vitest run packages/core/src/Button/Button.test.tsx packages/core/src/i18n/useTranslator.test.tsx(52/52 passed)node scripts/check-changesets.mjs(passed)