Skip to content

Commit cb40762

Browse files
authored
Merge 3bd603f into fd1e6f1
2 parents fd1e6f1 + 3bd603f commit cb40762

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

src/Dialog/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import * as React from 'react';
2-
import { useRef, useEffect } from 'react';
31
import classNames from 'classnames';
4-
import KeyCode from 'rc-util/lib/KeyCode';
5-
import useId from 'rc-util/lib/hooks/useId';
62
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';
75
import pickAttrs from 'rc-util/lib/pickAttrs';
6+
import * as React from 'react';
7+
import { useEffect, useRef } from 'react';
88
import type { IDialogPropTypes } from '../IDialogPropTypes';
9-
import Mask from './Mask';
109
import { getMotionName } from '../util';
1110
import Content from './Content';
1211
import type { ContentRef } from './Content/Panel';
12+
import Mask from './Mask';
1313

1414
export 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) {

src/IDialogPropTypes.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { ReactNode, CSSProperties, SyntheticEvent } from 'react';
21
import type { GetContainer } from 'rc-util/lib/PortalWrapper';
2+
import type { CSSProperties, ReactNode, SyntheticEvent } from 'react';
33

44
export 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;

tests/index.spec.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable react/no-render-return-value, max-classes-per-file, func-names, no-console */
2-
import React, { cloneElement, useEffect } from 'react';
3-
import { act } from 'react-dom/test-utils';
42
import { render } from '@testing-library/react';
53
import type { ReactWrapper } from 'enzyme';
64
import { mount } from 'enzyme';
75
import KeyCode from 'rc-util/lib/KeyCode';
6+
import React, { cloneElement, useEffect } from 'react';
7+
import { act } from 'react-dom/test-utils';
88
import type { DialogProps } from '../src';
99
import Dialog from '../src';
1010

@@ -505,4 +505,18 @@ describe('dialog', () => {
505505
expect(afterClose).toHaveBeenCalledTimes(0);
506506
});
507507
});
508+
509+
describe('afterOpenChange', () => {
510+
it('should trigger afterOpenChange when visible changed', () => {
511+
const afterOpenChange = jest.fn();
512+
513+
const wrapper = mount(<Dialog afterOpenChange={afterOpenChange} visible />);
514+
jest.runAllTimers();
515+
516+
wrapper.setProps({ visible: false });
517+
jest.runAllTimers();
518+
519+
expect(afterOpenChange).toHaveBeenCalledTimes(2);
520+
});
521+
});
508522
});

0 commit comments

Comments
 (0)