Skip to content

Commit 7e76af9

Browse files
author
Sasha Kondrashov
committed
modal
1 parent be43928 commit 7e76af9

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/modules/Modal/Modal.d.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,43 @@ export interface StrictModalProps extends StrictPortalProps {
6262
* Action onClick handler when using shorthand `actions`.
6363
*
6464
* @param {SyntheticEvent} event - React's original SyntheticEvent.
65-
* @param {object} data - All props.
65+
* @param {object} props - All props.
6666
*/
67-
onActionClick?: (event: React.MouseEvent<HTMLElement>, data: ModalProps) => void
67+
onActionClick?: (event: React.MouseEvent<HTMLElement>, props: ModalProps) => void
6868

6969
/**
7070
* Called when a close event happens.
7171
*
7272
* @param {SyntheticEvent} event - React's original SyntheticEvent.
73-
* @param {object} data - All props.
73+
* @param {object} props - All props.
74+
* @param {boolean} open - Whether the modal is displayed.
7475
*/
75-
onClose?: (event: React.MouseEvent<HTMLElement>, data: ModalProps) => void
76+
onClose?: (event: React.MouseEvent<HTMLElement>, props: ModalProps, open: boolean) => void
7677

7778
/**
7879
* Called when the portal is mounted on the DOM.
7980
*
8081
* @param {null}
81-
* @param {object} data - All props.
82+
* @param {object} props - All props.
8283
*/
83-
onMount?: (nothing: null, data: ModalProps) => void
84+
onMount?: (nothing: null, props: ModalProps) => void
8485

8586
/**
8687
* Called when an open event happens.
8788
*
8889
* @param {SyntheticEvent} event - React's original SyntheticEvent.
89-
* @param {object} data - All props.
90+
* @param {object} props - All props.
91+
* @param {boolean} open - Whether the modal is displayed.
9092
*/
91-
onOpen?: (event: React.MouseEvent<HTMLElement>, data: ModalProps) => void
93+
onOpen?: (event: React.MouseEvent<HTMLElement>, props: ModalProps, open: boolean) => void
9294

9395
/**
9496
* Called when the portal is unmounted from the DOM.
9597
*
9698
* @param {null}
97-
* @param {object} data - All props.
99+
* @param {object} props - All props.
98100
*/
99-
onUnmount?: (nothing: null, data: ModalProps) => void
101+
onUnmount?: (nothing: null, props: ModalProps) => void
100102

101103
/** Controls whether or not the Modal is displayed. */
102104
open?: boolean

src/modules/Modal/Modal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const Modal = React.forwardRef(function (props, ref) {
108108
debug('close()')
109109

110110
setOpen(false)
111-
_.invoke(props, 'onClose', e, { ...props, open: false })
111+
_.invoke(props, 'onClose', e, props, false)
112112
}
113113

114114
const handleDocumentMouseDown = (e) => {
@@ -129,14 +129,14 @@ const Modal = React.forwardRef(function (props, ref) {
129129
return
130130

131131
setOpen(false)
132-
_.invoke(props, 'onClose', e, { ...props, open: false })
132+
_.invoke(props, 'onClose', e, props, false)
133133
}
134134

135135
const handleOpen = (e) => {
136136
debug('open()')
137137

138138
setOpen(true)
139-
_.invoke(props, 'onOpen', e, { ...props, open: true })
139+
_.invoke(props, 'onOpen', e, props, true)
140140
}
141141

142142
const handlePortalMount = (e) => {

test/specs/modules/Modal/Modal-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ describe('Modal', () => {
277277

278278
wrapper.find('#trigger').simulate('click')
279279
onOpen.should.have.been.calledOnce()
280-
onOpen.should.have.been.calledWithMatch({ type: 'click' }, { open: true })
280+
onOpen.should.have.been.calledWithMatch({ type: 'click' }, {}, true)
281281
})
282282

283283
it('is not called on body click', () => {
@@ -296,7 +296,7 @@ describe('Modal', () => {
296296

297297
domEvent.click('.ui.dimmer')
298298
onClose.should.have.been.calledOnce()
299-
onClose.should.have.been.calledWithMatch({}, { open: false })
299+
onClose.should.have.been.calledWithMatch({}, {}, false)
300300
})
301301

302302
it('is called on click outside of the modal', () => {
@@ -305,6 +305,7 @@ describe('Modal', () => {
305305

306306
domEvent.click(document.querySelector('.ui.modal').parentNode)
307307
onClose.should.have.been.calledOnce()
308+
onClose.should.have.been.calledWithMatch({}, {}, false)
308309
})
309310

310311
it('is not called on mousedown inside and mouseup outside of the modal', () => {
@@ -338,6 +339,7 @@ describe('Modal', () => {
338339

339340
domEvent.keyDown(document, { key: 'Escape' })
340341
onClose.should.have.been.calledOnce()
342+
onClose.should.have.been.calledWithMatch({}, {}, false)
341343
})
342344

343345
it('is not called when the open prop changes to false', () => {

0 commit comments

Comments
 (0)