File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change 1- import * as React from 'react' ;
2- import { useRef , useEffect } from 'react' ;
31import classNames from 'classnames' ;
4- import KeyCode from 'rc-util/lib/KeyCode' ;
5- import useId from 'rc-util/lib/hooks/useId' ;
62import contains from 'rc-util/lib/Dom/contains' ;
3+ import useId from 'rc-util/lib/hooks/useId' ;
4+ import KeyCode from 'rc-util/lib/KeyCode' ;
75import pickAttrs from 'rc-util/lib/pickAttrs' ;
6+ import * as React from 'react' ;
7+ import { useEffect , useRef } from 'react' ;
88import type { IDialogPropTypes } from '../IDialogPropTypes' ;
9- import Mask from './Mask' ;
109import { getMotionName } from '../util' ;
1110import Content from './Content' ;
1211import type { ContentRef } from './Content/Panel' ;
12+ import Mask from './Mask' ;
1313
1414export default function Dialog ( props : IDialogPropTypes ) {
1515 const {
@@ -25,6 +25,7 @@ export default function Dialog(props: IDialogPropTypes) {
2525 wrapClassName,
2626 wrapProps,
2727 onClose,
28+ afterOpenChange,
2829 afterClose,
2930
3031 // Dialog
@@ -86,6 +87,7 @@ export default function Dialog(props: IDialogPropTypes) {
8687 afterClose ?.( ) ;
8788 }
8889 }
90+ afterOpenChange ?.( newVisible ) ;
8991 }
9092
9193 function onInternalClose ( e : React . SyntheticEvent ) {
Original file line number Diff line number Diff line change 1- import type { ReactNode , CSSProperties , SyntheticEvent } from 'react' ;
21import type { GetContainer } from 'rc-util/lib/PortalWrapper' ;
2+ import type { CSSProperties , ReactNode , SyntheticEvent } from 'react' ;
33
44export type IDialogPropTypes = {
55 className ?: string ;
@@ -8,6 +8,7 @@ export type IDialogPropTypes = {
88 mask ?: boolean ;
99 children ?: any ;
1010 afterClose ?: ( ) => any ;
11+ afterOpenChange ?: ( open : boolean ) => void ;
1112 onClose ?: ( e : SyntheticEvent ) => any ;
1213 closable ?: boolean ;
1314 maskClosable ?: boolean ;
Original file line number Diff line number Diff line change @@ -504,4 +504,18 @@ describe('dialog', () => {
504504 expect ( afterClose ) . toHaveBeenCalledTimes ( 0 ) ;
505505 } ) ;
506506 } ) ;
507+
508+ describe ( 'afterOpenChange' , ( ) => {
509+ it ( 'should trigger afterOpenChange when visible changed' , ( ) => {
510+ const afterOpenChange = jest . fn ( ) ;
511+
512+ const wrapper = mount ( < Dialog afterOpenChange = { afterOpenChange } visible /> ) ;
513+ jest . runAllTimers ( ) ;
514+
515+ wrapper . setProps ( { visible : false } ) ;
516+ jest . runAllTimers ( ) ;
517+
518+ expect ( afterOpenChange ) . toHaveBeenCalledTimes ( 2 ) ;
519+ } ) ;
520+ } ) ;
507521} ) ;
You can’t perform that action at this time.
0 commit comments