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 = (