Skip to content

feat: support aria-* and data-* #592

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
May 12, 2025

Conversation

kiner-tang
Copy link
Contributor

@kiner-tang kiner-tang commented May 11, 2025

Summary by CodeRabbit

  • 新功能

    • 选项支持自定义 aria-* 和 data-* 属性,提升可访问性和数据标记能力。
  • 测试

    • 新增测试用例,验证 aria-* 和 data-* 属性可正确渲染到对应 DOM 元素上。

Copy link

vercel bot commented May 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cascader ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 11, 2025 3:32am

Copy link

coderabbitai bot commented May 11, 2025

Walkthrough

本次变更为级联选择组件的选项对象增加了对 aria-*data-* 属性的支持。通过在数据结构和渲染逻辑中提取并传递这些属性,实现了自定义无障碍和数据属性的透传。同时,新增了相关测试用例以验证功能。

Changes

文件/路径 变更摘要
examples/simple.tsx addressOptions 第一个对象(福建)中添加了 aria-labelaria-labelledbydata-type 属性。
src/OptionList/Column.tsx 使用 pickAttrs 工具函数提取选项对象中的 ARIA 和 data 属性,并将其传递给 <li> 元素。
tests/index.spec.tsx 新增测试用例,验证 aria-*data-* 属性能正确渲染到 DOM 元素上。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant Cascader组件
    participant OptionList
    participant DOM

    用户->>Cascader组件: 提供带 aria/data 属性的 options
    Cascader组件->>OptionList: 渲染选项列表
    OptionList->>DOM: 将 aria/data 属性透传到 <li> 元素
Loading

Suggested reviewers

  • zombieJ

Poem

小兔挥笔写新篇,
属性透传真方便。
ARIA 数据皆可见,
无障碍里显温暖。
测试加持保安全,
代码世界更美满!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/OptionList/Column.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

examples/simple.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

tests/index.spec.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 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 f8cb450 and d4060a5.

📒 Files selected for processing (3)
  • examples/simple.tsx (1 hunks)
  • src/OptionList/Column.tsx (3 hunks)
  • tests/index.spec.tsx (1 hunks)
🔇 Additional comments (5)
src/OptionList/Column.tsx (3)

3-3: 引入了 pickAttrs 工具函数

引入 rc-util/lib/pickAttrs 工具函数以支持提取和透传 aria-* 和 data-* 属性,这是实现这一特性的基础。


143-146: 已实现属性提取功能

通过 pickAttrs 工具函数从选项对象中提取 aria-* 和 data-* 属性,这样可以支持无障碍功能和自定义数据属性。配置项正确指定了需要提取的属性类型。


178-178: 成功透传属性到 DOM 元素

将提取的 aria-* 和 data-* 属性透传到 <li> 元素上,确保这些属性能够正确应用到渲染的 DOM 元素中,增强了组件的可访问性和灵活性。

examples/simple.tsx (1)

11-13: 示例中添加了自定义属性

为示例中的第一个选项 "福建" 添加了 aria-label、aria-labelledby 和 data-type 属性,很好地展示了新特性的使用方法。属性值与选项内容保持一致,便于理解和使用。

tests/index.spec.tsx (1)

1158-1191: 新增了完整的测试用例

添加了名为 "support aria-* and data-*" 的测试用例,测试逻辑完整:

  1. 创建了带有 aria-* 和 data-* 属性的选项数据
  2. 渲染 Cascader 组件
  3. 验证这些属性是否正确地应用到了渲染的 DOM 元素上

测试用例覆盖了核心功能,确保了特性的正确实现和稳定性。

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Copy link

codecov bot commented May 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.83%. Comparing base (f8cb450) to head (d4060a5).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #592   +/-   ##
=======================================
  Coverage   99.83%   99.83%           
=======================================
  Files          23       23           
  Lines         610      611    +1     
  Branches      176      176           
=======================================
+ Hits          609      610    +1     
  Misses          1        1           

☔ 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.

@kiner-tang kiner-tang marked this pull request as ready for review May 11, 2025 03:34
@afc163 afc163 merged commit 156b142 into react-component:master May 12, 2025
11 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