Skip to content

Commit e50738b

Browse files
committed
new/Modal: onCloseModal prop
1 parent a61bcdf commit e50738b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/ui/modal/src/modal.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ export const ModalContext = createContext<ModalContextProps | null>(null)
2323
// Build modal
2424
const Modal = forwardRef<ModalActionsProps, ModalProps>(
2525
(
26-
{ id, size = "sm", _style, children, variant = "simple", _htmlProps },
26+
{
27+
id,
28+
size = "sm",
29+
_style,
30+
children,
31+
variant = "simple",
32+
_htmlProps,
33+
onCloseModal,
34+
},
2735
ref,
2836
) => {
2937
// generate id if not provided
@@ -56,6 +64,9 @@ const Modal = forwardRef<ModalActionsProps, ModalProps>(
5664
// Remove lock class from body on close
5765
document.body.classList.remove("sui-locked")
5866

67+
// onClose callback
68+
if (onCloseModal) onCloseModal()
69+
5970
// Update open state
6071
setIsOpen(false)
6172
}, [])

packages/ui/modal/src/modal.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type ModalProps = {
88
variant?: "simple" | "advanced" | "app-connect" // Variant type of the modal
99
size?: "sm" | "md" | "lg" | "xl" // Size of the modal (small, medium, large, extra-large)
1010
children?: React.ReactNode // Content of the modal (React children)
11+
onCloseModal?: () => void // callback function to be called upon closing the modal
1112
ref: object // Used to access the open and close modals of the modal
1213
} & SuiStyleType &
1314
SuiHTMLAttributes

packages/ui/modal/stories/tabs/TabCode.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import { Section, Row, Col, Table, List, Code, Tag, PackageInstallGuide, PropSec
4141
</List>
4242
</PropSection>
4343

44+
<PropSection title="ref" type="object" isRequired={true}>
45+
<p>A callback function to be invoked upon closing the modal, it could be used to reset the modal data for proExample=""</p>
46+
</PropSection>
47+
4448
<PropSection title="children" type="React Node">
4549
<p>Content of the modal</p>
4650
</PropSection>

0 commit comments

Comments
 (0)