-
Notifications
You must be signed in to change notification settings - Fork 808
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
v3 don't respect closeTimeoutMS
on unmount anymore
#530
Comments
Hi @Kerumen, prefer to using |
Yes I know. In my case I can't really use |
On |
I tried but no luck. Event with the line commented out the modal seems to unmount instantly. |
Possibly. I'll try something this evening. |
Hey @diasbruno. Is there any movement on this bug? We are really keen to upgrade our project to React 16 and this is the only issue holding us up :-) We are keen to keep using this great library! |
@TeamChad Can you do some debugging on this issue? I didn't have time yet to have look at this one (sorry), but I can give some help...One place to look at is the documentation of |
@Kerumen If you change your rendering of the modal to what's below this will solve the issue in your "not working" codesandbox.io link. I had used conditional rendering and needed to make this change after updating React.
|
Hello folks I did some debugging. Finally! Here's what I found. React 16 does not provide any control over unmounting the portal. The portal unmounts whenever the parent unmounts. facebook/react#10143 (comment) – this issue clarifies that The issue further points out that the ability to control the unmounting of portal with So, henceforth we will not be able to control the unmounting of the portal using the Now lets take a look at React Modal code. I will present what I understand after the debugging. react-modal/src/components/Modal.js Lines 150 to 169 in 4377cc8
In case of React 15, unmounting the parent will set up a timer. And after the timer elapses, react-modal/src/components/Modal.js Lines 171 to 175 in 4377cc8
In React 15, the fading out animation of the portal takes place between these In React 16, we lose the ability to schedule the unmounting of the portal itself. Hence we cannot perform any animation. |
Odd. I'm able to fade out without any issue. Running:
and basically just using http://reactcommunity.org/react-modal/styles/transitions.html |
Somebody find the solution for closing animation? |
I am using import React from "react"
import ReactModal from "react-modal"
import { navigate } from "gatsby"
import "./modal.component.scss"
/**
* Necessary implementation for screen-readers. Read more:
* http://reactcommunity.org/react-modal/examples/set_app_element.html
*/
ReactModal.setAppElement(`#___gatsby`)
class Modal extends React.Component {
classes = {
overlayClassName: {
base: `modal__backdrop`,
afterOpen: `modal__backdrop--after-open`
},
className: {
base: `modal__inner`,
afterOpen: `modal__inner--after-open`
},
bodyOpenClassName: `modal__body--open`
}
options = {
closeTimeout: 660
}
cssVariables = {
// Necessary CSS variable for modal transition
//
'--modal-transition-duration': `${this.options.closeTimeout}ms`,
// Optional CSS variables to adjust modal behaviour
//
// '--modal-overlay-color': `255, 255, 255`,
// '--modal-overlay-alpha': `0.9`,
// '--modal-timing-function': `cubic-bezier(.86 ,0, .32, 1)`,
// '--modal-body-shift': `-10vw`;
}
constructor() {
super()
this.state = {
showModal: false
}
}
componentDidMount() {
this.applyCssVariables()
this.showModal()
}
componentWillUnmount() {
this.removeCssVariables()
}
render() {
const { children } = this.props
const { showModal } = this.state
const { closeTimeout } = this.options
return (
<ReactModal
isOpen={showModal}
onRequestClose={() => this.hideModal()}
closeTimeoutMS={closeTimeout}
{...this.classes}
>
<div className="container">
{children}
</div>
</ReactModal>
)
}
/**
* Changes state to opened modal.
*/
showModal() {
this.setState({
showModal: true
})
}
/**
* changes state to closed modal and navigates to the index page.
*/
hideModal() {
const { closeTimeout } = this.options
const { bodyOpenClassName, className, overlayClassName } = this.classes
document.body.classList.remove(bodyOpenClassName)
document.querySelector(`.${className.base}`).classList.remove(className.afterOpen)
document.querySelector(`.${overlayClassName.base}`).classList.remove(overlayClassName.afterOpen)
setTimeout(() => {
this.setState({
showModal: false
})
navigate(`/`)
}, closeTimeout)
//
}
/**
* Applys all CSS Variables to the document so the stylesheet
* can use certain variables required for the modal behaviour.
*/
applyCssVariables() {
Object.keys(this.cssVariables).forEach(key => {
const value = this.cssVariables[key]
return document.documentElement.style.setProperty(key, value)
})
}
/**
* Removes all CSS variables in order not to spoil the DOM unnecessarily.
*/
removeCssVariables() {
Object.keys(this.cssVariables).forEach(key => {
const value = this.cssVariables[key]
document.documentElement.style.removeProperty(key, value)
})
}
}
export default Modal If you're having questions, let me know. I will explain the code. |
I'm closing this one. It looks like a bug, but actually is how the new behavior of |
Summary:
Before the React 16 compatibility, we were able to unmount the modal with an animation. It's not possible anymore with the
v3
.Steps to reproduce:
<Modal />
withcloseTimeoutMS={200}
Expected behavior:
The Modal should unmount with an animation.
Link to example of issue:
React 15 and v2: https://codesandbox.io/s/7k63p8lk81 (working)
React 16 and v3: https://codesandbox.io/s/mml6ql88py (not working)
The text was updated successfully, but these errors were encountered: