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 behavior #354

Merged
merged 2 commits into from
Oct 28, 2024
Merged

feat: improve a11y behavior #354

merged 2 commits into from
Oct 28, 2024

Conversation

afc163
Copy link
Member

@afc163 afc163 commented Oct 28, 2024

ref #353

这样更合理,aria 属性精确到实际的交互元素上。

Summary by CodeRabbit

  • 新功能
    • 更新了 CollapsePanel 组件,简化了事件处理和动态属性设置。
  • 改进
    • 通过合并事件处理逻辑,提高了组件的可维护性和效率。
    • 动态设置 rolearia-expandedaria-disabledtabIndex 属性,增强了无障碍性。
  • 样式调整
    • 修改了可折叠组件的 LESS 样式表中的类选择器名称,以提高命名的一致性和清晰度。

Copy link

vercel bot commented Oct 28, 2024

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

Name Status Preview Comments Updated (UTC)
collapse ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 28, 2024 8:25am

Copy link

coderabbitai bot commented Oct 28, 2024

Walkthrough

本次变更涉及rc-collapse项目的package.jsonsrc/Panel.tsx文件。在package.json中,新增了@testing-library/user-event依赖,版本为^14.5.2。在src/Panel.tsx中,修改了CollapsePanel组件,合并了点击和键盘事件处理,简化了属性设置和图标节点逻辑,同时更新了类名以反映当前状态,提升了代码的可维护性和清晰度。

Changes

文件 变更摘要
package.json 新增依赖:"@testing-library/user-event": "^14.5.2"devDependencies中。
src/Panel.tsx 合并事件处理,简化属性设置,更新类名,提升可维护性和清晰度。
assets/index.less 重命名类选择器:. @{prefixCls}-header-collapsible-only. @{prefixCls}-collapsible-header. @{prefixCls}-icon-collapsible-only. @{prefixCls}-collapsible-icon,并调整了光标属性。

Possibly related PRs

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.

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.12%. Comparing base (d403776) to head (9387e53).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #354      +/-   ##
==========================================
- Coverage   99.13%   99.12%   -0.02%     
==========================================
  Files           5        5              
  Lines         116      114       -2     
  Branches       42       43       +1     
==========================================
- Hits          115      113       -2     
  Misses          1        1              

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

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

51-60: 建议为可折叠模式添加注释说明

图标渲染逻辑简化得很好,但建议为不同的可折叠模式('header' 和 'icon')添加注释说明,以便其他开发者更好地理解这些模式的区别和用途。

  // ======================== Icon ========================
+ // collapsible 模式说明:
+ // - 'header': 整个标题可点击
+ // - 'icon': 仅图标可点击
  const iconNodeInner =
    typeof expandIcon === 'function' ? expandIcon(props) : <i className="arrow" />;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d403776 and 6af214c.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/Panel.tsx (2 hunks)
🔇 Additional comments (3)
package.json (1)

57-57: 新增的测试依赖对提升无障碍功能测试覆盖率很有帮助!

添加 @testing-library/user-event 依赖是个很好的选择,因为它能够:

  • 模拟真实的用户交互,特别是键盘操作
  • 有助于验证无障碍功能的正确性
  • 与现有的测试库完美配合
src/Panel.tsx (2)

35-47: 事件处理和无障碍属性的优化实现

代码优化得很好:

  • 统一了点击和键盘事件的处理逻辑
  • 根据组件状态正确设置了 ARIA 属性
  • 适当处理了键盘访问
  • 禁用状态下正确处理了 tabIndex

Line range hint 63-76: 类名结构优化合理

类名的组织结构清晰,很好地反映了组件的不同状态:

  • 使用 item-active 表示激活状态
  • 使用 header-collapsible-onlyicon-collapsible-only 明确交互区域

Comment on lines 84 to +95
style: styles.header,
role: accordion ? 'tab' : 'button',
...(['header', 'icon'].includes(collapsible) ? {} : collapsibleProps),
};

if (!collapsibleHeader && !collapsibleIcon) {
headerProps.onClick = handleItemClick;
headerProps.tabIndex = disabled ? -1 : 0;
}

// ======================== Render ========================
return (
<div {...resetProps} ref={ref} className={collapsePanelClassNames}>
<div {...headerProps}>
{showArrow && iconNode}
<span
className={`${prefixCls}-header-text`}
onClick={collapsible === 'header' ? handleItemClick : undefined}
{...(collapsible === 'header' ? collapsibleProps : {})}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

需要扩展无障碍测试覆盖范围

代码已经实现了基本的无障碍属性(aria-expanded、aria-disabled、role等),但测试覆盖度不够全面:

  • 仅测试了基础的属性存在性
  • 缺少键盘交互测试
  • 缺少不同 collapsible 模式下的无障碍行为测试

建议:

  • 添加键盘导航测试用例(Enter、Space 键触发)
  • 为不同的 collapsible 模式添加专门的无障碍测试
  • 添加 ARIA 属性在不同状态下的动态变化测试
🔗 Analysis chain

建议进行无障碍功能测试

无障碍属性的实现看起来不错,但建议:

  1. 使用屏幕阅读器进行实际测试
  2. 验证不同 collapsible 模式下的朗读体验
  3. 确保键盘导航的流畅性
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 检查是否有相关的无障碍测试用例

# 搜索测试文件中的无障碍相关测试
rg -l "aria-|role=|keyboard|screenreader|a11y" --type ts --type tsx | grep -i "test"

Length of output: 112


Script:

#!/bin/bash
# 搜索测试文件中的无障碍相关测试,修正文件类型参数
rg -l "aria-|role=|keyboard|screenreader|a11y" -g "*.test.*" -g "*.spec.*"

# 检查组件中的无障碍属性实现
rg "aria-|role=" src/Panel.tsx -A 2

Length of output: 374


Script:

#!/bin/bash
# 检查测试文件中的具体无障碍测试内容
rg "aria-|role=|keyboard|screenreader|a11y" tests/index.spec.tsx -A 3

# 检查快照文件中的无障碍属性实现
rg "aria-|role" tests/__snapshots__/index.spec.tsx.snap -A 2

Length of output: 1076

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)
assets/index.less (1)

Line range hint 71-76: 建议:考虑合并相似的样式规则

当前的 .@{prefixCls}-collapsible-icon 样式与 .@{prefixCls}-collapsible-header 有重叠的行为模式。

建议重构为:

.@{prefixCls}-collapsible {
  &-header,
  &-icon {
    cursor: default;
    .@{prefixCls}-expand-icon {
      cursor: pointer;
    }
  }
  
  &-header .@{prefixCls}-header-text {
    cursor: pointer;
  }
}

这样可以:

  • 减少代码重复
  • 提高维护性
  • 保持相同的可访问性效果
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6af214c and 9387e53.

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/index.spec.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • assets/index.less (2 hunks)
  • src/Panel.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Panel.tsx
🔇 Additional comments (1)
assets/index.less (1)

Line range hint 62-70: 可访问性改进:标题区域交互行为优化

新增的样式类很好地区分了可点击和不可点击的区域,这与 ARIA 属性的应用相呼应,提升了可访问性。通过将 cursor: defaultcursor: pointer 分别应用于不同元素,为用户提供了清晰的视觉反馈。

@afc163 afc163 merged commit 06a04d0 into master Oct 28, 2024
10 checks passed
@afc163 afc163 deleted the fix/a11y-behavior branch October 28, 2024 08:28
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.

1 participant