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' ;
3
1
import classNames from 'classnames' ;
4
- import KeyCode from 'rc-util/lib/KeyCode' ;
5
- import useId from 'rc-util/lib/hooks/useId' ;
6
2
import contains from 'rc-util/lib/Dom/contains' ;
3
+ import useId from 'rc-util/lib/hooks/useId' ;
4
+ import KeyCode from 'rc-util/lib/KeyCode' ;
7
5
import pickAttrs from 'rc-util/lib/pickAttrs' ;
6
+ import * as React from 'react' ;
7
+ import { useEffect , useRef } from 'react' ;
8
8
import type { IDialogPropTypes } from '../IDialogPropTypes' ;
9
- import Mask from './Mask' ;
10
9
import { getMotionName } from '../util' ;
11
10
import Content from './Content' ;
12
11
import type { ContentRef } from './Content/Panel' ;
12
+ import Mask from './Mask' ;
13
13
14
14
export default function Dialog ( props : IDialogPropTypes ) {
15
15
const {
@@ -25,6 +25,7 @@ export default function Dialog(props: IDialogPropTypes) {
25
25
wrapClassName,
26
26
wrapProps,
27
27
onClose,
28
+ afterOpenChange,
28
29
afterClose,
29
30
30
31
// Dialog
@@ -86,6 +87,7 @@ export default function Dialog(props: IDialogPropTypes) {
86
87
afterClose ?.( ) ;
87
88
}
88
89
}
90
+ afterOpenChange ?.( newVisible ) ;
89
91
}
90
92
91
93
function onInternalClose ( e : React . SyntheticEvent ) {
Original file line number Diff line number Diff line change 1
- import type { ReactNode , CSSProperties , SyntheticEvent } from 'react' ;
2
1
import type { GetContainer } from 'rc-util/lib/PortalWrapper' ;
2
+ import type { CSSProperties , ReactNode , SyntheticEvent } from 'react' ;
3
3
4
4
export type IDialogPropTypes = {
5
5
className ?: string ;
@@ -8,6 +8,7 @@ export type IDialogPropTypes = {
8
8
mask ?: boolean ;
9
9
children ?: any ;
10
10
afterClose ?: ( ) => any ;
11
+ afterOpenChange ?: ( open : boolean ) => void ;
11
12
onClose ?: ( e : SyntheticEvent ) => any ;
12
13
closable ?: boolean ;
13
14
maskClosable ?: boolean ;
Original file line number Diff line number Diff line change @@ -504,4 +504,18 @@ describe('dialog', () => {
504
504
expect ( afterClose ) . toHaveBeenCalledTimes ( 0 ) ;
505
505
} ) ;
506
506
} ) ;
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
+ } ) ;
507
521
} ) ;
You can’t perform that action at this time.
0 commit comments