Skip to content

a11y(badge): add optional sr-only prefix and ensure labels are never color-only#470

Open
samjay8 wants to merge 1 commit into
CredenceOrg:mainfrom
samjay8:a11y/badge-sr-semantics
Open

a11y(badge): add optional sr-only prefix and ensure labels are never color-only#470
samjay8 wants to merge 1 commit into
CredenceOrg:mainfrom
samjay8:a11y/badge-sr-semantics

Conversation

@samjay8

@samjay8 samjay8 commented Jun 29, 2026

Copy link
Copy Markdown

Closes #444

Summary

Gives status badges screen-reader context (e.g. "Bond status: Slashed") without changing the visible API or contrast ratios.

Changes

src/components/Badge.tsx

  • Added srPrefix?: string prop - renders an .sr-only <span> before the visible label so assistive technology announces the badge in context (e.g. srPrefix="Bond status:" reads as "Bond status: Slashed"); no extra DOM when omitted
  • Added title attribute matching displayLabel for truncation tooltip support
  • Fixed trailing-space in badge root className concatenation (now uses .trim())

src/components/Badge.test.tsx

  • Replaced the misnamed file (which was testing Banner) with a correct Badge-specific test suite
  • Covers: all 9 known variants and their default labels, unknown-variant normalization and label fallback, label override, title attribute for all variants, className prop, srPrefix DOM and accessible-name assertions, and a color-only regression guard asserting every severity variant has a non-empty visible label

docs/COMPONENTS.md

  • Added srPrefix to the Badge props table with description and usage examples
  • Updated accessibility note to explain the title attribute and color-alone guidance

Test plan

  • npm run lint passes
  • npm run build passes
  • npm run test passes (? 95% Badge branch coverage)

…color-only

Gives status badges screen-reader context (e.g. "Bond status: Slashed") without
changing the visible API or contrast.

- Add srPrefix?: string prop — renders an .sr-only <span> before the visible
  label so assistive tech announces the badge in context; no extra DOM when omitted
- Add title attribute matching displayLabel for truncation tooltips
- Trim trailing whitespace from the badge root className concatenation
- Replace misnamed Badge.test.tsx (which tested Banner) with a correct Badge
  test suite covering: variant normalization, label override, title attribute,
  className, srPrefix DOM and accessible-name assertions, and a color-only
  regression guard that asserts every severity variant has a non-empty label
- Update docs/COMPONENTS.md Badge entry with srPrefix prop, usage example,
  and accessibility guidance

Closes CredenceOrg#444
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@samjay8 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make the Badge component announce status semantics to screen readers, not just color

1 participant