Skip to content

feat: add shared useAllowClear hook - #820

Merged
zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:feat-use-allow-clear
Oct 13, 2026
Merged

zombieJ merged 1 commit into
react-component:masterfrom
QDyanbing:feat-use-allow-clear

Conversation

@QDyanbing

@QDyanbing QDyanbing commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

变更说明

为各 rc 组件提供统一的清除配置解析能力,落实 ant-design/ant-design#59553 中 util 侧的公共接口。

  • 新增并从包入口导出 useAllowClear 和 AllowClearConfig,支持可选的 clearIcon、disabled、tabIndex 和 label。
  • 布尔形式归一化为 disabled:false / undefined 返回 { disabled: true },true 返回 { disabled: false };对象形式保留原有字段,并将未配置的 disabled 补齐为 false。
  • 使用 React 记忆化保持相同输入下的返回引用,不修改输入对象。组件默认值、配置合并、图标、国际化和实际清除行为仍由调用方处理。
  • 补充公共入口测试和使用文档,覆盖字段保留、禁用后恢复、输入不可变性及返回引用稳定性。

验证

  • 单元测试:32 个测试套件通过,228 项通过、1 项跳过。
  • npm run tsc 通过。
  • npm run lint 通过,仅有原有的 13 条警告。
  • npm run compile 通过,已核对 ES / CommonJS 类型导出和 CommonJS 入口。
  • 变更文件 Prettier 检查与 git diff --check 通过。

文档站构建未运行。后续 rc 组件接入及 antd 配置合并不在本 PR 范围内。

Summary by CodeRabbit

  • 新功能
    • 新增清除配置 Hook,可将布尔值或配置对象规范化为清除配置,并支持自定义图标、标签和按钮焦点顺序。
    • 导出该 Hook 及其配置类型。
  • 文档
    • 新增使用说明,涵盖默认行为、配置字段保留,以及清除按钮的显示规则。

@vercel

vercel Bot commented Oct 13, 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 Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1555610-db62-4359-99df-b859c8a08b06
📥 Commits

Reviewing files that changed from the base of the PR and between 993255e and ce6ef27.

📒 Files selected for processing (4)
  • docs/demo/useAllowClear.md
  • src/hooks/useAllowClear.ts
  • src/index.ts
  • tests/useAllowClear.test.tsx

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

Walkthrough

新增 useAllowClear Hook,将布尔值或配置对象规范化为 AllowClearConfig。同时新增公开导出、使用文档和测试,覆盖配置字段、输入不可变性及结果记忆化。

Changes

清除配置规范化

Layer / File(s) Summary
配置规范化与验证
src/hooks/useAllowClear.ts, tests/useAllowClear.test.tsx
新增 AllowClearConfig 和 useAllowClear。测试覆盖布尔值与对象输入的规范化、字段保留、输入不可变性,以及输入不变时的引用稳定性。
公开导出与使用文档
src/index.ts, docs/demo/useAllowClear.md
新增 Hook 和类型的公开导出。文档说明配置规则、记忆化行为及组件使用约定。

Priority: ⬇️ Low

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

Change: Feature

Merge Risk: ⚪ Minimal · up to ce6ef

The shared clear-configuration hook appears ready to merge after normal checks.

Pre-merge checks · Passed 5
Passed Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“feat: add shared useAllowClear hook”准确概括了本次新增共享 useAllowClear Hook 的主要变更,并且简洁明确。
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 3 files. (1 skipped: 1 …
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 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

我是小兔,捧来新 Hook,
布尔与配置,排成清晰路。
字段稳稳留,输入不受扰,
引用随输入,安静守约好。
月光下我蹦跳,祝代码顺畅!

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.00%. Comparing base (993255e) to head (ce6ef27).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #820      +/-   ##
==========================================
+ Coverage   86.94%   87.00%   +0.05%     
==========================================
  Files          41       42       +1     
  Lines        1111     1116       +5     
  Branches      404      392      -12     
==========================================
+ Hits          966      971       +5     
  Misses        143      143              
  Partials        2        2              

☔ 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.

@zombieJ
zombieJ merged commit 6e7a022 into react-component:master Oct 13, 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