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 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/Transition.js
Original file line number Diff line number Diff line change
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 doesNotHaveTimeoutOrListener = timeout == null && !this.props.addEndListener
if (!node || doesNotHaveTimeoutOrListener) {
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 }}
*/
timeout: (props, ...args) => {
let pt = timeoutsShape
Expand Down
25 changes: 25 additions & 0 deletions test/Transition-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,31 @@ describe('Transition', () => {
inst.setProps({ in: true })
})

it('should mount/unmount immediately if not have enter/exit timeout', (done) => {
const wrapper = mount(
<Transition in={true} timeout={{}}>
<div />
</Transition>
)

expect(wrapper.state('status')).toEqual(ENTERED)
let calledAfterTimeout = false
setTimeout(() => {
calledAfterTimeout = true
}, 10)
wrapper.setProps({
in: false,
onExited() {
expect(wrapper.state('status')).toEqual(EXITED)
if (calledAfterTimeout) {
throw new Error('wrong timeout')
} else {
done()
}
}
})
})

describe('appearing timeout', () => {
it('should use enter timeout if appear not set', done => {
let calledBeforeEntered = false
Expand Down