Created
October 5, 2019 20:39
-
-
Save cherscarlett/d5cfaefe04f4c4c7c978f0b5d136a1eb to your computer and use it in GitHub Desktop.
Disabling pointer events outside of your popup in React
This file contains 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
useLayoutEffect( | |
() => { | |
const {current: menuDOM} = menuRef; | |
const body = window.document.querySelector('body'); | |
if (menuDOM && isOpen) { | |
body.style['pointer-events'] = 'none'; | |
menuDOM.style['pointer-events'] = 'initial'; | |
} else if (menuDOM && !isOpen) { | |
body.style['pointer-events'] = null; | |
menuDOM.style['pointer-events'] = null; | |
} | |
}, | |
[isOpen] | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment