Created
January 25, 2018 04:11
-
-
Save eldyvoon/179b70809ea644ce5269a02c833e200b to your computer and use it in GitHub Desktop.
react-modal css scoping parentSelector
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
//util | |
export default getClassesFromNode = node => { | |
const classnames = node && node.className | |
let classnames_in_string = '' | |
classnames.split(' ').forEach(v=>{ | |
classnames_in_string += '.' + v | |
}) | |
return ()=>document.querySelector(classnames_in_string) | |
} | |
//parent | |
<div ref={ref => this.parentNode = ref} className='account edit'> | |
</div> | |
//custom component that wrap react-modal | |
<MyModal parentClasses={getClassesFromNode(this.parentNode} | |
//actual react-modal | |
<ReactModal parentSelector={parentClasses}> | |
<div className='modal-body'>content</div> | |
</div> | |
//css to style modal content | |
.acount.edit { | |
modal-body { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment