Skip to content

Commit 7c9fa59

Browse files
committed
feat(Dialog): add useDialogContainer hook
1 parent 4051fe9 commit 7c9fa59

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/components/overlays/Dialog/DialogForm.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ export function DialogForm<T extends FieldTypes = FieldTypes>(
8585
onDismiss?.();
8686

8787
if (!preserve) {
88-
form?.resetFields();
88+
// let animations finish before resetting the form
89+
setTimeout(() => {
90+
form?.resetFields();
91+
}, 250);
8992
}
9093
}
9194

src/components/overlays/Dialog/dialog-container.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
import React, { useState, useMemo } from 'react';
1+
import React, { useState, useMemo, ReactElement } from 'react';
22

33
import { useEvent } from '../../../_internal/index';
44

55
import { DialogContainer } from './DialogContainer';
66

7+
// Overload for dialogs that expect no props
8+
export function useDialogContainer(Component: React.ComponentType<{}>): {
9+
open: () => void;
10+
close: () => void;
11+
rendered: ReactElement | null;
12+
};
13+
14+
// Overload for dialogs that require props
15+
export function useDialogContainer<P>(Component: React.ComponentType<P>): {
16+
open: (props: P) => void;
17+
close: () => void;
18+
rendered: ReactElement | null;
19+
};
20+
721
/**
822
* Generic hook to manage a dialog component.
923
*
@@ -16,7 +30,7 @@ export function useDialogContainer<P>(Component: React.ComponentType<P>) {
1630

1731
// 'open' accepts props required by the Component and opens the dialog
1832
const open = useEvent((props: P) => {
19-
setComponentProps(props);
33+
setComponentProps(props === undefined ? ({} as P) : props);
2034
setIsOpen(true);
2135
});
2236

0 commit comments

Comments
 (0)