Skip to content
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

fix: 修复 Tag 组件在点击关闭时触发 onClick 的问题 #712

Merged
merged 2 commits into from
Oct 12, 2024

Conversation

KMS-Bismarck
Copy link
Collaborator

@KMS-Bismarck KMS-Bismarck commented Oct 11, 2024

Types of changes

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Others

Changelog

  • 修复 Tag 组件在点击关闭时触发 onClick 的问题

Other information

Summary by CodeRabbit

  • Bug Fixes
    • 修复了标签关闭操作的事件处理,确保关闭操作不会触发父元素上的其他事件监听器。
  • 版本更新
    • 将版本号从 "3.4.3-beta.10" 更新至 "3.4.3-beta.11"。
  • 文档更新
    • 在变更日志中添加了版本 "3.4.3-beta.11" 的新条目,记录了相关的修复信息。

Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

此次更改涉及 packages/base/src/tag/use-tag.ts 文件中的 useTag 钩子。具体而言,在 handleClose 函数中新增了一行代码 e.stopPropagation();,该行代码用于阻止事件向上冒泡,确保关闭操作不会意外触发附加在父元素上的其他事件监听器。整体结构和逻辑保持不变,没有其他显著的控制流或功能更改。

Changes

文件路径 更改摘要
packages/base/src/tag/use-tag.ts handleClose 函数中新增 e.stopPropagation(); 以阻止事件冒泡。
package.json 更新版本号:"3.4.3-beta.10""3.4.3-beta.11"
packages/shineout/src/tag/doc/changelog.cn.md 新增版本条目 3.4.3-beta.11,包括修复 onClick 事件触发的问题。

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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 40f0eb4 and ef3fcba.

📒 Files selected for processing (1)
  • packages/base/src/tag/use-tag.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
packages/base/src/tag/use-tag.ts (1)

69-69: 修复了关闭按钮触发 onClick 的问题

添加 e.stopPropagation(); 是一个很好的解决方案。这行代码阻止了点击事件向上冒泡,从而解决了关闭按钮触发 Tag 组件 onClick 事件的问题。

这个修改:

  1. 直接解决了 PR 中描述的问题。
  2. 不影响组件的其他功能。
  3. 在函数开始时调用,确保即使函数提前返回,事件传播也会被阻止。

@@ -66,6 +66,7 @@ const useTag = (props: BaseTagProps) => {
};

const handleClose = (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

缺少 Tag 组件的测试用例

目前未找到与 Tag 组件相关的测试文件。建议添加相应的单元测试,以验证 e.stopPropagation() 的行为并防止未来的回归问题。

🔗 Analysis chain

建议添加注释并考虑测试覆盖

虽然这个修改解决了问题,但我有以下建议:

  1. 考虑添加一个简短的注释,解释为什么需要 e.stopPropagation()。这将有助于其他开发者理解这行代码的重要性。

  2. 请确保更新或添加相关的单元测试,以验证这个新行为。这将有助于防止将来可能的回归。

建议的代码修改:

 const handleClose = (e: React.MouseEvent<HTMLDivElement>) => {
+  // 阻止事件冒泡,避免触发 Tag 的 onClick 事件
   e.stopPropagation();
   if (disabled || dismiss !== Finish) {
     return;
   }
   handleDismiss(e);
 };

为了确保测试覆盖,可以运行以下命令来检查相关测试文件:

这将帮助我们确认是否需要更新现有测试或添加新的测试用例。

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 搜索与 Tag 组件相关的测试文件
fd -e test.ts -e test.tsx | grep -i tag

# 如果存在测试文件,显示其内容
test_file=$(fd -e test.ts -e test.tsx | grep -i tag | head -n 1)
if [ -n "$test_file" ]; then
    echo "Found test file: $test_file"
    echo "Content:"
    cat "$test_file"
else
    echo "No test file found for Tag component"
fi

Length of output: 210

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

🧹 Outside diff range and nitpick comments (1)
packages/shineout/src/tag/__doc__/changelog.cn.md (1)

1-5: 更改看起来不错,但可以稍作改进。

新的更新日志条目准确地描述了修复的问题,并且格式与现有条目一致。然而,我们可以稍微调整一下措辞以提高清晰度。

建议将描述修改为:

- 修复 `Tag` 组件在 `onClose` 时触发 onClick 的问题
+ 修复 `Tag` 组件在点击关闭按钮时错误触发 `onClick` 事件的问题

这样可以更准确地描述问题的具体情况,使读者更容易理解修复的内容。

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ef3fcba and bdac557.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • packages/shineout/src/tag/doc/changelog.cn.md (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used

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.

1 participant