Skip to content

fix(lab): accessible names and data-table fallbacks for charts - #4382

Merged
cixzhang merged 1 commit into
meta:mainfrom
bhamodi:a11y/lab-chart-names
Jul 30, 2026
Merged

cixzhang merged 1 commit into
meta:mainfrom
bhamodi:a11y/lab-chart-names

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Charts were invisible to assistive technology (a11y scan finding #3, severity SERIOUS, WCAG 1.1.1 Non-text Content). The root <svg> elements of the lab charts had no role="img", no accessible name, no <title>, and no text alternative for the plotted data -- a screen reader user got nothing at all from a Chart or RadialChart, and Sankey was only named when it happened to need horizontal scrolling.

This PR gives every chart root an accessible name and, for modest datasets, a visually hidden data-table text alternative (using the core VisuallyHidden primitive), so the underlying values are readable by assistive tech.

Lab has no i18n mechanism (other lab components use Intl for dates only, English strings elsewhere), so defaults are English and every chart accepts a label prop override for localized names. This is documented on each prop.

Changes

  • Chart (packages/lab/src/Chart/Chart.tsx) -- svg now has role="img" + aria-label. New label prop; defaults to "Chart of {yKeys} by {xKey}". Visually hidden table (x column + one column per y key) rendered when rows x series <= 100 points (documented MAX_TABLE_POINTS cutoff -- beyond that a table is more noise than signal, name-only).
  • RadialChart (packages/lab/src/Radial/RadialChart.tsx) -- svg now has role="img" + aria-label. New label prop; defaults to "Radar chart of {axes}" (spider) / "Pie chart of {valueKey}" (pie). Hidden table: pie mode lists label/value/percentage per slice; spider mode lists one row per series across the axes (row header uses the same first-string-field heuristic RadialArea uses for dataKey). Same <=100-point cutoff.
  • SankeyChart (packages/lab/src/Sankey/SankeyChart.tsx) -- svg now has role="img" + aria-label in both the scrolling and non-scrolling paths (previously only the scroll wrapper from fix(lab): accessibility cleanup for CodeEditor, SankeyChart, and Schedule #3549 was named, and only when scrolling). New label prop (default 'Sankey chart') feeds both the svg and the scroll region. Hidden From/To/Value table of links (node labels resolved from node defs), <=100 links cutoff.
  • Chart v2 (packages/charts/src/Chart.tsx) -- had the same gap, partially: aria-label only when title was set, and never role="img". Now always role="img" with aria-label = title ?? "Chart of {series labels} by {xKey}" (per the convention, the existing title prop is preferred as the name -- no new prop). Same hidden data table (columns = union of primary series dataKeys, utility marks excluded), <=100-point cutoff.
  • vitest.config.ts -- added packages/charts to the ui test project (it previously fell through to the DOM-less node project, exactly the migration path the config's partitioning comment prescribes) and mapped the bare @astryxdesign/core specifier to source so charts' runtime core imports resolve in tests.

Table-vs-name-only rationale per chart: Chart/Radial/charts-v2 receive structured rows/slices, so a table is meaningful; Sankey's graph is flattened to its links (source, target, value), which is the standard text serialization of a flow diagram.

Test plan

New tests (15 new assertions-bearing tests across 4 files) were written first and confirmed failing pre-fix: 15 failed | 6 passed (the 6 = 2 pre-existing Sankey scroll tests + 4 over-cutoff negatives that are trivially true pre-fix).

Post-fix:

  • prettier --check on all 9 changed files -- clean
  • eslint on all 9 changed files -- clean
  • tsc --project packages/lab/tsconfig.json --noEmit -- 0 errors
  • tsc --project packages/charts/tsconfig.json --noEmit -- 0 errors
  • vitest run packages/lab/src/Chart packages/lab/src/Radial packages/lab/src/Sankey packages/charts/src -- 8 files, 47 tests passed
  • vitest run packages/lab -- 21 files, 268 tests passed
  • node scripts/check-changesets.mjs -- passes (44 changesets valid)

Coverage per chart: svg has role="img" + accessible name (default and custom label); data table renders with correct values for a small dataset and is visually hidden (StyleX clip class, not display:none/hidden); table skipped over the cutoff; Sankey named in both scroll and no-scroll paths, custom label applied to both svg and scroll region.

Notes

  • No changeset: both @astryxdesign/lab and @astryxdesign/charts are private: true; scripts/check-changesets.mjs rejects them ("private/ignored and cannot be released"), verified empirically. Per the checker's guidance, private packages are changeset-exempt.
  • ThreeDChart is intentionally not touched here -- it is handled in a separate PR (fix(lab): ThreeDChart accessible name, pausable rotation, keyboard camera #4381) using the same label + role="img" convention.
  • The Vercel deployment failure on fork PRs is known infra and unrelated.

@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 26, 2026 5:08am

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge needs:design-review Affects visuals — Design should review labels Jul 26, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 26, 2026
@github-actions

github-actions Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@bhamodi
bhamodi force-pushed the a11y/lab-chart-names branch from a34830f to c8fd4ee Compare July 30, 2026 07:59
@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Jul 30, 2026
github-actions Bot added a commit that referenced this pull request Jul 30, 2026

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think geo had this so good to see it brought in.

@cixzhang
cixzhang enabled auto-merge (squash) July 30, 2026 22:09
@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 30, 2026
@cixzhang
cixzhang merged commit bd18aee into meta:main Jul 30, 2026
18 checks passed
@github-actions
github-actions Bot deleted the a11y/lab-chart-names branch July 31, 2026 08:38
AKnassa added a commit to AKnassa/astryx that referenced this pull request Aug 27, 2026
The eight add/add conflicts resolved to main's files in the merge; this
ports back only the assertions main does not cover and that still hold
today (render gates and sizing, layer groups and masks, style restore,
registry glyph, xstyle forwarding, context guards). Duplicates of main's
coverage are dropped rather than kept twice.

Four files went stale over the 815-commit gap and follow today's
behavior: the hidden data-table fallback (meta#4382) means chart label and
tooltip queries scope to the svg; useTooltip's touch guard is per
pointer type (meta#5248) and a controlled tooltip reports Escape through
onHide (meta#4881); TableHeaderCell dividers are logical inline-end
properties (meta#4434).
cixzhang pushed a commit that referenced this pull request Sep 3, 2026
…sted viz packages and hooks (#4295) (#4377)

* test: cover the viz packages and five core hooks

packages/charts and packages/vega had no functional tests at all, and
packages/lab's chart primitives (Chart*, Radial*, ThreeD*, Sankey*,
SVGIcon) rendered nothing under test. Add colocated tests for each, plus
renderHook tests for the three useCalendar* hooks, useCollapsible and
useTableFilterState.

Harness: charts and vega were falling through to the `node` vitest
project, which has no jsdom, no StyleX transform and no jest-dom, so
their tests could never have run there. Move both into the `ui` project
and give vega the test scripts the other packages already have.

53 test files, 307 tests. Verified: full suite 7943 pass / 430 files,
still green with packages/core/dist absent (the cold-CI path, which
charts needs because it imports core by bare name for values); 8 sampled
mutations across all four packages, each killed by exactly the new test.

Refs #4295

* test: cover remaining core hooks and components

Finishes the functional-coverage sweep started in 64d9ea3. Adds
renderHook tests for useScrollLock, useLightbox, useChatPasteAsToken,
useImperativeAlertDialog, useTranslator and useTooltip, plus colocated
tests for the components that had none: CommandPaletteEmpty,
InputClearButton, TypeaheadItem, ChatSendButton, PowerSearchToken,
PowerSearchFilterEditor and TableHeaderCell.

Two of the issue's nine "zero-test" components already had tests
(ChatComposerDrawer, MobileNavToggle, from #3996 and #3721), so the
inventory is smaller than the issue states.

Extracts the StyleX declaration read-back helper that three of these
files each needed into __tests__/stylexDeclarations.ts rather than
landing a third copy.

Two branches are deliberately left uncovered, with the reason recorded
next to them: the ignored-onOpenChange(true) guards in useLightbox and
useImperativeAlertDialog are unreachable through the public surface,
and reaching into element props to force them both breaks the repo's
no-react-introspection lint rule and asserts a value that is already
settled. useTooltip's focus paths are also omitted -- jsdom resolves
:focus-visible as :focus, so those tests would pass with the gate
deleted.

Verified: 8101 tests / 443 files green, eslint and prettier clean,
core typecheck clean; three sampled mutations (the send-button variant
ternary, CommandPaletteEmpty's xstyle merge, useTooltip's touch
suppression) each killed by exactly one new test.

Refs #4295

* test: port the branch's remaining assertions onto main's test files

The eight add/add conflicts resolved to main's files in the merge; this
ports back only the assertions main does not cover and that still hold
today (render gates and sizing, layer groups and masks, style restore,
registry glyph, xstyle forwarding, context guards). Duplicates of main's
coverage are dropped rather than kept twice.

Four files went stale over the 815-commit gap and follow today's
behavior: the hidden data-table fallback (#4382) means chart label and
tooltip queries scope to the svg; useTooltip's touch guard is per
pointer type (#5248) and a controlled tooltip reports Escape through
onHide (#4881); TableHeaderCell dividers are logical inline-end
properties (#4434).

* test(calendar): assert month labels as English literals

CI's lint job fails on the one raw Intl call left in these tests:
main's no-raw-intl-locale rule keeps its test-oracle allowlist inside
the rule, and this file is not on it. The oracle was also the wrong
side: with no InternationalizationProvider mounted, useLocale() resolves
to 'en', so the hook's labels never followed the machine locale that
Intl.DateTimeFormat(undefined) reads. Literal 'April 2026' style
assertions match Calendar.test.tsx and drop the Intl dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants