Skip to main content

Modal

A dialog overlay that interrupts the user to present critical information or request a decision.

Source: Re-exported from antd. Full documentation: Ant Design Modal

When to Use

  • Require user confirmation before a destructive action.
  • Display supplementary content without leaving the current page.
  • Collect a small amount of user input.

Basic Usage

import { Modal, Button } from '@vef-framework-react/components';
import { useState } from 'react';

export default function Demo() {
const [open, setOpen] = useState(false);

return (
<>
<Button type="primary" onClick={() => setOpen(true)}>
Open Modal
</Button>
<Modal
title="Basic Modal"
open={open}
onOk={() => setOpen(false)}
onCancel={() => setOpen(false)}
>
<p>Modal content goes here.</p>
</Modal>
</>
);
}

Async OK Handler

import { Modal, Button } from '@vef-framework-react/components';
import { useState } from 'react';

export default function Demo() {
const [open, setOpen] = useState(false);
const [loading, setLoading] = useState(false);

const handleOk = async () => {
setLoading(true);
await saveData();
setLoading(false);
setOpen(false);
};

return (
<>
<Button onClick={() => setOpen(true)}>Open</Button>
<Modal
title="Save Changes"
open={open}
onOk={handleOk}
confirmLoading={loading}
onCancel={() => setOpen(false)}
>
<p>Are you sure you want to save?</p>
</Modal>
</>
);
}

Confirmation Dialog

For simple confirmations, use the static Modal.confirm method:

import { Modal } from '@vef-framework-react/components';

function handleDelete(id: number) {
Modal.confirm({
title: 'Delete Record',
content: 'This action cannot be undone. Continue?',
okText: 'Delete',
okType: 'danger',
onOk: () => deleteRecord(id),
});
}

For inline confirm buttons, consider using ActionButton with confirmable instead.

<Modal
title="Custom Footer"
open={open}
footer={[
<Button key="back" onClick={() => setOpen(false)}>Return</Button>,
<Button key="submit" type="primary" onClick={handleOk}>Submit</Button>,
]}
>
<p>Content</p>
</Modal>
<Modal title="Info" open={open} footer={null} onCancel={() => setOpen(false)}>
<p>Read-only content.</p>
</Modal>

API

PropTypeDefaultDescription
openbooleanfalseWhether the modal is visible
titleReactNodeModal title
childrenReactNodeModal body content
footerReactNode | nullCustom footer; null hides footer
onOk(e) => voidOK button click handler
onCancel(e) => voidCancel / close handler
okTextReactNode'OK'OK button label
cancelTextReactNode'Cancel'Cancel button label
okTypeButtonType'primary'OK button type
confirmLoadingbooleanfalseShow loading on OK button
widthnumber | string520Modal width
centeredbooleanfalseVertically center the modal
closablebooleantrueShow close icon
maskClosablebooleantrueClose on mask click
destroyOnClosebooleanfalseUnmount children on close
forceRenderbooleanfalsePre-render content
keyboardbooleantrueClose on Escape key
zIndexnumber1000z-index
afterClose() => voidCallback after close animation
afterOpenChange(open) => voidCallback after open state changes

Best Practices

  • Set destroyOnClose when the modal contains a form to reset state on close.
  • Avoid deeply nested modals; use Drawer for secondary panels.
  • Use Modal.confirm for simple yes/no confirmations; use ActionButton with confirmable for inline table actions.