fix: revert changes to closeOnBlur and add closeOnClickOutside

This commit is contained in:
Antonella Sgarlatta
2021-05-04 15:44:12 -03:00
parent 15db4767f5
commit 45357c1976
3 changed files with 12 additions and 16 deletions

View File

@@ -15,10 +15,16 @@ const NotesContextMenu = observer(({ appState }: Props) => {
(open: boolean) => appState.notes.setContextMenuOpen(open)
);
const closeOnClickOutside = (event: MouseEvent) => {
if (!contextMenuRef.current?.contains(event.target as Node)) {
appState.notes.setContextMenuOpen(false);
}
};
useEffect(() => {
document.addEventListener('click', closeOnBlur);
document.addEventListener('click', closeOnClickOutside);
return () => {
document.removeEventListener('click', closeOnBlur);
document.removeEventListener('click', closeOnClickOutside);
};
});