Skip to content

fix(core): expose aria-expanded and aria-controls on MobileNav toggle - #3721

Merged
nynexman4464 merged 1 commit into
meta:mainfrom
bhamodi:a11y/mobilenav-toggle-expanded
Jul 23, 2026
Merged

nynexman4464 merged 1 commit into
meta:mainfrom
bhamodi:a11y/mobilenav-toggle-expanded

Conversation

@bhamodi

@bhamodi bhamodi commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MobileNavToggle rendered a Button with an aria-label and onClick, but exposed no aria-expanded and no aria-controls (packages/core/src/MobileNav/MobileNavToggle.tsx). Screen-reader users had no way to tell whether the nav drawer was currently open, nor which element the hamburger button controls.

Making aria-controls resolve required a shared id, which did not exist: the AppShell mobile context (useAppShellMobile()) exposed no drawer id, and the MobileNav <dialog> had no id at all. This wires that up end to end:

  • AppShell generates a stable useId() and publishes it on the mobile context as mobileNavId.
  • MobileNav applies that id to its <dialog> (falling back to a locally generated useId() when used standalone outside AppShell).
  • MobileNavToggle sets aria-expanded={isMobileNavOpen} and aria-controls={mobileNavId || undefined}.

aria-controls is set whenever the id resolves: the native <dialog> stays in the DOM whenever the layout is below the mobile breakpoint -- it is mounted via React <Activity mode="hidden"> (or a plain fragment fallback) and simply hidden when closed -- so the referenced id always resolves inside an AppShell. Purely additive; no behavior or visual change.

mobileNavId is optional on AppShellMobileContextValue (mobileNavId?: string) and is applied entirely internally, so adding it is not a breaking change: callers that construct the context by hand do not need to supply it. When absent (standalone MobileNav, or a hand-built context), MobileNav falls back to its own useId() and the toggle drops aria-controls.

Changes

  • MobileNav/MobileNavToggle.tsx: forward aria-expanded + aria-controls from context onto the toggle button.
  • MobileNav/MobileNav.tsx: apply the shared mobileNavId (with a standalone useId() fallback) as the <dialog> id.
  • AppShell/AppShell.tsx + AppShell/AppShellMobileContext.tsx: generate and publish mobileNavId on the mobile context, as an optional field (omitted from the default context value).
  • AppShell/useAppShellMobile.doc.mjs: document the new (optional) mobileNavId return field.

Test plan

  • node_modules/.bin/vitest run --root . packages/core/src/MobileNav packages/core/src/AppShell packages/core/src/SideNav packages/core/src/TopNav -- 212 pass, including three new tests in MobileNavToggle.test.tsx:
    • exposes aria-expanded="false" when the drawer is closed
    • exposes aria-expanded="true" after opening the drawer
    • references the nav drawer via aria-controls that resolves to the dialog -- asserts the toggle's aria-controls resolves via document.getElementById to the <dialog> element.
  • node_modules/.bin/tsc --project packages/core/tsconfig.json --noEmit -- clean on changed files.

Notes

Found during a broader a11y audit of core components; scoped to one fix per PR. Button forwards arbitrary aria-* props to the underlying <button>, so aria-controls reaches the DOM. Making mobileNavId optional means no existing surface that interacts with the mobile context has to change -- the SideNav test and the MobileNavToggle example blocks that an earlier revision had to update are back to untouched. Rebased onto latest main.

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

@bhamodi is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 9, 2026
@bhamodi
bhamodi force-pushed the a11y/mobilenav-toggle-expanded branch from 25691b5 to 89c294e Compare July 9, 2026 06:09
* DOM id of the mobile nav drawer. Shared so the toggle can point its
* `aria-controls` at the drawer and the drawer can apply it as its `id`.
*/
mobileNavId: string;

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.

Since we're adding a new required property this can result in breaking surfaces currently interacting with this context. One way to tell is how we needed to update the tests and example Calais despite them not needing to apply the Aria controls. Curious if you think this is worth the breaking change? Otherwise we could make this optional and remember to apply the ID internally. The accessibility aspect is not fully realized until the toggle for the mobile nav is also consuming this ID.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call -- made it optional. mobileNavId?: string is now optional on AppShellMobileContextValue and dropped from the default context value, so it's no longer a breaking change: any surface that constructs this context by hand compiles without it. To prove that out, I reverted the fixture edits this originally forced -- SideNav.test.tsx and the two MobileNavToggle example blocks are back to untouched.

The id is still applied entirely internally, so the a11y wiring is fully realized with no work required from callers:

  • AppShell generates the id (useId()) and publishes it on the context.
  • MobileNav applies it as the <dialog> id, falling back to a locally generated useId() when used standalone.
  • MobileNavToggle sets aria-controls={mobileNavId || undefined} (dropped cleanly when absent) and aria-expanded.

So inside an AppShell the toggle consumes the id and points aria-controls at the drawer (the accessibility aspect is realized); outside one, nothing breaks and the toggle just omits aria-controls.

@github-actions github-actions Bot added 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 11, 2026
@github-actions
github-actions Bot requested a review from cixzhang July 11, 2026 18:30
@github-actions github-actions Bot added the community Authored by a community contributor (not on the eng/design team) label Jul 11, 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.

Back to you for the breaking feedback

@bhamodi
bhamodi force-pushed the a11y/mobilenav-toggle-expanded branch from 89c294e to d17dcb4 Compare July 14, 2026 02:02
@vercel

vercel Bot commented Jul 14, 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 23, 2026 8:35pm

Request Review

@github-actions github-actions Bot removed the needs:design-review Affects visuals — Design should review label Jul 14, 2026
@github-actions
github-actions Bot requested a review from cixzhang July 14, 2026 02:03
@bhamodi

bhamodi commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @cixzhang -- addressed the breaking feedback and rebased onto latest main.

Not a breaking change anymore. mobileNavId is now optional (mobileNavId?: string) on AppShellMobileContextValue and removed from the default context value. The id is still generated and applied entirely internally -- AppShell publishes it, MobileNav applies it to the <dialog> (falling back to a local useId() standalone), and MobileNavToggle consumes it via aria-controls={mobileNavId || undefined}. Callers that build the context by hand no longer have to supply it, so I reverted the edits this had forced onto SideNav.test.tsx and the two MobileNavToggle example blocks -- they're back to untouched, which is the proof the breaking surface is gone.

Rebase. Resolved a conflict in MobileNav.tsx where the <dialog> was refactored upstream to use mergeProps / composeEventHandlers; the only addition there now is id={dialogId}.

Verification:

  • vitest run packages/core/src/MobileNav packages/core/src/AppShell packages/core/src/SideNav packages/core/src/TopNav -- 212 pass.
  • vitest run packages/core -- full suite green.
  • tsc --noEmit + eslint on changed files -- clean.

Back to you!

@github-actions

github-actions Bot commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Modified Components

AppShell
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 556 -
Complexity N/A Very High (91) -
MobileNav
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 376 -
Complexity N/A Very High (39) -

Bundle Size Summary

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

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

AppShell - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 9/10 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | View full report

@cixzhang

Copy link
Copy Markdown
Contributor

Thanks this looks good!

@cixzhang

cixzhang commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

There some merge conflicts preventing merge so may need to rebase again. Sorry for the wait.

@bhamodi
bhamodi force-pushed the a11y/mobilenav-toggle-expanded branch from d17dcb4 to b2325ce Compare July 23, 2026 13:23
@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 23, 2026
@bhamodi
bhamodi force-pushed the a11y/mobilenav-toggle-expanded branch from b2325ce to 98dc1b3 Compare July 23, 2026 13:34
@bhamodi
bhamodi force-pushed the a11y/mobilenav-toggle-expanded branch from 98dc1b3 to a85f209 Compare July 23, 2026 20:31
@nynexman4464
nynexman4464 merged commit d84a353 into meta:main Jul 23, 2026
19 checks passed
@github-actions
github-actions Bot deleted the a11y/mobilenav-toggle-expanded branch July 24, 2026 08:12
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.

This branch was successfully deployed

1 active deployment
Preview — a85f2091 Deployed Jul 23, 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.

3 participants