Skip to content

Commit

Permalink
fix(TransionablePortal): fix state handling (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter authored and levithomason committed Jan 10, 2018
1 parent 9f195bb commit 18443ce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
11 changes: 2 additions & 9 deletions src/addons/TransitionablePortal/TransitionablePortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ export default class TransitionablePortal extends Component {
componentWillReceiveProps({ open }) {
debug('componentWillReceiveProps()', { open })

// Heads up! We apply `open` prop only when it's defined, otherwise it will break
// autocontrolled Portal
if (!_.isNil(open)) this.setState({ portalOpen: open })
this.setState({ portalOpen: open })
}

// ----------------------------------------
Expand All @@ -99,13 +97,8 @@ export default class TransitionablePortal extends Component {

handlePortalClose = () => {
debug('handlePortalClose()')
const { open } = this.props
const { portalOpen } = this.state

// Heads up! We simply call `onClose` when component is controlled with `open` prop.
// But, when it's autocontrolled we should change the state to opposite to keep the transition
// queue
if (_.isNil(open)) this.setState({ portalOpen: !portalOpen })
this.setState({ portalOpen: false })
}

handlePortalOpen = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ describe('TransitionablePortal', () => {
})

describe('open', () => {
it('blocks update of state on Portal close', () => {
it('does not block update of state on Portal close', () => {
wrapperMount(<TransitionablePortal {...requiredProps} open />)
wrapper.should.have.state('portalOpen', true)

domEvent.click(document.body)
wrapper.should.have.state('portalOpen', true)
wrapper.should.have.state('portalOpen', false)
})
})
})

0 comments on commit 18443ce

Please sign in to comment.