Modal
Use the Modal component for focused overlays that require the user to review content or complete a task without leaving the current screen.
Import Modal
Import Modal from Tavix:
import { Modal } from "tavix";Component API
<Modal
open={false}
onClose
children
size="md"
position="center"
closeOnOverlay={true}
closeOnEscape={true}
showClose={true}
/>Props
open: Controls whether the modal is visible.onClose: Callback fired when the modal closes.children: Content rendered inside the modal body.size: Modal size variant. Defaults tomd.position: Modal alignment. Defaults tocenter.closeOnOverlay: Closes the modal when the backdrop is clicked.closeOnEscape: Closes the modal when the Escape key is pressed.showClose: Shows the close button in the upper-right corner.
Behavior
- Renders only when
openistrue. - Adds a fullscreen overlay behind the modal.
- Prevents background scrolling while the modal is open.
- Calls
onClosewhen the backdrop is clicked andcloseOnOverlayis enabled. - Calls
onClosewhen the Escape key is pressed andcloseOnEscapeis enabled. - Uses
role="dialog"andaria-modal="true"for accessibility. - Stops propagation to avoid closing the modal when interacting with the content area.
Examples
Basic modal
const [open, setOpen] = useState(false);
<>
<button type="button" onClick={() => setOpen(true)}>Open modal</button>
<Modal open={open} onClose={() => setOpen(false)}>
<div>
<h2>Profile</h2>
<p>Update your details and save changes.</p>
</div>
</Modal>
</>Modal with custom size
<Modal open={open} onClose={handleClose} size="lg" position="center">
<div>
<h2>Subscription settings</h2>
<p>Choose your plan and billing preferences.</p>
</div>
</Modal>Notes
- Use
Modalfor general-purpose overlays and content windows. - For action-confirmation flows, consider
DialogorAlertDialoginstead of a generic modal.