fix: react hook

This commit is contained in:
root 2025-07-13 00:22:28 +08:00
parent cb494dd28e
commit 0b9d9d3f3d
1 changed files with 10 additions and 9 deletions

View File

@ -73,15 +73,6 @@ export const CategorySelector: React.FC<CategorySelectorProps> = ({
}
}, [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<CategorySelectorProps> = ({
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 = (
<div
ref={dropdownRef}