Skip to content
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

feat: improve a11y #292

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

aojunhao123
Copy link

@aojunhao123 aojunhao123 commented Nov 17, 2024

image
image

由于input外层包了span标签,导致a11y测试无法通过。
这个pr将label标签下沉到了rc-checkbox内部,ant-design侧的改动细节在这个commit

Summary by CodeRabbit

  • 新功能

    • 更新了复选框组件的结构,使用 <label> 元素替代 <span>,提高了可访问性。
    • 新增 children 属性,允许在复选框组件内渲染子元素。
  • 改进

    • 更改了 holderRef 的类型,以确保复选框与其标签之间的正确关联。

Copy link

coderabbitai bot commented Nov 17, 2024

Walkthrough

该更改修改了 src/index.tsx 中的 Checkbox 组件,将 holderRef 的类型从 HTMLElement 更改为 HTMLLabelElement,指明该引用现在专门指向标签元素。组件的外层元素由 <span> 切换为 <label>,增强了可访问性,确保复选框输入与其标签正确关联。新增的 children 属性允许在复选框组件中渲染子元素。onChange 处理程序的逻辑保持不变,依然管理选中状态并以适当的事件结构调用提供的 onChange 回调。整体上,这些更改专注于改善组件的 HTML 语义和灵活性,而不改变其核心功能或事件处理。

Changes

文件路径 更改摘要
src/index.tsx holderRef 类型从 HTMLElement 更改为 HTMLLabelElement,将外层元素从 <span> 更改为 <label>,并新增 children 属性。

Poem

在兔子洞里欢声笑语,
复选框变身为标签的舞。
语义清晰,易于访问,
小小改变,乐无穷。
兔子们跳跃,庆祝新生,
代码更新,心中欢腾! 🐇✨

Warning

Rate limit exceeded

@aojunhao123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 4 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 527999c and 9e2da0c.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 527999c and 9e2da0c.

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

41-41: 添加 children 属性符合可访问性要求

新增的 children 属性使得标签文本可以正确地与复选框关联,这是提高可访问性的重要改进。


46-46: holderRef 类型更改提高了类型安全性

将 holderRef 的类型从 HTMLElement 更改为 HTMLLabelElement 更准确地反映了组件的结构,有助于在编译时捕获潜在的类型错误。


Line range hint 94-106: 组件结构改进优化了可访问性

将复选框和相关内容包装在 label 元素中的改动:

  1. 确保了标签文本与复选框的正确关联
  2. 改善了屏幕阅读器的可访问性
  3. 符合 HTML 语义化标准

建议添加一些自动化测试来验证可访问性改进。


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
Author

@afc163 大佬有空帮忙看一下

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (818d219) to head (9e2da0c).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #292   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           30        31    +1     
  Branches         5         6    +1     
=========================================
+ Hits            30        31    +1     

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

@afc163
Copy link
Member

afc163 commented Nov 18, 2024

这样不行,children 也要在 label 内容,不然文字和 checkbox 关联不上。

要下沉就要把 children 也下沉。

@aojunhao123
Copy link
Author

这样不行,children 也要在 label 内容,不然文字和 checkbox 关联不上。

要下沉就要把 children 也下沉。

done

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: 1

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

41-41: 建议为 children 属性添加类型注解

为了提高代码的类型安全性和可维护性,建议为新增的 children 属性添加明确的类型注解。

- children,
+ children?: React.ReactNode,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f412e81 and 527999c.

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

46-46: 将 holderRef 类型更改为 HTMLLabelElement 是个很好的改进

这个类型更改使得类型定义更加精确,与新的 label 包装结构相匹配,同时也有助于提供更好的类型检查和IDE支持。

src/index.tsx Outdated Show resolved Hide resolved
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