-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
A11y: Add aria-selected attribute to tab buttons #32656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes screen reader announcing incorrect selected state on non-selected tabs. Added aria-selected and tabIndex attributes to TabButton components to properly communicate tab state to assistive technologies like Windows Narrator. Fixes storybookjs#32654
fix(a11y): add aria-selected attribute to tab buttons
📝 WalkthroughWalkthroughAdds aria-selected attribute to TabButton elements in the Tabs component to reflect each tab’s active state. No other behavior changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
code/core/src/components/components/tabs/tabs.tsx (1)
230-230: LGTM! The accessibility fix is correct.Adding
aria-selected={active}properly communicates the selected state to assistive technologies. React automatically converts the boolean value to the string "true" or "false" required by the ARIA spec, so this implementation is correct.For complete WCAG/ARIA tab pattern compliance, consider also adding
aria-controlsto link each tab to its corresponding panel:role="tab" aria-selected={active} + aria-controls={`panel-${sanitize(id) ?? indexId}`} >And ensure the corresponding tab panels (rendered in
Content) haverole="tabpanel"andaria-labelledbyattributes. This is a broader enhancement beyond the current fix.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
code/core/src/components/components/tabs/tabs.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Adhere to ESLint and Prettier rules across all JS/TS source files
Files:
code/core/src/components/components/tabs/tabs.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Fix type errors and prefer precise typings instead of using any or suppressions, consistent with strict mode
Files:
code/core/src/components/components/tabs/tabs.tsx
🔇 Additional comments (1)
code/core/src/components/components/tabs/tabs.tsx (1)
232-232: Ensure functionaltitlecomponents render correctly
TabsProps.titleaccepts anFC, but<title/>renders an HTML element; use the component properly:- {typeof title === 'function' ? <title /> : title} + {typeof title === 'function' ? React.createElement(title) : title}No current
Tabsusage passes a function component totitle, but this fix is required to support it.
|
View your CI Pipeline Execution ↗ for commit 9cec261
☁️ Nx Cloud last updated this comment at |
Sidnioulz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution @Nischit-Ekbote! I hope to see more to come!
We have a broader fix available in #32458, but I'll go ahead and merge your fix once CI is green, as the other PR will take longer to merge.
If you want to fix more accessibility issues, don't hesitate to browse through https://github.com/orgs/storybookjs/projects/23/views/1 to see what's not yet fixed on the other PR.
…ies-codemod-more-ts-support CSF: Enhance config-to-csf-factory to support type wrappers
Fixes screen reader announcing incorrect selected state on non-selected tabs. Added aria-selected attribute to TabButton components to properly communicate tab state to assistive technologies like Windows Narrator.
Closes #32654
What I did
Added
aria-selectedattribute to TabButton components in the Tabs component to fix accessibility issues where screen readers (Windows Narrator) were announcing incorrect "selected" state on non-selected tabs.The fix includes:
aria-selected={active}- Properly communicates selected state to screen readersChecklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
Manual testing is required for this accessibility fix.
Testing steps:
yarn startTested on:
Result: ✅ Screen reader now correctly announces selected/not selected state on tabs.
Documentation
MIGRATION.MD
Note: No documentation update needed as this is an internal accessibility fix with no API changes.
Checklist for Maintainers
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsSummary by CodeRabbit