-
Notifications
You must be signed in to change notification settings - Fork 134
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Walkthrough本次变更涉及 Changes
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
There was a problem hiding this 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
📒 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-only
和icon-collapsible-only
明确交互区域
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 : {})} |
There was a problem hiding this comment.
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
建议进行无障碍功能测试
无障碍属性的实现看起来不错,但建议:
- 使用屏幕阅读器进行实际测试
- 验证不同 collapsible 模式下的朗读体验
- 确保键盘导航的流畅性
🏁 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
There was a problem hiding this 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
⛔ 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: default
和cursor: pointer
分别应用于不同元素,为用户提供了清晰的视觉反馈。
ref #353
这样更合理,aria 属性精确到实际的交互元素上。
Summary by CodeRabbit
CollapsePanel
组件,简化了事件处理和动态属性设置。role
、aria-expanded
、aria-disabled
和tabIndex
属性,增强了无障碍性。