feat: support `role` prop in RcSelect for accessibility
Motivation
Currently, <RcSelect /> does not accept the role prop as an input, which prevents developers from explicitly defining accessibility roles (e.g., role="combobox").
This causes accessibility checkers to report errors such as ARIA attribute is not allowed: aria-required="true" because the element lacks a supported role.
What I changed
- Added
role?: stringtoSelectPropstype. - Passed the
roleprop down to the root element of RcSelect.
Impact
Developers can now explicitly set role="combobox" (or other ARIA-supported roles) on <Select />, ensuring proper accessibility compliance.
Related
- Improves integration with libraries like Ant Design where
aria-requiredis used on<Select />.
Summary by CodeRabbit
- 新功能
- Select 组件新增可选属性 role,用于指定 ARIA role,提升与读屏器等辅助技术的兼容性与可配置性。未设置时行为与以往一致,不影响现有使用。无需迁移;升级后可在表单或自定义下拉等场景按需配置 role 以满足无障碍要求。
The latest updates on your projects. Learn more about Vercel for GitHub.
| Project | Deployment | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| select | Preview | Comment | Oct 1, 2025 4:43am |
Walkthrough
在 src/Select.tsx 中为 SelectProps 新增可选属性 role?: string,以支持将无障碍相关的 role 传递到 Select 组件。仅为公共 API 扩展,无行为或控制流改动,并附带与可访问性相关的代码注释。
Changes
| Cohort / File(s) | Change summary |
|---|---|
| Select 组件 API 扩展 `src/Select.tsx` |
在 SelectProps<ValueType, OptionType> 中新增可选属性 role?: string,用于传递无障碍 role;无逻辑与控制流变更,添加了相关注释。 |
Estimated code review effort
🎯 2 (Simple) | ⏱️ ~8 minutes
Suggested reviewers
- zombieJ
Poem
我是小兔写新诗,轻点键帽不费力,
Select 添个 role 字,语义悄然更清晰。
无改流程风不起,只把接口多一笔,
无障之门更易启,蹦跳审阅笑嘻嘻。 🐇✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title Check | ✅ Passed | 这个标题清晰地说明了主要变更,即在 RcSelect 组件中增加对 role 属性的支持以提升可访问性,准确传达了功能新增的核心目的,没有包含无关内容或模糊术语。 |
✨ Finishing touches
- [ ] 📝 Generate Docstrings
🧪 Generate unit tests
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c2dc26872fed3c763c377f40e2eb9c263d1600b6 and 94326ff68a57e3f335fe194f7c91b444335dd599.
📒 Files selected for processing (1)
-
src/Select.tsx(1 hunks)
🔇 Additional comments (2)
src/Select.tsx (2)
183-187: LGTM! 接口定义清晰且文档完善新增的
role属性类型正确,相关的 GitHub issue 链接提供了充足的上下文说明,有助于理解这个可访问性改进的动机。
718-718: LGTM!restProps正确传递
role属性通过restProps扩展运算符传递给BaseSelect组件,实现方式恰当。扩展运算符放置在开头,允许后续的显式属性在需要时进行覆盖。
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 @coderabbitai help to get the list of available commands and usage tips.
Summary of Changes
Hello @jsh1400, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a crucial accessibility enhancement to the RcSelect component by enabling the explicit definition of the role attribute. Previously, the component lacked this capability, leading to accessibility errors related to ARIA attributes. By allowing developers to pass a role prop, this change ensures better compliance with accessibility standards and smoother integration with other UI libraries that rely on proper ARIA roles.
Highlights
-
Accessibility Role Support: The
RcSelectcomponent now supports aroleprop, allowing developers to explicitly define accessibility roles for the select element. -
Type Definition Update: The
SelectPropsinterface insrc/Select.tsxhas been updated to include an optionalroleproperty of typestring. - Enhanced ARIA Compliance: This change resolves issues where accessibility checkers reported errors due to missing or unsupported ARIA roles, improving compliance, especially with libraries like Ant Design.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 98.11%. Comparing base (c2dc268) to head (94326ff).
:warning: Report is 42 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #1165 +/- ##
=======================================
Coverage 98.11% 98.11%
=======================================
Files 39 39
Lines 1489 1489
Branches 452 452
=======================================
Hits 1461 1461
Misses 28 28
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Hi 👋
Thanks for reviewing my PR!
This fix is important for addressing related issues in Ant Design:
- https://github.com/ant-design/ant-design/issues/46030
- https://github.com/ant-design/ant-design/pull/55185#discussion_r2389642896
All checks have passed, and the changes can be cleanly merged.
Would appreciate if this could be merged when convenient 🙏
@jsh1400 I think it is better to use AriaRole type from React to support semantic naming. Will you be able to update PR?
@zombieJ What do you think about passing aria-required (maybe even all aria- attributes) to internal Input component that currently holds all accessibility attributes (https://github.com/react-component/select/blob/master/src/SelectInput/Input.tsx#L179) instead of provided approach? The same way @rc-component/input works https://github.com/react-component/input/blob/master/src/Input.tsx#L235. I think Select's wrapper should not render these attributes.
Close by https://github.com/react-component/select/pull/1190. If you still encounter problems after the new version is released, please feel free to open a new issue.