Skip to content

Commit

Permalink
Hide notifications when clicking outside #241
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed Aug 9, 2021
1 parent dc464f2 commit fd6efd7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/js/components/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,14 @@ const BibWebContainer = props => {
}
}, []);

const handleGlobalClick = useCallback(ev => {
if(ev.target.closest('.message')) {
// ignore clicks inside the message
return;
}
dispatch({ type: CLEAR_ALL_MESSAGES });
}, []);

const handleStyleInstallerDelete = useCallback(deleteStyleName => {
setCitationStyles(citationStyles.filter(cs => cs.name !== deleteStyleName ));
}, [citationStyles]);
Expand Down Expand Up @@ -1108,6 +1116,11 @@ const BibWebContainer = props => {
return () => document.removeEventListener('keydown', handleKeyDown);
}, [handleKeyDown]);

useEffect(() => {
document.addEventListener('click', handleGlobalClick);
return () => document.removeEventListener('click', handleGlobalClick);
}, [handleGlobalClick]);

useEffect(() => {
document.addEventListener('copy', handleCopyToClipboard, true);

Expand Down

0 comments on commit fd6efd7

Please sign in to comment.