Created
November 12, 2017 14:32
-
-
Save nash403/1a7659bb7cc06f2ea235bf01a49935c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function hideOnClickOutside(selector) { | |
const outsideClickListener = (event) => { | |
if (!$(event.target).closest(selector).length) { | |
if ($(selector).is(':visible')) { | |
$(selector).hide() | |
removeClickListener() | |
} | |
} | |
} | |
const removeClickListener = () => { | |
document.removeEventListener('click', outsideClickListener) | |
} | |
document.addEventListener('click', outsideClickListener) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment