Skip to content

fix: support data attributes in closable - #420

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
QDyanbing:fix-closable-data-attrs
Nov 20, 2026
Merged

yoyo837 merged 1 commit into
react-component:masterfrom
QDyanbing:fix-closable-data-attrs

Conversation

@QDyanbing

@QDyanbing QDyanbing commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Notification 的 closable 对象目前既未声明 data-,也未将其透传到关闭按钮。本次在现有 ClosableConfig 上补充 data- 索引类型,并使用 pickAttrs 的 { aria: true, data: true } 配置提取属性,沿现有渲染路径传给实际关闭按钮。

新增公开入口测试,覆盖 useNotification 默认配置、单条通知配置、Notification 和 NotificationList;验证 data-*、aria-label、role、closable=false、配置整体覆盖规则及关闭回调参数与次数。同时保留现有 disabled 行为,确认普通 DOM 属性和额外事件不会被透传。

验证:

  • npm test:60 项测试通过;补充 disabled 断言后,相关 4 项测试再次通过。
  • npm run tsc、npm run lint,以及修改文件的 ESLint 和格式检查通过;常规 lint 存在既有警告。

本次仅补齐兼容性支持,不修改图标、默认显隐、自动关闭、销毁或回调语义,不推进 V7 的 closable 行为统一。

参考:ant-design/ant-design#59667

Summary by CodeRabbit

  • 新功能
    • 通知关闭按钮现在会转发配置中的 data-* 属性;原有 aria-* 属性转发保持不变。
  • 测试
    • 增加了对属性转发与筛选、关闭配置替换规则及关闭交互的测试。

@vercel

vercel Bot commented Nov 20, 2026

Copy link
Copy Markdown

@QDyanbing is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

ClosableConfig 新增对 data-* 属性的类型支持。useClosable 现在会转发配置中的 aria-* 和 data-* 属性。新增测试覆盖属性转发、配置替换、关闭按钮状态及通知移除行为。

Changes

关闭按钮属性转发

Layer / File(s) Summary
属性转发与验证
src/hooks/useClosable.ts, tests/closable.test.tsx
ClosableConfig 新增 data-* 属性索引签名。useClosable 提取并转发 aria-* 和 data-* 属性。测试覆盖根级和通知级配置、属性筛选、关闭回调及通知移除。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

诗歌

我是小兔,带来一枚 data 标记
关按钮收好 aria 与 data
配置切换,属性随之更新
轻轻一点,通知便离开
新测试排成一行胡萝卜
月光下,我蹦回草丛里

Suggested reviewers: zombiej

Merge Risk: Minimal · up to 52ce4

Close buttons now receive data-* attributes from the closable configuration. Existing behavior is preserved and the change is tested, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“fix: support data attributes in closable”与变更内容一致。变更在 ClosableConfig 中新增 data-* 索引签名,并让 useClosable 转发 data-* 属性到关闭按钮。测试文件覆盖了 Notification 与 NotificationList 的 data-* 转发。标题说明了主要变更,描述具体,没有模糊用语。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

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.

ESLint install timed out. The project may have too many dependencies for the sandbox.

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

小兔看见属性已转发
aria 与 data 各自就位
关闭按钮轻轻响应
通知从列表中移除
测试守护每个步骤

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 535afca0-f0af-42d8-abd0-586b3955f676
Commits

Reviewing files that changed from the base of the PR and between cea66a1 and 52ce442.

Files selected for processing: 2

  • src/hooks/useClosable.ts
  • tests/closable.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.21%. Comparing base (cea66a1) to head (52ce442).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #420   +/-   ##
=======================================
  Coverage   99.21%   99.21%           
=======================================
  Files          12       12           
  Lines         381      382    +1     
  Branches      103      103           
=======================================
+ Hits          378      379    +1     
  Misses          3        3           

☔ View full report in Codecov by Harness.
📢 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.

@yoyo837
yoyo837 merged commit a764305 into react-component:master Nov 20, 2026
11 of 12 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