refactor: refactor toggle logic

This commit is contained in:
jongomez 2023-09-29 10:49:18 +01:00 committed by Jon
parent e4f3567cec
commit eace6c6160
1 changed files with 10 additions and 12 deletions

View File

@ -69,14 +69,18 @@ export const Dropdown: React.FC<DropdownProps> & {
},
})
const handleToggle = (open: boolean) => {
if (isControlled) {
onToggle && onToggle(open)
} else {
setOpenState(open)
}
}
const onTrigger = () => {
if (disabled) return
if (isControlled) {
onToggle && onToggle(!open)
} else {
setOpenState(!open)
}
handleToggle(!open)
}
useEffect(() => {
@ -161,13 +165,7 @@ export const Dropdown: React.FC<DropdownProps> & {
<DropdownMenu
handleRef={containerRef}
open={open}
onClose={() => {
if (isControlled) {
onToggle && onToggle(false)
} else {
setOpenState(false)
}
}}
onClose={() => handleToggle(false)}
size={size}
genericFontFamily={props.genericFontFamily}
>