mirror of https://github.com/acid-info/lsd.git
refactor: refactor toggle logic
This commit is contained in:
parent
e4f3567cec
commit
eace6c6160
|
@ -69,14 +69,18 @@ export const Dropdown: React.FC<DropdownProps> & {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const handleToggle = (open: boolean) => {
|
||||||
|
if (isControlled) {
|
||||||
|
onToggle && onToggle(open)
|
||||||
|
} else {
|
||||||
|
setOpenState(open)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const onTrigger = () => {
|
const onTrigger = () => {
|
||||||
if (disabled) return
|
if (disabled) return
|
||||||
|
|
||||||
if (isControlled) {
|
handleToggle(!open)
|
||||||
onToggle && onToggle(!open)
|
|
||||||
} else {
|
|
||||||
setOpenState(!open)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -161,13 +165,7 @@ export const Dropdown: React.FC<DropdownProps> & {
|
||||||
<DropdownMenu
|
<DropdownMenu
|
||||||
handleRef={containerRef}
|
handleRef={containerRef}
|
||||||
open={open}
|
open={open}
|
||||||
onClose={() => {
|
onClose={() => handleToggle(false)}
|
||||||
if (isControlled) {
|
|
||||||
onToggle && onToggle(false)
|
|
||||||
} else {
|
|
||||||
setOpenState(false)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
size={size}
|
size={size}
|
||||||
genericFontFamily={props.genericFontFamily}
|
genericFontFamily={props.genericFontFamily}
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue