Skip to content

Commit f0c8485

Browse files
author
Sasha Kondrashov
committed
popup
1 parent ae015ac commit f0c8485

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/modules/Popup/Popup.d.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,35 @@ export interface StrictPopupProps extends StrictPortalProps {
7474
* Called when a close event happens.
7575
*
7676
* @param {SyntheticEvent} event - React's original SyntheticEvent.
77-
* @param {object} data - All props.
77+
* @param {object} props - All props.
78+
* @param {boolean} open - Whether the popup is displayed.
7879
*/
79-
onClose?: (event: React.MouseEvent<HTMLElement>, data: PopupProps) => void
80+
onClose?: (event: React.MouseEvent<HTMLElement>, props: PopupProps, open: boolean) => void
8081

8182
/**
8283
* Called when the portal is mounted on the DOM.
8384
*
8485
* @param {null}
85-
* @param {object} data - All props.
86+
* @param {object} props - All props.
8687
*/
87-
onMount?: (nothing: null, data: PopupProps) => void
88+
onMount?: (nothing: null, props: PopupProps) => void
8889

8990
/**
9091
* Called when an open event happens.
9192
*
9293
* @param {SyntheticEvent} event - React's original SyntheticEvent.
93-
* @param {object} data - All props.
94+
* @param {object} props - All props.
95+
* @param {boolean} open - Whether the popup is displayed
9496
*/
95-
onOpen?: (event: React.MouseEvent<HTMLElement>, data: PopupProps) => void
97+
onOpen?: (event: React.MouseEvent<HTMLElement>, props: PopupProps, open: boolean) => void
9698

9799
/**
98100
* Called when the portal is unmounted from the DOM.
99101
*
100102
* @param {null}
101-
* @param {object} data - All props.
103+
* @param {object} props - All props.
102104
*/
103-
onUnmount?: (nothing: null, data: PopupProps) => void
105+
onUnmount?: (nothing: null, props: PopupProps) => void
104106

105107
/** Disables automatic repositioning of the component, it will always be placed according to the position value. */
106108
pinned?: boolean

src/modules/Popup/Popup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ const Popup = React.forwardRef(function (props, ref) {
171171

172172
const handleClose = (e) => {
173173
debug('handleClose()')
174-
_.invoke(props, 'onClose', e, { ...props, open: false })
174+
_.invoke(props, 'onClose', e, props, false)
175175
}
176176

177177
const handleOpen = (e) => {
178178
debug('handleOpen()')
179-
_.invoke(props, 'onOpen', e, { ...props, open: true })
179+
_.invoke(props, 'onOpen', e, props, true)
180180
}
181181

182182
const hideOnScroll = (e) => {

test/specs/modules/Popup/Popup-test.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('Popup', () => {
150150
assertInBody('.ui.popup.visible', false)
151151
})
152152

153-
it('is called with (e, props) when scroll', () => {
153+
it('is called on scroll', () => {
154154
const onClose = sandbox.spy()
155155

156156
wrapperMount(<Popup content='foo' hideOnScroll onClose={onClose} trigger={trigger} />)
@@ -159,7 +159,7 @@ describe('Popup', () => {
159159
domEvent.scroll(window)
160160

161161
onClose.should.have.been.calledOnce()
162-
onClose.should.have.been.calledWithMatch({}, { content: 'foo', onClose, trigger })
162+
onClose.should.have.been.calledWithMatch({}, { content: 'foo', onClose, trigger }, false)
163163
})
164164

165165
it('not hide on scroll from inside a popup', () => {
@@ -178,6 +178,7 @@ describe('Popup', () => {
178178

179179
domEvent.scroll(window)
180180
onClose.should.have.been.calledOnce()
181+
onClose.should.have.been.calledWithMatch({}, {}, false)
181182
})
182183
})
183184

@@ -222,6 +223,7 @@ describe('Popup', () => {
222223

223224
domEvent.click('body')
224225
onClose.should.have.been.calledOnce()
226+
onClose.should.have.been.calledWithMatch({}, {}, false)
225227
})
226228

227229
it('is called when pressing escape', () => {
@@ -230,6 +232,7 @@ describe('Popup', () => {
230232

231233
domEvent.keyDown(document, { key: 'Escape' })
232234
onClose.should.have.been.calledOnce()
235+
onClose.should.have.been.calledWithMatch({}, {}, false)
233236
})
234237

235238
it('is not called when the open prop changes to false', () => {
@@ -252,7 +255,7 @@ describe('Popup', () => {
252255

253256
wrapper.find('#trigger').simulate('click')
254257
onOpen.should.have.been.calledOnce()
255-
onOpen.should.have.been.calledWithMatch({}, { open: true })
258+
onOpen.should.have.been.calledWithMatch({}, {}, true)
256259
})
257260
})
258261

@@ -267,7 +270,7 @@ describe('Popup', () => {
267270

268271
domEvent.click(document.body)
269272
onClose.should.have.been.called()
270-
onClose.should.have.been.calledWithMatch({}, { open: false })
273+
onClose.should.have.been.calledWithMatch({}, {}, false)
271274
})
272275
})
273276

0 commit comments

Comments
 (0)