Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add afterOpenChange prop #349

Merged
merged 4 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function Dialog(props: IDialogPropTypes) {
wrapClassName,
wrapProps,
onClose,
onOpenChanged,
afterClose,

// Dialog
Expand Down Expand Up @@ -86,6 +87,7 @@ export default function Dialog(props: IDialogPropTypes) {
afterClose?.();
}
}
onOpenChanged?.(newVisible)
MuxinFeng marked this conversation as resolved.
Show resolved Hide resolved
}

function onInternalClose(e: React.SyntheticEvent) {
Expand Down
3 changes: 2 additions & 1 deletion src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactNode, CSSProperties, SyntheticEvent } from 'react';
import type { GetContainer } from 'rc-util/lib/PortalWrapper';
import type { CSSProperties, ReactNode, SyntheticEvent } from 'react';

export type IDialogPropTypes = {
className?: string;
Expand All @@ -8,6 +8,7 @@ export type IDialogPropTypes = {
mask?: boolean;
children?: any;
afterClose?: () => any;
onOpenChanged?: (open: boolean) => void;
onClose?: (e: SyntheticEvent) => any;
closable?: boolean;
maskClosable?: boolean;
Expand Down
14 changes: 14 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,18 @@ describe('dialog', () => {
expect(afterClose).toHaveBeenCalledTimes(0);
});
});

describe('onOpenChanged', () => {
it('should trigger onOpenChanged when visible changed', () => {
const onOpenChanged = jest.fn();

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

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

expect(onOpenChanged).toHaveBeenCalledTimes(2);
});
});
});