For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/modal.md.
Associate the default confirm button with the form using type="submit" and a form ID to retain native validation. Update open in the form's onSubmit handler.
Use icon and description to add an icon and supporting description to the modal. Header and footer dividers are shown by default; set divided={false} to hide them.
description.tsx
import { Button, Form, FormField, Input, Modal } from '@ifhover/leaf-ui';import { Pencil } from 'lucide-react';import { useId, useState } from 'react';export function ModalDescription() { const [open, setOpen] = useState(false); const formId = useId(); return ( <> <Button onClick={() => setOpen(true)}>Rename file</Button> <Modal open={open} title="Rename file" description="The new name will appear in the file list and downloads." icon={<Pencil />} confirmText="Save" onClose={() => setOpen(false)} confirmButtonProps={{ type: 'submit', form: formId }} > <Form id={formId} layout="vertical" onSubmit={(event) => { event.preventDefault(); setOpen(false); }} > <FormField label="File name" required> <Input name="filename" defaultValue="Design notes.md" /> </FormField> </Form> </Modal> </> );}
A footer function receives the default buttons, so extra actions can retain their confirmation and cancellation behavior. Use Space to manage custom button spacing. Set footer={null} to hide the footer.
footer.tsx
import { Button, Modal, Paragraph, Space } from '@ifhover/leaf-ui';import { useState } from 'react';export function ModalFooter() { const [open, setOpen] = useState(false); const [details, setDetails] = useState(false); return ( <> <Button onClick={() => setOpen(true)}>Custom footer</Button> <Modal open={open} title="About drafts" onClose={() => setOpen(false)} footer={({ cancelButton, confirmButton }) => ( <Space size="sm" wrap> <Button variant="text" onClick={() => setDetails(!details)}> {details ? 'Hide details' : 'View details'} </Button> {cancelButton} {confirmButton} </Space> )} > <Paragraph>New documents are saved as drafts and can be edited later.</Paragraph> {details && <Paragraph>Drafts are visible only to you until you publish them.</Paragraph>} </Modal> </> );}
Content is preserved after the first opening by default. destroyOnClose unmounts it after the closing transition, so uncontrolled inputs return to their initial values when reopened. preserve takes precedence over destroyOnClose, while forceRender keeps content mounted. Controlled state held outside the dialog must still be reset by the application.
Focus moves to the first focusable control by default. Use initialFocus to choose a different target. Closing restores the previously focused element; returnFocus can specify another destination.
Return a Promise to show loading and prevent duplicate actions. Default cancellation, close-button, backdrop and Escape dismissal are blocked while it is pending. The application must still update open after onConfirm succeeds; rejection keeps the dialog open and displays the error.
Use tabs to embed line tabs beneath the heading or in place of it when untitled. The tab bar stays fixed above the scrolling body and always keeps its bottom divider even when divided={false}. Omit item children when using the tabs solely to switch state for Modal's children.
tabs.tsx
import { Button, Modal, Text } from '@ifhover/leaf-ui';import { useState } from 'react';export function ModalTabs() { const [open, setOpen] = useState(false); return ( <> <Button onClick={() => setOpen(true)}>Project settings</Button> <Modal open={open} title="Project settings" divided={false} onClose={() => setOpen(false)} tabs={{ items: [ { key: 'general', label: 'General', children: <Text>Display settings forms or details in separate tab panels.</Text>, }, { key: 'members', label: 'Permissions', children: <Text>The tab bar stays fixed while only the body scrolls.</Text>, }, ], }} /> </> );}
Embedded tabs; replace the heading when untitled or sit beneath it, retaining the tab bar bottom divider.
onClose
() => void
—
Requests closure; update open in the application
onConfirm
() => void | Promise<void>
—
Default confirm-button action, optionally returning a Promise; blocks repeated confirmation and built-in closing while pending. The application must still update open after success.
onCancel
() => void
—
Called when Cancel, the close button, the mask or Escape requests closing; falls back to onClose.
confirmText
ReactNode
Locale default
Content of the default confirm button, accepting text or a React node. null or undefined uses the current locale's common.confirm ("确定" in Simplified Chinese, "OK" in English). Applies to the default footer and confirmButton passed to a footer function; does not affect custom buttons.
cancelText
ReactNode
Locale default
Content of the default cancel button, accepting text or a React node. null or undefined uses the current locale's common.cancel ("取消" in Simplified Chinese, "Cancel" in English). Applies to the default footer and cancelButton passed to a footer function; does not affect custom buttons. Set footer={null} to hide the entire footer.
See the Tabs API (opens in a new tab) for embedded tab props. Modal fixes type="line" and placement="top", keeps the tab bar fixed above the scrollable body with its bottom divider always visible regardless of divided={false}, and restores an ordinary modal when items is empty.
type ModalTabsProps = Omit<TabsProps, 'type' | 'placement' | 'children'>;