Skip to content

feat: Merge 'afterClose' to 'closable' #500

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

EmilyyyLiu
Copy link

@EmilyyyLiu EmilyyyLiu commented Jul 17, 2025

将afterClose属性合并到closable中,并添加测试与修改文档
afterClose -> closable.afterClose
关联issue ant-design/ant-design#54394

Summary by CodeRabbit

  • 文档

    • 更新了 closable 属性的说明,支持在对象类型中新增可选的 afterClose 回调,并将独立的 afterClose 属性标记为已废弃。
  • 新特性

    • 支持通过 closable 属性对象传递 afterClose 回调函数,实现更灵活的关闭后处理。
    • 优化了对关闭动画和状态更新的处理逻辑,提升关闭流程的稳定性。
  • 测试

    • 增加了同时传递新旧 afterClose 回调时的行为测试,确保兼容性。

Copy link

vercel bot commented Jul 17, 2025

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

Name Status Preview Comments Updated (UTC)
dialog ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2025 1:53am

Copy link

coderabbitai bot commented Jul 17, 2025

Walkthrough

本次变更将 Dialog 组件的关闭相关回调 afterClose 从顶层属性迁移到 closable 对象中,形成统一的 API 设计。涉及类型定义、文档、实现和测试的同步调整,保留了旧 afterClose 属性但标注为废弃,并确保新旧回调均被调用。

Changes

文件/分组 变更简述
README.md 文档中为 closable 对象类型增加 afterClose:function,顶层 afterClose 标记为废弃(删除线)。
src/IDialogPropTypes.tsx 新增 ClosableType 类型,closable 属性类型改为 ClosableType,顶层 afterClose 添加废弃说明。
src/DialogWrap.tsx 支持从 closable 对象中读取 afterClose 回调,优先调用 closable.afterClose,兼容旧 afterClose。
tests/index.spec.tsx 新增测试,验证 closable.afterClose 与废弃的 afterClose 同时存在时均被调用。
src/Dialog/index.tsx 修改 useEffect 依赖数组,确保关闭逻辑在相关状态变化时正确触发。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Dialog
    participant DialogWrap

    User->>Dialog: 关闭 Dialog
    Dialog->>DialogWrap: 触发关闭流程
    alt closable.afterClose 存在
        DialogWrap->>DialogWrap: 调用 closable.afterClose()
    end
    alt 顶层 afterClose 存在
        DialogWrap->>DialogWrap: 调用 afterClose()
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 分钟

Suggested reviewers

  • thinkasany
  • zombieJ

Poem

兔子写诗庆新规,
afterClose 搬新家。
closable 里藏玄机,
旧友不忘也照顾。
代码整齐又统一,
API 进步乐哈哈!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

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

src/DialogWrap.tsx

Oops! Something went wrong! :(

ESLint: 7.32.0

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47f3e40 and c1e9939.

📒 Files selected for processing (1)
  • src/DialogWrap.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/DialogWrap.tsx
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@EmilyyyLiu EmilyyyLiu changed the title feat: Merge 'AfterClose' to 'Closable' feat: Merge 'afterClose' to 'closable' Jul 17, 2025
Copy link

codecov bot commented Jul 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.46%. Comparing base (302f4f4) to head (9fbc534).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #500      +/-   ##
==========================================
+ Coverage   98.43%   98.46%   +0.02%     
==========================================
  Files           8        8              
  Lines         192      195       +3     
  Branches       66       68       +2     
==========================================
+ Hits          189      192       +3     
  Misses          3        3              

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

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

🧹 Nitpick comments (1)
src/Dialog/index.tsx (1)

170-170: 建议优化 useEffect 依赖项以提升性能

doClose 添加到依赖数组中虽然符合 React Hook 规则,但会导致不必要的重新渲染,因为 doClose 函数在每次组件渲染时都会重新创建。

建议使用 useCallback 包装 doClose 函数来优化性能:

-  function doClose() {
+  const doClose = React.useCallback(() => {
     // Clean up scroll bar & focus back
     setAnimatedVisible(false);

     if (mask && lastOutSideActiveElementRef.current && focusTriggerAfterClose) {
       try {
         lastOutSideActiveElementRef.current.focus({ preventScroll: true });
       } catch (e) {
         // Do nothing
       }
       lastOutSideActiveElementRef.current = null;
     }

     // Trigger afterClose only when change visible from true to false
     if (animatedVisible) {
       afterClose?.();
     }
-  }
+  }, [mask, focusTriggerAfterClose, animatedVisible, afterClose]);

这样可以避免 useEffect 因为 doClose 函数的重新创建而频繁执行。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb629f3 and 47f3e40.

📒 Files selected for processing (1)
  • src/Dialog/index.tsx (1 hunks)

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