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

fix: aria-selected should not always set to false under combobox mode #1077

Merged

Conversation

nathanlao
Copy link
Contributor

@nathanlao nathanlao commented Oct 11, 2024

This is a

bug fix related to accessibility

Related Issues

This can fix the issue that aria-select is always set to false in autoComplete component (under combobox mode)
ant-design/ant-design#48036

Background

Although no option is considered permanently "selected" under the combobox mode (autoComplete), if the aria-selected is affected by this then it could violate the accessibility issue, hence I made a change to determine accessibnility selection (set aria-selected attribute) while still maintain the visual consistency

image

Summary by CodeRabbit

  • 新功能
    • 更新了OptionList组件以改善选择状态和可访问性,特别是在“combobox”模式下。
    • 新增了isAriaSelected函数,以支持更好的无障碍功能。
  • 改进
    • aria-selected属性现在使用isAriaSelected,确保无障碍状态反映最新逻辑。

Copy link

vercel bot commented Oct 11, 2024

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

Name Status Preview Comments Updated (UTC)
select ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 11, 2024 10:16pm

Copy link
Contributor

coderabbitai bot commented Oct 11, 2024

Walkthrough

此次更改主要集中在 src/OptionList.tsx 文件中的 OptionList 组件。isSelected 函数进行了更新,以便在模式为 'combobox' 时返回 false,而不是检查值是否存在于 rawValues 中。此外,新增了 isAriaSelected 函数,该函数根据模式进行选择状态的判断,并在渲染项目时更新了 aria-selected 属性,以反映新的逻辑。useEffect 钩子仍然存在,继续依赖 getEnabledActiveIndex 函数来确定活动索引。

Changes

文件路径 更改摘要
src/OptionList.tsx 更新 isSelected 函数以处理 'combobox' 模式;新增 isAriaSelected 函数以增强无障碍功能;更新 aria-selected 属性的使用。

Possibly related PRs

Suggested reviewers

  • afc163

Poem

在兔子洞里欢跳跃,
选项列表新变化,
'combobox' 模式真奇妙,
无障碍功能更高效。
让我们一起欢庆吧! 🐇✨


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.

Copy link
Contributor

@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/OptionList.tsx (1)

136-145: 新增的 isAriaSelected 函数很好地解决了问题

这个新函数很好地解决了 combobox 模式下 aria-selected 属性的问题。对于 combobox 模式,它通过不区分大小写的比较来确定选中状态,这提高了用户体验。对于其他模式,它保持了原有的逻辑。

建议:考虑将 String(value).toLowerCase() 的结果缓存,以避免在每次比较时重复执行这个操作。例如:

const lowerValue = String(value).toLowerCase();
return lowerValue === searchValue.toLowerCase();

这可能会略微提高性能,特别是在处理大量选项时。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fb2a981 and 6bb66e9.

📒 Files selected for processing (1)
  • src/OptionList.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (3)
src/OptionList.tsx (3)

127-132: 修改后的 isSelected 函数符合预期

这个更改很好地解决了 combobox 模式下的问题。现在,当模式为 'combobox' 时,函数始终返回 false,这有助于解决 PR 中提到的 aria-selected 属性设置问题。对于其他模式,函数仍然检查值是否存在于 rawValues 中,保持了原有的逻辑。

这个修改符合 PR 的目标,提高了组件的可访问性。


294-294: aria-selected 属性的更新符合预期

在渲染函数中,aria-selected 属性现在使用新的 isAriaSelected 函数来设置,而不是之前的 isSelected 函数。这个变更出现在第 294 行和第 379 行。

这个修改确保了 aria-selected 属性在所有模式下(包括 combobox 模式)都能正确设置。这对于提高组件的可访问性非常重要,特别是对于使用屏幕阅读器的用户。

这个变更很好地实现了 PR 的目标,提高了组件的整体可访问性。

Also applies to: 379-379


127-145: 总体评价:改进了可访问性,同时保持了视觉一致性

这次更改主要集中在改进 aria-selected 属性的处理,特别是在 combobox 模式下。主要变更包括:

  1. 修改了 isSelected 函数,使其在 combobox 模式下始终返回 false。
  2. 新增了 isAriaSelected 函数,根据不同模式正确处理选中状态。
  3. 更新了渲染函数,使用新的 isAriaSelected 函数来设置 aria-selected 属性。

这些变更有效地解决了 PR 中提到的问题,提高了组件的可访问性,同时保持了视觉上的一致性。代码结构良好,变更最小化且集中,这有助于维护代码的可读性和可维护性。

总的来说,这是一个高质量的改进,它增强了组件的可访问性,同时保持了现有功能的完整性。

Also applies to: 294-294, 379-379

Copy link

codecov bot commented Oct 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.24%. Comparing base (fb2a981) to head (6bb66e9).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1077   +/-   ##
=======================================
  Coverage   98.23%   98.24%           
=======================================
  Files          39       39           
  Lines        1474     1482    +8     
  Branches      439      418   -21     
=======================================
+ Hits         1448     1456    +8     
  Misses         26       26           

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

@afc163 afc163 merged commit 601a209 into react-component:master Oct 12, 2024
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