Skip to content

Commit

Permalink
fix(Popup): execute onClose when Popup closes on scroll (#2182)
Browse files Browse the repository at this point in the history
* fix(Popup): Execute onClose when popup closes on scroll

* test(Popup): add test for onClose
  • Loading branch information
mkarajohn authored and layershifter committed Oct 26, 2017
1 parent f3cb7b1 commit 01b02f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/modules/Popup/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,19 @@ export default class Popup extends Component {
return portalProps
}

hideOnScroll = () => {
hideOnScroll = (e) => {
this.setState({ closed: true })

eventStack.unsub('scroll', this.hideOnScroll, { target: window })
setTimeout(() => this.setState({ closed: false }), 50)

this.handleClose(e)
}

handleClose = (e) => {
debug('handleClose()')
const { onClose } = this.props
if (onClose) onClose(e, this.props)

_.invoke(this.props, 'onClose', e, this.props)
}

handleOpen = (e) => {
Expand Down
17 changes: 12 additions & 5 deletions test/specs/modules/Popup/Popup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,21 @@ describe('Popup', () => {
wrapper.find('button').simulate('click')
assertInBody('.ui.popup.visible')

document.body.scrollTop = 100
domEvent.scroll(window)
assertInBody('.ui.popup.visible', false)
})

const evt = document.createEvent('CustomEvent')
evt.initCustomEvent('scroll', false, false, null)
it('is called with (e, props) when scroll', () => {
const onClose = sandbox.spy()
const trigger = <button>foo</button>

window.dispatchEvent(evt)
wrapperMount(<Popup content='foo' hideOnScroll onClose={onClose} trigger={trigger} />)
.find('button')
.simulate('click')

assertInBody('.ui.popup.visible', false)
domEvent.scroll(window)
onClose.should.have.been.calledOnce()
onClose.should.have.been.calledWithMatch({}, { content: 'foo', onClose, trigger })
})
})

Expand Down

0 comments on commit 01b02f7

Please sign in to comment.