Repository navigation
fix(core): expose aria-expanded and aria-controls on MobileNav toggle - #3721
Conversation
|
@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. |
25691b5 to
89c294e
Compare
| * 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
AppShellgenerates the id (useId()) and publishes it on the context.MobileNavapplies it as the<dialog>id, falling back to a locally generateduseId()when used standalone.MobileNavTogglesetsaria-controls={mobileNavId || undefined}(dropped cleanly when absent) andaria-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.
cixzhang
left a comment
There was a problem hiding this comment.
Back to you for the breaking feedback
89c294e to
d17dcb4
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Thanks @cixzhang -- addressed the breaking feedback and rebased onto latest Not a breaking change anymore. Rebase. Resolved a conflict in Verification:
Back to you! |
PR Analysis ReportModified ComponentsAppShell
MobileNav
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. AppShell - 1 issue(s)
Generated by PR Enrichment workflow | View full report |
|
Thanks this looks good! |
|
There some merge conflicts preventing merge so may need to rebase again. Sorry for the wait. |
d17dcb4 to
b2325ce
Compare
b2325ce to
98dc1b3
Compare
98dc1b3 to
a85f209
Compare
…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.
Summary
MobileNavTogglerendered aButtonwith anaria-labelandonClick, but exposed noaria-expandedand noaria-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-controlsresolve required a shared id, which did not exist: the AppShell mobile context (useAppShellMobile()) exposed no drawer id, and theMobileNav<dialog>had noidat all. This wires that up end to end:AppShellgenerates a stableuseId()and publishes it on the mobile context asmobileNavId.MobileNavapplies that id to its<dialog>(falling back to a locally generateduseId()when used standalone outside AppShell).MobileNavTogglesetsaria-expanded={isMobileNavOpen}andaria-controls={mobileNavId || undefined}.aria-controlsis 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.mobileNavIdis optional onAppShellMobileContextValue(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 (standaloneMobileNav, or a hand-built context),MobileNavfalls back to its ownuseId()and the toggle dropsaria-controls.Changes
MobileNav/MobileNavToggle.tsx: forwardaria-expanded+aria-controlsfrom context onto the toggle button.MobileNav/MobileNav.tsx: apply the sharedmobileNavId(with a standaloneuseId()fallback) as the<dialog>id.AppShell/AppShell.tsx+AppShell/AppShellMobileContext.tsx: generate and publishmobileNavIdon the mobile context, as an optional field (omitted from the default context value).AppShell/useAppShellMobile.doc.mjs: document the new (optional)mobileNavIdreturn 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 inMobileNavToggle.test.tsx:exposes aria-expanded="false" when the drawer is closedexposes aria-expanded="true" after opening the drawerreferences the nav drawer via aria-controls that resolves to the dialog-- asserts the toggle'saria-controlsresolves viadocument.getElementByIdto 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.
Buttonforwards arbitraryaria-*props to the underlying<button>, soaria-controlsreaches the DOM. MakingmobileNavIdoptional means no existing surface that interacts with the mobile context has to change -- the SideNav test and theMobileNavToggleexample blocks that an earlier revision had to update are back to untouched. Rebased onto latestmain.