close
Skip to content

fix: add aria-labelledby to checkbox for better a11y#1004

Merged
afc163 merged 1 commit into
react-component:masterfrom
aojunhao123:fix/checkbox-aria-labelledby
Jan 27, 2026
Merged

fix: add aria-labelledby to checkbox for better a11y#1004
afc163 merged 1 commit into
react-component:masterfrom
aojunhao123:fix/checkbox-aria-labelledby

Conversation

@aojunhao123
Copy link
Copy Markdown
Contributor

@aojunhao123 aojunhao123 commented Jan 26, 2026

image

修一下antd那边挂掉的a11y test case。主要是在这个pr里把checkbox的aria-label给去掉了,但是发现这个其实不能去掉。因为checkbox需要提供文本内容给读屏器播报,使用aria-labelledby来解。测了一下不会重复播报,antd那边测试也没问题

Summary by CodeRabbit

发布说明

  • 无障碍访问改进

    • 增强了树节点组件的屏幕阅读器支持,提升了键盘导航和屏幕阅读器用户的体验。
  • 代码优化

    • 改进了内部代码组织结构,提高了代码整洁度和维护性。

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 26, 2026

@aojunhao123 is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @aojunhao123, I'm Gemini Code Assist1! 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 significantly improves the accessibility of the tree component by implementing the aria-labelledby attribute on checkboxes. This change ensures that assistive technologies can correctly identify and announce the purpose of each checkbox, leading to a more navigable and understandable user interface for all users.

Highlights

  • Accessibility Improvement: Added the aria-labelledby attribute to the checkbox element within the TreeNode component to explicitly associate it with its label, enhancing accessibility for screen readers.
  • Node ID Refactoring: Relocated the generation of the nodeId to an earlier point in the TreeNode component's render cycle, ensuring it is available when the aria-labelledby attribute is set.
  • Dependency Array Update: Modified the dependency array of the useMemo hook responsible for rendering the checkbox, replacing props.title with nodeId to ensure correct re-evaluation when the node identifier changes.
  • Snapshot Test Updates: Updated existing snapshot tests in Tree.spec.tsx.snap and TreeProps.spec.tsx.snap to reflect the addition of the aria-labelledby attribute on checkbox elements.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 👍 and 👎 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.

Footnotes

  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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 26, 2026

演进说明

通过在 TreeNode 组件顶部计算 getTreeNodeId(treeId, eventKey) 来引入稳定的节点标识符,并在整个组件中重复使用,同时改进复选框的可访问性属性和依赖项管理。

变更概览

类型 / 文件 修改摘要
NodeId 稳定化和可访问性改进
src/TreeNode.tsx
将 nodeId 计算移至组件顶层,为复选框 span 添加 aria-labelledby={nodeId} 属性以增强无障碍访问性;更新 useMemo 依赖数组,将 props.title 替换为 nodeId;消除拖拽流程中重复的 nodeId 声明,实现单一定义的统一管理

估算代码审查工作量

🎯 2 (Simple) | ⏱️ ~10 minutes

可能相关的 PR

推荐审查人

  • zombieJ
  • afc163

兔子的贺诗

🐰 小节点换新妆,
ID 上移显端庄,
无障碍染新装,
一个定义闪闪亮!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确地反映了拉取请求的主要变更:向复选框添加aria-labelledby属性以改进可访问性。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.84%. Comparing base (177b147) to head (caa09ac).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1004   +/-   ##
=======================================
  Coverage   99.84%   99.84%           
=======================================
  Files          14       14           
  Lines        1295     1295           
  Branches      396      396           
=======================================
  Hits         1293     1293           
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces aria-labelledby to the checkbox elements within the TreeNode component, significantly improving accessibility for users who rely on assistive technologies. The nodeId is correctly generated and used, and the useMemo dependency array has been updated to reflect this change. The refactoring of nodeId declaration to an earlier, more appropriate scope is also a good improvement.

Comment thread src/TreeNode.tsx
Comment thread src/TreeNode.tsx
Comment thread src/TreeNode.tsx
Comment thread src/TreeNode.tsx
@afc163 afc163 merged commit 29e62ca into react-component:master Jan 27, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants