unstable_Dialog API
- Component status:
-
unstable
Import
Section titled “Import”import { unstable_Dialog as Dialog } from "@stratakit/structures";// ORimport * as Dialog from "@stratakit/structures/unstable_Dialog";Dialog.Root
Section titled “Dialog.Root”A modal dialog component used to display content in a window overlay. Must include Dialog.Header and Dialog.Content as direct
descendants. Additionally, Dialog.Footer can be optionally used as a direct descendant.
Example:
const [open, setOpen] = useState(false);
<Dialog.Root modal={true} open={open} onClose={() => setOpen(false)}> <Dialog.Heading>Heading</Dialog.Heading> <Dialog.Content>Content</Dialog.Content> <Dialog.Footer> <Dialog.ActionList actions={[ <Button key="ok" onClick={() => setOpen(false)}>Ok</Button>, ]} />
</Dialog.Footer></Dialog.Root>true (required) Determines whether the dialog is modal. Currently, only modal dialogs are supported.
backdrop
Section titled “backdrop”boolean | ReactElement<DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, string | JSXElementConstructor<any>> | ElementType<...> | undefined (optional) Determines whether there will be a backdrop behind the dialog. On modal
dialogs, this is true by default. Besides a boolean, this prop can also
be a React component or JSX element that will be rendered as the backdrop.
Note: If a custom component is used, it must accept ref and spread all props to its underlying DOM element, the same way a native element would.
hideOnInteractOutside
Section titled “hideOnInteractOutside”BooleanOrCallback<Event | SyntheticEvent<Element, Event>> | undefined (optional) true Determines if the dialog should hide when the user clicks or focuses on an element outside the dialog.
This prop can be either a boolean or a function that takes an event as an argument and returns a boolean. The event object represents the event that triggered the action, which could be a native event or a React synthetic event of various types.
onClose
Section titled “onClose”((event: Event) => void) | undefined (optional) This is an event handler prop triggered when the dialog’s close event is
dispatched. The close event is similar to the native dialog
close
event. The only difference is that this event can be canceled with
event.preventDefault(), which will prevent the dialog from hiding.
It’s important to note that this event only fires when the dialog store’s
open state is set
to false. If the controlled
open prop value changes, or
if the dialog’s visibility is altered in any other way (such as unmounting
the dialog without adjusting the open state), this event won’t be
triggered.
boolean | undefined (optional) Controls the open state of the dialog. This is similar to the
open
attribute on native dialog elements.
unmountOnHide
Section titled “unmountOnHide”boolean | undefined (optional) true When set to true, the content element will be unmounted and removed from
the DOM when it’s hidden.
Additional props
Section titled “Additional props”Dialog.Header
Section titled “Dialog.Header”The header of a dialog. Should be used as a child of Dialog.Root. Must include Dialog.Heading as a direct
descendant. Additionally, Dialog.CloseButton can be optionally used as a direct descendant.
Example:
<Dialog.Header> <Dialog.Heading>Heading</Dialog.Heading> <Dialog.CloseButton /></Dialog.Header>Use render prop when only a heading is displayed in a header.
<Dialog.Header render={<Dialog.Heading />}>Heading</Dialog.Header>Additional props
Section titled “Additional props”Dialog.Heading
Section titled “Dialog.Heading”The heading of a dialog. Should be used as a child of Dialog.DialogHeader.
Example:
<Dialog.Heading>Heading</Dialog.Heading>Additional props
Section titled “Additional props”Dialog.CloseButton
Section titled “Dialog.CloseButton”A button that closes the dialog. Displayed as an icon button in the top-right corner of the dialog.
Should be used as a child of Dialog.DialogHeader.
Example:
<Dialog.CloseButton />string | undefined (optional) "Dismiss" Label for the close button.
Additional props
Section titled “Additional props”Dialog.Content
Section titled “Dialog.Content”The content of a dialog. Should be used as a child of Dialog.Root.
Example:
<Dialog.Content>Content</Dialog.Content>Additional props
Section titled “Additional props”Dialog.Footer
Section titled “Dialog.Footer”The footer section of a dialog, typically used to display action buttons at the bottom of the dialog.
Should be used as a child of Dialog.Root. Use Dialog.ActionList as a direct descendant to display a list of actions.
Example:
<Dialog.Footer> <Dialog.ActionList actions={[ <Button key="cancel" onClick={() => setOpen(false)}>Cancel</Button>, <Button key="ok" tone="accent" onClick={() => setOpen(false)}>Ok</Button>, ]} /></Dialog.Footer>Additional props
Section titled “Additional props”Dialog.ActionList
Section titled “Dialog.ActionList”A container for action buttons in a dialog. Should be used as a child of Dialog.Footer.
Example:
<Dialog.ActionList actions={[ <Button key="cancel" onClick={() => setOpen(false)}>Cancel</Button>, <Button key="ok" tone="accent" onClick={() => setOpen(false)}>Ok</Button>, ]}/>actions
Section titled “actions”ReactNode[] | undefined (optional) The actions available for the dialog. Must be a list of Button components.
Additional props
Section titled “Additional props”Dialog.Backdrop
Section titled “Dialog.Backdrop”The backdrop of a dialog. Should be passed into the backdrop prop of Dialog.Root.
Example:
<Dialog.Root modal={true} backdrop={<Dialog.Backdrop />} />