Spaces:
Sleeping
Sleeping
Update src/components/Category/CategorySelector.tsx
Browse files
src/components/Category/CategorySelector.tsx
CHANGED
@@ -48,6 +48,7 @@ const CategorySelector: React.FC<CategorySelectorProps> = ({
|
|
48 |
};
|
49 |
|
50 |
const handleCategorySelect = (categoryId: string) => {
|
|
|
51 |
onChange(categoryId);
|
52 |
setShowDropdown(false);
|
53 |
};
|
@@ -79,7 +80,12 @@ const CategorySelector: React.FC<CategorySelectorProps> = ({
|
|
79 |
<div
|
80 |
key={category._id}
|
81 |
className="px-4 py-2 text-sm hover:bg-gray-100 cursor-pointer flex items-center"
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
83 |
>
|
84 |
<div
|
85 |
className="w-3 h-3 rounded-full mr-2"
|
|
|
48 |
};
|
49 |
|
50 |
const handleCategorySelect = (categoryId: string) => {
|
51 |
+
// 重要:确保这个函数被正确调用
|
52 |
onChange(categoryId);
|
53 |
setShowDropdown(false);
|
54 |
};
|
|
|
80 |
<div
|
81 |
key={category._id}
|
82 |
className="px-4 py-2 text-sm hover:bg-gray-100 cursor-pointer flex items-center"
|
83 |
+
// 重要: 使用独立的事件处理函数,不依赖冒泡
|
84 |
+
onClick={(e) => {
|
85 |
+
e.preventDefault();
|
86 |
+
e.stopPropagation();
|
87 |
+
handleCategorySelect(category._id);
|
88 |
+
}}
|
89 |
>
|
90 |
<div
|
91 |
className="w-3 h-3 rounded-full mr-2"
|