Created
September 19, 2018 06:05
-
-
Save vladanyes/e6085b12789bd44fbcd219a52102c0d8 to your computer and use it in GitHub Desktop.
React click outside element.(no ref)
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
iconClick = () => { | |
if (this.state.showMenu === 'none') { | |
this.showMenu(); | |
document.addEventListener('click', this.iconClickOutside); | |
} else if (this.state.showMenu === 'flex') { | |
this.hideMenu(); | |
document.removeEventListener('click', this.iconClickOutside); | |
} | |
} | |
iconClickOutside = (e) => { | |
if(e.target.id !== 'swe-settings-item') { | |
this.hideMenu(); | |
return | |
} | |
this.iconClick() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment