Skip to content
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ReactDOM.render(
| maskTransitionName | String | | mask animation css class name | |
| title | String\|React.Element | | Title of the dialog | |
| footer | React.Element | | footer of the dialog | |
| closable | Boolean \| ({ closeIcon?: React.ReactNode; disabled?: boolean } & React.AriaAttributes | true | whether show close button | |
| closable | Boolean \| ({ closeIcon?: React.ReactNode; disabled?: boolean, afterClose:function } & React.AriaAttributes) | true | whether show close button | |
| mask | Boolean | true | whether show mask | |
| maskClosable | Boolean | true | whether click mask to close | |
| keyboard | Boolean | true | whether support press esc to close | |
Expand Down
4 changes: 4 additions & 0 deletions src/DialogWrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props) => {
forceRender,
destroyOnHidden = false,
afterClose,
closable,
panelRef,
} = props;
const [animatedVisible, setAnimatedVisible] = React.useState<boolean>(visible);
Expand Down Expand Up @@ -49,6 +50,9 @@ const DialogWrap: React.FC<IDialogPropTypes> = (props) => {
{...props}
destroyOnHidden={destroyOnHidden}
afterClose={() => {
const { afterClose: closableAfterClose = undefined } =
typeof closable === 'object' && closable !== null ? closable : {};
closableAfterClose?.();
afterClose?.();
setAnimatedVisible(false);
}}
Expand Down
8 changes: 7 additions & 1 deletion src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export type ModalClassNames = Partial<Record<SemanticName, string>>;

export type ModalStyles = Partial<Record<SemanticName, CSSProperties>>;

export type ClosableType = {
closeIcon?: React.ReactNode;
disabled?: boolean;
afterClose?: () => any;
};

export type IDialogPropTypes = {
className?: string;
keyboard?: boolean;
Expand All @@ -17,7 +23,7 @@ export type IDialogPropTypes = {
afterClose?: () => any;
afterOpenChange?: (open: boolean) => void;
onClose?: (e: SyntheticEvent) => any;
closable?: boolean | ({ closeIcon?: React.ReactNode; disabled?: boolean } & React.AriaAttributes);
closable?: boolean | (ClosableType & React.AriaAttributes);
maskClosable?: boolean;
visible?: boolean;
destroyOnHidden?: boolean;
Expand Down
19 changes: 19 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,25 @@ describe('dialog', () => {

expect(afterClose).toHaveBeenCalledTimes(0);
});

it('should prioritize closable.afterClose when both exist', () => {
const afterClose = jest.fn();
const legacyAfterClose = jest.fn();

const { rerender } = render(
<Dialog closable={{ afterClose }} afterClose={legacyAfterClose} visible />,
);
act(() => {
jest.runAllTimers();
});

rerender(<Dialog closable={{ afterClose }} afterClose={legacyAfterClose} visible={false} />);
act(() => {
jest.runAllTimers();
});
expect(afterClose).toHaveBeenCalledTimes(1);
expect(legacyAfterClose).toHaveBeenCalledTimes(1);
});
});

describe('afterOpenChange', () => {
Expand Down
Loading