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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sheinx",
"private": true,
"version": "3.4.3-beta.10",
"version": "3.4.3-beta.11",
"description": "A react library developed with sheinx",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/tag/use-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

if (disabled || dismiss !== Finish) {
return;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/shineout/src/tag/__doc__/changelog.cn.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.4.3-beta.11
2024-10-12
### 🐞 BugFix

- 修复 `Tag` 组件在 `onClose` 时触发 onClick 的问题 ([#712](https://github.com/sheinsight/shineout-next/pull/712))

## 3.4.2
2024-09-29
### 🐞 BugFix
Expand Down