Skip to content

Conversation

Dcose
Copy link

@Dcose Dcose commented Oct 11, 2025

🤔 这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

🔗 相关 Issue

💡 需求背景和解决方案

  • 背景:
    当前 Button 组件在使用 div 作为按钮或图标按钮时,部分无障碍需求未完全满足 WCAG 2.1 标准,例如键盘可操作性、aria 标签、loading 状态标识等。

  • 解决方案:

    1. 增加 role="button"aria-disabled 等无障碍属性,确保 div 按钮可被屏幕阅读器识别。
    2. 为键盘操作(Enter / Space)提供事件支持,保证非 <button> 元素也可操作。
    3. icon 元素加上 aria-hidden="true",避免装饰性图标干扰屏幕阅读器。
    4. loading 状态时增加 aria-busy 标识。
    5. 新增 button.a11y.test.tsx 测试文件,覆盖所有新增无障碍行为。

📝 更新日志

  • feat(Button): 增强组件的无障碍支持,符合 WCAG 2.1 标准

  • 本条 PR 不需要纳入 Changelog

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request enhances the Button component's accessibility (a11y) support to meet WCAG 2.1 standards. The changes focus on improving keyboard operability, screen reader compatibility, and proper semantic markup for various button types.

Key Changes:

  • Added comprehensive accessibility attributes (role, aria-disabled, aria-busy, aria-label, tabIndex)
  • Implemented keyboard event handlers for div-based buttons (Enter and Space key support)
  • Enhanced icon accessibility by adding aria-hidden attribute to decorative icons
  • Created extensive test suite covering all accessibility improvements

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
Button.tsx Core implementation of accessibility features including ARIA attributes, keyboard handlers, and semantic improvements
button.a11y.test.tsx Comprehensive test suite validating WCAG 2.1 compliance and accessibility behaviors

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const handleKeyDown = (e: React.KeyboardEvent) => {
if (!disabled && !loading) {
if (e.key === 'Enter') {
onClick?.(e as unknown as React.MouseEvent<HTMLDivElement>);
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The type casting e as unknown as React.MouseEvent<HTMLDivElement> is problematic because it forces a KeyboardEvent to be treated as a MouseEvent. Consider creating a separate handler or using a union type that accepts both event types.

Copilot uses AI. Check for mistakes.


const handleKeyUp = (e: React.KeyboardEvent) => {
if (!disabled && !loading && e.key === ' ') {
onClick?.(e as unknown as React.MouseEvent<HTMLDivElement>);
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

Same type casting issue as line 76. The KeyboardEvent should not be forced into a MouseEvent type, as this could lead to runtime issues when the onClick handler expects MouseEvent-specific properties.

Copilot uses AI. Check for mistakes.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 11, 2025

完成

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 11, 2025

tdesign-react-demo

npm i https://pkg.pr.new/tdesign-react@3884

commit: 1a9e168

@Tencent Tencent deleted a comment from github-actions bot Oct 11, 2025
@RylanBot
Copy link
Collaborator

/update-snapshots

@github-actions
Copy link
Contributor

⏳ 正在运行快照更新。。。 CI: Open

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