Skip to content

Instantly share code, notes, and snippets.

@cherscarlett
Created October 5, 2019 20:39
Show Gist options
  • Save cherscarlett/d5cfaefe04f4c4c7c978f0b5d136a1eb to your computer and use it in GitHub Desktop.
Save cherscarlett/d5cfaefe04f4c4c7c978f0b5d136a1eb to your computer and use it in GitHub Desktop.
Disabling pointer events outside of your popup in React
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