Skip to content

Commit

Permalink
fix(HeaderColumnButtonDropdown): when user clicks away, close menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ramfox committed Sep 10, 2019
1 parent fae0bd7 commit 6fe1ed3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/components/chrome/HeaderColumnButtonDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,30 @@ const HeaderColumnButtonDropdown: React.FunctionComponent<HeaderColumnButtonDrop
setShowMenu(!showMenu)
event.stopPropagation()
}
const dropdown: any = React.useRef(null)

const handleClick = (e: MouseEvent) => {
if (dropdown.current.contains(e.target)) {
// inside click
return
}
// outside click
setShowMenu(false)
}

React.useEffect(() => {
document.addEventListener('mousedown', (e) => handleClick(e))

return () => {
document.removeEventListener('mousedown', (e) => handleClick(e))
}
})

const { icon, label = '', tooltip, onClick = toggleMenu, items } = props

return (
<div
ref={dropdown}
className='header-column header-column-dropdown'
data-tip={tooltip}
onClick={onClick}
Expand Down

0 comments on commit 6fe1ed3

Please sign in to comment.