Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"rc-util": "^5.6.1"
},
"devDependencies": {
"@types/classnames": "^2.2.11",
"@types/enzyme": "^3.10.7",
"@types/jest": "^26.0.14",
"@types/react": "^16.9.2",
Expand Down
2 changes: 2 additions & 0 deletions src/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function Dialog(props: IDialogChildProps) {
wrapClassName,
wrapProps,
onClose,
afterOpen,
afterClose,

// Dialog
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function Dialog(props: IDialogChildProps) {
lastOutSideActiveElementRef.current = document.activeElement as HTMLElement;
contentRef.current?.focus();
}
afterOpen?.();
} else {
// Clean up scroll bar & focus back
setAnimatedVisible(false);
Expand Down
3 changes: 2 additions & 1 deletion src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type IDialogPropTypes = {
mask?: boolean;
children?: any;
afterClose?: () => any;
afterOpen?: () => any;
onClose?: (e: SyntheticEvent) => any;
closable?: boolean;
maskClosable?: boolean;
Expand Down Expand Up @@ -41,4 +42,4 @@ export type IDialogPropTypes = {
// https://github.com/ant-design/ant-design/issues/19771
// https://github.com/react-component/dialog/issues/95
focusTriggerAfterClose?: boolean;
}
};
14 changes: 14 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,20 @@ describe('dialog', () => {
});
});

describe('afterOpen', () => {
it('should trigger afterOpen when set visible to true', () => {
const afterOpen = jest.fn();

const wrapper = mount(<Dialog afterOpen={afterOpen} visible={false} />);
jest.runAllTimers();

wrapper.setProps({ visible: true });
jest.runAllTimers();

expect(afterOpen).toHaveBeenCalledTimes(1);
});
});

describe('afterClose', () => {
it('should trigger afterClose when set visible to false', () => {
const afterClose = jest.fn();
Expand Down