Skip to content

fix: add aria-hidden attribute to visually hidden input element #279

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

Merged
merged 2 commits into from
Oct 27, 2024

Conversation

aojunhao123
Copy link
Contributor

@aojunhao123 aojunhao123 commented Oct 25, 2024

Description

添加了 aria-hidden="true" 属性到视觉隐藏的 radio input 元素上,以优化屏幕阅读器的体验。

改动原因

该 radio input 元素仅用于组件内部状态管理,不需要被屏幕阅读器读取。添加 aria-hidden 属性可以防止冗余的朗读信息,提升无障碍体验。

相关改动

  • 为 Segmented 组件中的隐藏 input 元素添加 aria-hidden="true" 属性

参考文档

Summary by CodeRabbit

  • 新功能
    • InternalSegmentedOption 组件的 <input> 元素中添加了 aria-hidden="true" 属性,增强了可访问性,使辅助技术忽略该输入。

Copy link

coderabbitai bot commented Oct 25, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

此次更改在InternalSegmentedOption组件的<input>元素中引入了新属性aria-hidden="true",以增强可访问性,指示辅助技术应忽略该输入。Segmented组件的整体结构和逻辑保持不变,未对现有的props或方法进行修改。handleChange函数继续管理单选输入的更改事件,确保仅在输入未禁用时调用onChange回调。normalizeOptions函数处理选项,以确保每个选项都有有效的标题,同时MotionThumb组件用于管理所选选项的视觉表示。

Changes

文件路径 更改摘要
src/index.tsx 添加aria-hidden="true"属性到<input>元素,增强可访问性。保持Segmented组件的结构和逻辑不变。

Possibly related PRs

  • chore: remove useless #48: 此PR涉及Segmented组件的onChange事件处理程序,与主PR中InternalSegmentedOption组件的handleChange函数的逻辑重叠,表明两者之间存在直接关系。

Poem

在兔子窝里,变化真奇妙,
输入框里,隐藏了喧嚣。
可访问性提升,大家都欢笑,
选项如星辰,闪耀在草梢。
兔子跳跃,乐在其中,
新的功能,真是太棒! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@aojunhao123
Copy link
Contributor Author

input组件属于内部实现,对用户不可见,无需展示在屏幕阅读器上

QQ_1729848856214
QQ_1729848902624

Copy link

@coderabbitai coderabbitai bot left a 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

🧹 Outside diff range and nitpick comments (1)
src/index.tsx (1)

需要增强键盘可访问性支持

基于代码分析,虽然组件已实现了基本的ARIA属性(role="listbox"/"option"和aria-selected等),但仍缺少关键的键盘交互支持:

  • 未发现tabIndex属性设置
  • 缺少键盘事件处理(如onKeyDown)
  • 未实现焦点管理相关逻辑

建议添加以下改进:

  • 为可选项添加适当的tabIndex
  • 实现左右方向键导航
  • 添加焦点状态样式
  • 确保Enter/Space键可触发选择
🔗 Analysis chain

Line range hint 109-116: 建议验证完整的可访问性实现

虽然添加 aria-hidden 是个很好的改进,但建议进行全面的可访问性测试,确保:

  1. 键盘导航正常工作
  2. 焦点管理适当
  3. 高对比度模式下的可见性

运行以下脚本检查其他可访问性相关属性:


Let me check for keyboard navigation and focus management related attributes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查组件中的所有 ARIA 属性和角色
rg -i '(aria-|role=)' 

Length of output: 7194


Script:

#!/bin/bash
# Check for keyboard and focus related attributes
rg -i '(tabindex|onkey|focus)' src/index.tsx -A 2

Length of output: 51

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 02aa14a and bc04e6d.

📒 Files selected for processing (1)
  • src/index.tsx (1 hunks)
🔇 Additional comments (1)
src/index.tsx (1)

110-110: 添加 aria-hidden 属性改善了可访问性!

这个改动很好地解决了屏幕阅读器重复朗读的问题。由于该 input 元素仅用于内部状态管理,添加 aria-hidden="true" 可以防止辅助技术重复朗读,从而提供更好的用户体验。

@aojunhao123
Copy link
Contributor Author

@afc163 @zombieJ 大佬有空看一下,小改动

@afc163
Copy link
Member

afc163 commented Oct 26, 2024

ci 挂了

@aojunhao123
Copy link
Contributor Author

ci 挂了

已修复

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.21%. Comparing base (02aa14a) to head (bf9c01c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #279   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files           2        2           
  Lines         127      127           
  Branches       29       29           
=======================================
  Hits          126      126           
  Misses          1        1           

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

@afc163 afc163 merged commit 6bedd52 into react-component:master Oct 27, 2024
8 checks passed
@@ -107,6 +107,7 @@ const InternalSegmentedOption: React.FC<{
>
<input
className={`${prefixCls}-item-input`}
aria-hidden="true"
Copy link
Member

Choose a reason for hiding this comment

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

input 不是内部状态管理,而是专门用来做无障碍的。如果影响读屏器,应该是把其他的藏起来,而只保留 input 的读屏能力

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.

3 participants