8000 feat(CModal): add `onClosePrevented` and `onShow` event · v-rr/coreui-react@bf7592c · GitHub
[go: up one dir, main page]

Skip to content

Commit bf7592c

Browse files
committed
feat(CModal): add onClosePrevented and onShow event
1 parent 769983d commit bf7592c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/components/modal/CModal.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ export interface CModalProps extends HTMLAttributes<HTMLDivElement> {
4848
* Callback fired when the component requests to be closed.
4949
*/
5050
onClose?: () => void
51+
/**
52+
* Callback fired when the component requests to be closed.
53+
*/
54+
onClosePrevented?: () => void
55+
/**
56+
* Callback fired when the modal is shown, its backdrop is static and a click outside the modal or an escape key press is performed with the keyboard option set to false.
57+
*/
58+
onShow?: () => void
5159
/**
5260
* Generates modal using createPortal.
5361
*/
@@ -88,6 +96,8 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
8896
fullscreen,
8997
keyboard = true,
9098
onClose,
99+
onClosePrevented,
100+
onShow,
91101
portal = true,
92102
scrollable,
93103
size,
@@ -119,6 +129,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
119129
}
120130

121131
useLayoutEffect(() => {
132+
onClosePrevented && onClosePrevented()
122133
setTimeout(() => setStaticBackdrop(false), duration)
123134
}, [staticBackdrop])
124135

@@ -194,6 +205,7 @@ export const CModal = forwardRef<HTMLDivElement, CModalProps>(
194205
<CSSTransition
195206
in={_visible}
196207
timeout={!transition ? 0 : duration}
208+
onEnter={onShow}
197209
onExit={onClose}
198210
mountOnEnter
199211
unmountOnExit
@@ -226,6 +238,8 @@ CModal.propTypes = {
226238
]),
227239
keyboard: PropTypes.bool,
228240
onClose: PropTypes.func,
241+
onClosePrevented: PropTypes.func,
242+
onShow: PropTypes.func,
229243
portal: PropTypes.bool,
230244
scrollable: PropTypes.bool,
231245
size: PropTypes.oneOf(['sm', 'lg', 'xl']),

0 commit comments

Comments
 (0)
0