Skip to content

fix(lab): ThreeDChart accessible name, pausable rotation, keyboard camera - #4381

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

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

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes three accessibility issues in ThreeDChart (packages/lab/src/ThreeD/ThreeDChart.tsx) found by a11y scan #3:

  1. Unnamed svg root (serious, WCAG 1.1.1) — the root <svg> had no role, no accessible name, and no text alternative; screen readers announced nothing meaningful for the entire chart.
  2. Auto-rotation with no pause and no reduced-motion support (moderate, WCAG 2.2.2 / 2.3.3) — autoRotate ran a continuous rAF loop that never stopped and ignored prefers-reduced-motion.
  3. Pointer-only camera (moderate, WCAG 2.1.1) — the camera could only be rotated by mouse/touch drag; keyboard users had no equivalent.

Companion to the charts a11y PR (Chart/Radial/Sankey); this PR owns ThreeDChart.tsx exclusively, and the new label prop matches the naming and mechanism (role="img" + aria-label, derived default) used there.

Changes

  • Accessible name: root <svg> now has role="img" and aria-label from a new optional label prop, defaulting to a description derived from the data keys ("3D chart of {yKey} by {xKey} and {zKey}") — consistent with the Chart/Radial/Sankey defaults.
  • Reduced motion: auto-rotation is disabled entirely under prefers-reduced-motion: reduce, via the SSR-safe useMediaQuery hook from @astryxdesign/core/hooks (subscribes to matchMedia change events, so it reacts to live OS setting changes).
  • Pausable rotation: rotation pauses while the chart is hovered or focused (carousel-style pause) and resumes on leave/blur; the rAF loop is actually torn down (effect cleanup cancels the frame), not just skipped. The chart is focusable (tabIndex=0) whenever it auto-rotates so keyboard users can pause it too.
    • 2.2.2 reasoning: autoRotate is opt-in (default off) and decorative. With hover/focus pause giving users a way to stop the movement, reduced-motion respect, and the prop itself as the documented off switch (JSDoc updated), this satisfies 2.2.2's requirement for a mechanism to pause/stop non-essential moving content.
  • Keyboard camera (when interactive): ArrowLeft/ArrowRight rotate yaw, ArrowUp/ArrowDown rotate pitch, 10° per press, with the same [-89, 89] elevation clamp as pointer drag. Arrow keys call preventDefault() so the page does not scroll while the chart is focused; other keys are left alone. A static chart (no interaction, no rotation) gets no tab stop.

Test plan

New colocated suite packages/lab/src/ThreeD/ThreeDChart.test.tsx (15 tests), using the same ResizeObserver-driving pattern as SankeyChart.test.tsx plus a manual rAF queue and a camera probe child (use3D()) to observe angles:

  • svg named via default label and via custom label prop; static chart has no tabindex
  • reduced-motion (mocked matchMedia) prevents the rAF loop from ever being scheduled
  • hover and focus pause: cancelAnimationFrame spy fires, the queue empties, azimuth stops advancing, and rotation resumes on mouse-out/blur
  • arrow keys change yaw/pitch by 10° with clamping at ±89; keydown preventDefault asserted via fireEvent's return value (arrows prevented, other keys not); arrows ignored when not interactive

Commands (all pass):

  • node_modules/.bin/prettier --check on changed files — clean
  • node_modules/.bin/eslint on changed files — clean
  • node_modules/.bin/tsc --project packages/lab/tsconfig.json --noEmit — clean
  • node_modules/.bin/vitest run packages/lab/src/ThreeD --reporter=dot — 2 files, 51/51 passed
  • node_modules/.bin/vitest run packages/lab --reporter=dot — 20 files, 268/268 passed

Pre-fix failure confirmed: 14 of the 15 new tests fail against the unmodified component (the only passing one is the baseline "rotates when autoRotate is set" behavior check).

jsdom limitations: no real rendering/frame timing, so the rotation tests drive a stubbed rAF queue rather than real frames; visual smoothness of rotation and actual OS-level reduced-motion behavior were not manually verified in a browser. Manual check if desired: enable "reduce motion" in OS settings and confirm an autoRotate chart stays still; hover/focus it and confirm rotation pauses.

Notes

@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 Jul 30, 2026 8:01am

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 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

@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 6272b7a into meta:main Jul 30, 2026
20 checks passed
@github-actions
github-actions Bot deleted the a11y/lab-threed branch July 31, 2026 08:38

This branch was successfully deployed

1 active deployment
Preview — 6f4b9728 Deployed Jul 30, 2026 by vercel[bot]
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.

2 participants