Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Modal): map body class name before removing #817

Merged
merged 5 commits into from
Feb 9, 2018
Merged

Conversation

TheSharpieOne
Copy link
Member

Closes #665, Closes #763

src/Modal.js Outdated
const classes = document.body.className.replace(/(^| )modal-open( |$)/, ' ');
document.body.className = mapToCssModules(classNames(classes).trim(), this.props.cssModule);
setScrollbarWidth(this.originalBodyPadding);
if (!this.props.isOpen) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good check. In case that Modal never wasn't open before, it's still will removing class from body.

Copy link
Member Author

@TheSharpieOne TheSharpieOne Feb 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I ended up just resorting to keeping track of whether or not the instance added or removed the class. This way it will only ever add it if it isn't there and only remove it if it was added.
It won't prevent nested modals from adding duplicate classes to the class name, but it will ensure a single instance only contributes a single class and removes it. When all of the nested modals are closed, the body should have the same class as it did before the modals were opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants