fix: react hook
This commit is contained in:
@@ -73,15 +73,6 @@ export const CategorySelector: React.FC<CategorySelectorProps> = ({
|
|||||||
}
|
}
|
||||||
}, [isOpen, onCancel])
|
}, [isOpen, onCancel])
|
||||||
|
|
||||||
// 自动聚焦
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (isOpen && dropdownRef.current) {
|
|
||||||
dropdownRef.current.focus()
|
|
||||||
}
|
|
||||||
}, [isOpen])
|
|
||||||
|
|
||||||
if (!isOpen) return null
|
|
||||||
|
|
||||||
// 计算下拉框位置,确保不超出视窗
|
// 计算下拉框位置,确保不超出视窗
|
||||||
const adjustedPosition = React.useMemo(() => {
|
const adjustedPosition = React.useMemo(() => {
|
||||||
const maxHeight = 300 // 下拉框最大高度
|
const maxHeight = 300 // 下拉框最大高度
|
||||||
@@ -102,6 +93,16 @@ export const CategorySelector: React.FC<CategorySelectorProps> = ({
|
|||||||
return { x: Math.max(padding, x), y: Math.max(padding, y) }
|
return { x: Math.max(padding, x), y: Math.max(padding, y) }
|
||||||
}, [position])
|
}, [position])
|
||||||
|
|
||||||
|
// 自动聚焦
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isOpen && dropdownRef.current) {
|
||||||
|
dropdownRef.current.focus()
|
||||||
|
}
|
||||||
|
}, [isOpen])
|
||||||
|
|
||||||
|
// 如果不显示,返回 null
|
||||||
|
if (!isOpen) return null
|
||||||
|
|
||||||
const dropdown = (
|
const dropdown = (
|
||||||
<div
|
<div
|
||||||
ref={dropdownRef}
|
ref={dropdownRef}
|
||||||
|
|||||||
Reference in New Issue
Block a user