From 0b9d9d3f3d406c11cfd2118670a55945fd42a66a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 13 Jul 2025 00:22:28 +0800 Subject: [PATCH] fix: react hook --- src/components/timeline/CategorySelector.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/timeline/CategorySelector.tsx b/src/components/timeline/CategorySelector.tsx index b22d506..213a670 100644 --- a/src/components/timeline/CategorySelector.tsx +++ b/src/components/timeline/CategorySelector.tsx @@ -73,15 +73,6 @@ export const CategorySelector: React.FC = ({ } }, [isOpen, onCancel]) - // 自动聚焦 - React.useEffect(() => { - if (isOpen && dropdownRef.current) { - dropdownRef.current.focus() - } - }, [isOpen]) - - if (!isOpen) return null - // 计算下拉框位置,确保不超出视窗 const adjustedPosition = React.useMemo(() => { const maxHeight = 300 // 下拉框最大高度 @@ -102,6 +93,16 @@ export const CategorySelector: React.FC = ({ return { x: Math.max(padding, x), y: Math.max(padding, y) } }, [position]) + // 自动聚焦 + React.useEffect(() => { + if (isOpen && dropdownRef.current) { + dropdownRef.current.focus() + } + }, [isOpen]) + + // 如果不显示,返回 null + if (!isOpen) return null + const dropdown = (