fix: react hook
This commit is contained in:
parent
cb494dd28e
commit
0b9d9d3f3d
|
|
@ -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}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue