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 bug from issue #460 #464

Merged
merged 5 commits into from Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/Transition.js
Expand Up @@ -325,15 +325,18 @@ class Transition extends React.Component {
onTransitionEnd(node, timeout, handler) {
this.setNextCallback(handler)

if (node) {
if (this.props.addEndListener) {
this.props.addEndListener(node, this.nextCallback)
}
if (timeout != null) {
setTimeout(this.nextCallback, timeout)
}
} else {
const isNotHaveTimeoutOrListener = timeout == null && !this.props.addEndListener
dimensi marked this conversation as resolved.
Show resolved Hide resolved
if (!node || isNotHaveTimeoutOrListener) {
setTimeout(this.nextCallback, 0)
return
}

if (this.props.addEndListener) {
this.props.addEndListener(node, this.nextCallback)
}

if (timeout != null) {
setTimeout(this.nextCallback, timeout)
}
}

Expand Down Expand Up @@ -442,9 +445,11 @@ Transition.propTypes = {
* }}
* ```
*
* If the value of appear is not set, then the value from enter is taken.
* If the value of `appear` is not set, then the value from enter is taken.
*
* If the `enter` or `exit` value is `null` or `undefined`, then the timer is set to `0`
*
* @type {number | { enter?: number, exit?: number }}
* @type {number | { enter: number, exit: number, appear?: number }}
dimensi marked this conversation as resolved.
Show resolved Hide resolved
*/
timeout: (props, ...args) => {
let pt = timeoutsShape
Expand Down
4 changes: 2 additions & 2 deletions src/utils/PropTypes.js
Expand Up @@ -5,8 +5,8 @@ export const timeoutsShape =
? PropTypes.oneOfType([
PropTypes.number,
PropTypes.shape({
enter: PropTypes.number,
exit: PropTypes.number,
enter: PropTypes.number.isRequired,
exit: PropTypes.number.isRequired,
appear: PropTypes.number,
}).isRequired
])
dimensi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
43 changes: 43 additions & 0 deletions test/Transition-test.js
Expand Up @@ -438,5 +438,48 @@ describe('Transition', () => {

wrapper.setState({ in: false })
})


it('should unmount at once if not have enter timeout', done => {
const wrapper = mount(
<UnmountTransition
initialIn={false}
timeout={{ exit: 10 }}
onEnter={() => {
expect(wrapper.getStatus()).toEqual(EXITED)
expect(ReactDOM.findDOMNode(wrapper)).toExist()

done()
}}
/>
).instance()

expect(wrapper.getStatus()).toEqual(UNMOUNTED)
expect(ReactDOM.findDOMNode(wrapper)).toBeNull()

wrapper.setState({ in: true })
})


it('should unmount at once if not have exit timeout', done => {
const wrapper = mount(
<UnmountTransition
initialIn
timeout={{ enter: 10 }}
onExited={() => {
setTimeout(() => {
expect(wrapper.getStatus()).toEqual(UNMOUNTED)
expect(ReactDOM.findDOMNode(wrapper)).not.toExist()
done()
})
}}
/>
).instance()

expect(wrapper.getStatus()).toEqual(ENTERED)
expect(ReactDOM.findDOMNode(wrapper)).toExist()

wrapper.setState({ in: false })
})
dimensi marked this conversation as resolved.
Show resolved Hide resolved
})
})