Skip to content

feat(a11y): fallback <desc> generators for core charts (#119)#129

Merged
Ben Severn (benzsevern) merged 2 commits into
mainfrom
feat/119-a11y-fallback-desc
May 28, 2026
Merged

feat(a11y): fallback <desc> generators for core charts (#119)#129
Ben Severn (benzsevern) merged 2 commits into
mainfrom
feat/119-a11y-fallback-desc

Conversation

@benzsevern
Copy link
Copy Markdown
Collaborator

Summary

  • New src/core/a11yDescribe.ts with describeBars / describeSeries / describePie / describeScatter — short, deterministic, dependency-free sentences summarising chart shape.
  • BarChart, LineChart, AreaChart, PieChart, ScatterPlot now fall back to the generator when description is omitted, so the <desc> tag always carries something useful for screen readers.
  • New src/components/a11y.test.ts covers role="img", fallback <desc>, explicit-description precedence, and aria-label falling back to title.
  • a11yDescribe.test.ts covers each generator (singular nouns, empty data, multi-series, decimal trimming).

Why this is narrower than the issue

The original #119 spec assumed a11y plumbing was missing. Audit showed Surface already wires role / <title> / <desc> / aria-label / SR-only data table, and 14 of 15 chart components forward those props. The real remaining gap was: no fallback <desc> when consumers don't pass description, and no a11y test coverage. This PR closes both.

I narrowed the issue body before this PR; dataTable forwarding through diagrams (custom DataTableModel per diagram type) is now the follow-up tracked there.

Verification

  • npm run typecheck clean
  • npm test — 395 existing tests pass + 17 new
  • npm run build && npm run check:bundle — browser entry 48 KB gzipped (budget 75 KB), no font leak

Test plan

  • Typecheck clean
  • Full test suite green (75 files, 412 tests)
  • Bundle guard green
  • CI green

Closes the narrowed scope of #119.

Surface already wires role/title/desc/aria-label; the gap was that
charts only emitted <desc> when the consumer passed `description`.
Adds per-chart-type fallback generators so screen-reader users get
a useful one-liner from the data when no description is provided.

- new src/core/a11yDescribe.ts: describeBars / describeSeries /
  describePie / describeScatter
- BarChart, LineChart, AreaChart, PieChart, ScatterPlot fall back to
  the generator when `description` is omitted
- new src/components/a11y.test.ts covers role=img, fallback <desc>,
  explicit-description precedence, and aria-label falling back to title
- a11yDescribe.test.ts covers each generator (singular nouns, empty
  data, multi-series, decimal formatting)

Bundle stays at 48 KB gzipped (budget 75 KB). All 395 existing tests
pass plus 17 new.

Follow-up tracked in #119: dataTable forwarding through diagrams
(custom DataTableModel per diagram type).
@benzsevern Ben Severn (benzsevern) merged commit e105569 into main May 28, 2026
5 checks passed
@benzsevern Ben Severn (benzsevern) deleted the feat/119-a11y-fallback-desc branch May 28, 2026 16:32
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.

1 participant