Skip to content

Commit

Permalink
[components] Require setOpen property for MenuButton
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Oct 6, 2020
1 parent 1c327fe commit 430f4f9
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/@sanity/components/src/menuButton/menuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface MenuButtonProps {
menu?: React.ReactNode
placement?: string
open?: boolean
setOpen?: (val: boolean) => void
setOpen: (val: boolean) => void
}

export function MenuButton(props: MenuButtonProps & React.HTMLProps<HTMLDivElement>) {
Expand All @@ -26,15 +26,8 @@ export function MenuButton(props: MenuButtonProps & React.HTMLProps<HTMLDivEleme
...restProps
} = props

const handleClickOutside = useCallback(() => {
if (!setOpen) return
setOpen(false)
}, [setOpen])

const handleButtonClick = useCallback(() => {
if (!setOpen) return
setOpen(!open)
}, [open, setOpen])
const handleClickOutside = useCallback(() => setOpen(false), [setOpen])
const handleButtonClick = useCallback(() => setOpen(!open), [open, setOpen])

return (
<ClickOutside onClickOutside={handleClickOutside}>
Expand Down

0 comments on commit 430f4f9

Please sign in to comment.