Skip to Content
🎉 Coral x Panda has been released 🎉 Read the Migration Guide
DocumentationAtomsDialog

Dialog

This component is an overlay that requires the users to interact

Basic Usage

import { Dialog } from '@krakentech/coral/atoms'; <Button onClick={() => setOpen(true)}>Open dialog</Button> <Dialog ariaLabelledBy="dialog-title" open={open} onClose={() => setOpen(false)} > <Stack flexDirection="column" gap="smMd"> <Typography textStyle="h3" id="dialog-title"> Dialog title </Typography> <Typography> Dialog content Cupidatat duis officia laborum pariatur officia pariatur cupidatat proident id qui anim. Tempor dolore in non mollit incididunt quis eu. Dolor nulla cupidatat ea nisi commodo ut fugiat velit commodo est. Amet officia tempor magna eu reprehenderit dolore est laboris in ipsum ipsum nisi enim. </Typography> <Stack gap="smMd"> <Button variant="outlined" onClick={() => setOpen(false)} > Close </Button> <Button onClick={() => setOpen(false)}>Action</Button> </Stack> </Stack> </Dialog>

Dialog title

Dialog content Cupidatat duis officia laborum pariatur officia pariatur cupidatat proident id qui anim. Tempor dolore in non mollit incididunt quis eu. Dolor nulla cupidatat ea nisi commodo ut fugiat velit commodo est. Amet officia tempor magna eu reprehenderit dolore est laboris in ipsum ipsum nisi enim.

Properties

disableEscapeKeyDown

const [open, setOpen] = useState(false); <Button onClick={setOpen(true)}>Open dialog</Button> <Dialog ariaLabelledBy="title" onClose={() => setOpen(false)} open={open} disableEscapeKeyDown > <Typography id="title">Dialog title ...</Typography> </Dialog>

Dialog title

Dialog content Cupidatat duis officia laborum pariatur officia pariatur cupidatat proident id qui anim. Tempor dolore in non mollit incididunt quis eu. Dolor nulla cupidatat ea nisi commodo ut fugiat velit commodo est. Amet officia tempor magna eu reprehenderit dolore est laboris in ipsum ipsum nisi enim.

dialogWidth

const [open, setOpen] = useState(false); <Button onClick={setOpen(true)}>Open dialog</Button> <Dialog ariaLabelledBy="title" onClose={() => setOpen(false)} open={open} dialogWidth="md" > <Typography id="title">Dialog title ...</Typography> </Dialog>

Dialog title

Dialog content Cupidatat duis officia laborum pariatur officia pariatur cupidatat proident id qui anim. Tempor dolore in non mollit incididunt quis eu. Dolor nulla cupidatat ea nisi commodo ut fugiat velit commodo est. Amet officia tempor magna eu reprehenderit dolore est laboris in ipsum ipsum nisi enim.

Event Handlers

<Dialog ariaLabelledBy="title" onClose={() => {}} > ... </Dialog>

Responsiveness

const [open, setOpen] = useState(false); <Button onClick={setOpen(true)}>Open dialog</Button> <Dialog ariaLabelledBy="title" onClose={() => setOpen(false)} open={open} dialogWidth={{ base: "xs", lg: "md" }} > <Typography id="title">Dialog title ...</Typography> </Dialog>

Dialog title

Dialog content Cupidatat duis officia laborum pariatur officia pariatur cupidatat proident id qui anim. Tempor dolore in non mollit incididunt quis eu. Dolor nulla cupidatat ea nisi commodo ut fugiat velit commodo est. Amet officia tempor magna eu reprehenderit dolore est laboris in ipsum ipsum nisi enim.

Full API

NameTypeDefault
ariaLabelledBystring

The id of the element that describes the Dialog. This should be an id of a child element.

disableEscapeKeyDownboolean

If true, the Dialog will not close when the user clicks outside of it.

false
dialogWidthResponsiveVariant<"xs" | "sm" | "md" | "lg" | "xl" | "full">

If set, the Dialog will be rendered with a max-width of this value.

sm
onCloseDialogCloseCallback

A callback fired when the Dialog is closed.

  • event The event source of the callback.
  • reason The reason the Dialog was closed.
    • ‘backdropClick’ - The user clicked the backdrop.
    • ‘escapeKeyDown’ - The user pressed the escape key.
    • ‘closeButtonClick’ - The user clicked the close button.
openboolean

If true, the Dialog will be open by default.

false
refRefObject<HTMLDivElement>

A ref passed to the Dialog content element.

closedby"any" | "closerequest" | "none" | undefined

The closedby attribute is used to indicate what caused the dialog to close.

  • ‘any’ indicates that the dialog can be closed by any method (backdrop click, escape key, close button).
  • ‘closerequest’ indicates that the dialog can only be closed by calling the close() method on the dialog element, and not by user interactions.
  • ‘none’ indicates that the dialog cannot be closed by any method, including programmatically.

Note: Safari does not support the closedby attribute, so it will always behave as if closedby is set to ‘closerequest’. This means in Safari will open close by hittine the close button, or the escape key on the keyboard, but not by clicking outside of the dialog.

any
childrenReactNode

Design

Good to know

Only use a dialog modal when absolutely necessary.

A modal interrupts a users journey in order to grab their attention. It sits on top of a main window, disabling the main window until interacted with, while still keeping it partly visible.

Last updated on