From 10c6669aaa769a77cda990aeda487cef13211847 Mon Sep 17 00:00:00 2001 From: Dimitris Karagiannis Date: Tue, 10 Oct 2017 04:31:22 +0300 Subject: [PATCH 1/2] fix(Popup): Execute onClose when popup closes on scroll --- src/modules/Popup/Popup.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/Popup/Popup.js b/src/modules/Popup/Popup.js index d4e6bc3113..cebef0ee7e 100644 --- a/src/modules/Popup/Popup.js +++ b/src/modules/Popup/Popup.js @@ -278,11 +278,13 @@ 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) => { From 83d8fd6b33115fc92363b6c088fbb129035e2c42 Mon Sep 17 00:00:00 2001 From: Alexander Fedyashov Date: Thu, 26 Oct 2017 21:10:05 +0300 Subject: [PATCH 2/2] test(Popup): add test for onClose --- src/modules/Popup/Popup.js | 4 ++-- test/specs/modules/Popup/Popup-test.js | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/modules/Popup/Popup.js b/src/modules/Popup/Popup.js index cebef0ee7e..0e401b8602 100644 --- a/src/modules/Popup/Popup.js +++ b/src/modules/Popup/Popup.js @@ -289,8 +289,8 @@ export default class Popup extends Component { handleClose = (e) => { debug('handleClose()') - const { onClose } = this.props - if (onClose) onClose(e, this.props) + + _.invoke(this.props, 'onClose', e, this.props) } handleOpen = (e) => { diff --git a/test/specs/modules/Popup/Popup-test.js b/test/specs/modules/Popup/Popup-test.js index 85752c4726..41f0950ae5 100644 --- a/test/specs/modules/Popup/Popup-test.js +++ b/test/specs/modules/Popup/Popup-test.js @@ -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 = - window.dispatchEvent(evt) + wrapperMount() + .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 }) }) })