Skip to content

Dialog

The Dialog component displays content in a modal overlay, capturing user attention. It provides a flexible way to create modal dialogs with backdrop, positioning, and focus management.

import { useRef } from 'react';
import {
Button,
Dialog,
useDisclosure,
} from '@fintech-sandpit/ui/react';
const {
open,
onOpen,
onClose,
} = useDisclosure();
const initialFocusEl = useRef<HTMLButtonElement>(null);
return (
<Dialog.Root
open={open}
initialFocusEl={() => initialFocusEl.current}
onOpen={onOpen}
onClose={onClose}
>
<Button
colorScheme="primary"
onClick={onOpen}
>
Open Dialog
</Button>
<Dialog.Content>
<Dialog.Title>
Hey!
</Dialog.Title>
<Dialog.Description>
I'm a dialog!
</Dialog.Description>
<Dialog.Footer>
<Button
ref={initialFocusEl}
onClick={onClose}
>
Close me
</Button>
</Dialog.Footer>
<Dialog.CloseTrigger />
</Dialog.Content>
</Dialog.Root>
);
NameTypeDefaultDescription
openbooleanfalseWhether the dialog is open
defaultOpenbooleanfalseWhether the dialog is open by default
modalbooleantrueWhether the dialog is modal
closeOnInteractOutsidebooleantrueWhether to close on outside interaction
closeOnEscapebooleantrueWhether to close on Escape key
initialFocusEl() => HTMLElement | nullFunction that returns the element to focus initially
finalFocusEl() => HTMLElement | nullFunction that returns the element to focus finally
trapFocusbooleantrueWhether to trap focus inside the dialog
preventScrollbooleanfalseWhether to prevent scroll when the dialog is opened
restoreFocusbooleantrueWhether to restore focus when the dialog is closed
lazyMountbooleantrueWhether to lazy mount the dialog content
unmountOnExitbooleantrueWhether to unmount the dialog content when it is closed
role'dialog' | 'alertdialog''dialog'The role of the dialog
NameArgumentsDescription
onOpen() => voidCallback fired when dialog is opened
onClose() => voidCallback fired when dialog is closed