Dialog
Dialogs are windows containing contextual information, tasks, or workflows that appear over the user interface. Depending on the kind of Dialog, further interactions may be blocked until the Dialog is acknowledged.
Content
Dialogs are windows containing contextual information, tasks, or workflows that appear over the user interface. Spectrum includes several pre-defined dialog components with layouts for specific use cases, or you can use CustomDialog
to create a custom layout.
Standard Dialog
Use Dialog
for standard dialog layouts. It supports Image
, Heading
, Header
, Content
, Footer
, and ButtonGroup
slots. Dismissible dialogs replace their ButtonGroup
with a close button.
Alert Dialog
Use AlertDialog
for confirmation, error messages, and other critical information that must be acknowledged.
variant
autoFocusButton
Fullscreen Dialog
Use FullscreenDialog
for complex workflows that require more space. It supports Heading
, Header
, Content
, and ButtonGroup
slots.
variant
Custom Dialog
Use CustomDialog
for complete control over the dialog layout.
size
Dialog Container
Use DialogContainer
to show a dialog programmatically or mount in a different part of the JSX tree (e.g. outside a menu).
import {DialogContainer, Dialog, Button, ButtonGroup, Heading, Content, ActionMenu, MenuItem} from '@react-spectrum/s2';
import {useState} from 'react';
function DialogContainerExample() {
let [dialogType, setDialogType] = useState(null);
return (
<>
<ActionMenu onAction={setDialogType}>
<MenuItem id="edit">Edit Item</MenuItem>
<MenuItem id="delete">Delete Item</MenuItem>
<MenuItem id="share">Share Item</MenuItem>
</ActionMenu>
<DialogContainer onDismiss={() => setDialogType(null)}>
{dialogType === 'edit' && (
<Dialog>
{({close}) => (
<>
<Heading slot="title">Edit Item</Heading>
<Content>Make changes to your item here.</Content>
<ButtonGroup>
<Button onPress={close} variant="secondary">Cancel</Button>
<Button onPress={close} variant="accent">Save</Button>
</ButtonGroup>
</>
)}
</Dialog>
)}
{dialogType === 'delete' && (
<Dialog>
{({close}) => (
<>
<Heading slot="title">Delete Item</Heading>
<Content>Are you sure you want to delete this item? This action cannot be undone.</Content>
<ButtonGroup>
<Button onPress={close} variant="secondary">Cancel</Button>
<Button onPress={close} variant="negative">Delete</Button>
</ButtonGroup>
</>
)}
</Dialog>
)}
{dialogType === 'share' && (
<Dialog>
{({close}) => (
<>
<Heading slot="title">Share Item</Heading>
<Content>Choose how you would like to share this item.</Content>
<ButtonGroup>
<Button onPress={close} variant="secondary">Cancel</Button>
<Button onPress={close} variant="accent">Share</Button>
</ButtonGroup>
</>
)}
</Dialog>
)}
</DialogContainer>
</>
);
}
API
Dialog
<Dialog>
<Image slot="hero">
<Heading slot="title" />
<Header />
<Content />
<Footer />
<ButtonGroup />
</Dialog>
Name | Type | Default |
---|---|---|
isDismissible | boolean | Default: — |
Whether the Dialog is dismissible. | ||
size | 'S'
| 'M'
| 'L' | Default: 'M'
|
The size of the Dialog. | ||
isKeyboardDismissDisabled | boolean | Default: — |
Whether pressing the escape key to close the dialog should be disabled. | ||
children | ReactNode | | Default: — |
Children of the dialog. A function may be provided to access a function to close the dialog. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
AlertDialog
Name | Type | Default |
---|---|---|
variant | 'confirmation'
| 'information'
| 'destructive'
| 'error'
| 'warning' | Default: — |
The visual style of the AlertDialog. | ||
title | string | Default: — |
The title of the AlertDialog. | ||
children | ReactNode | Default: — |
The contents of the AlertDialog. | ||
cancelLabel | string | Default: — |
The label to display within the cancel button. | ||
primaryActionLabel | string | Default: — |
The label to display within the confirm button. | ||
secondaryActionLabel | string | Default: — |
The label to display within the secondary button. | ||
isPrimaryActionDisabled | boolean | Default: — |
Whether the primary button is disabled. | ||
isSecondaryActionDisabled | boolean | Default: — |
Whether the secondary button is disabled. | ||
autoFocusButton | 'cancel'
| 'primary'
| 'secondary' | Default: — |
Button to focus by default when the dialog opens. | ||
size | 'S'
| 'M'
| 'L' | Default: 'M'
|
The size of the Dialog. | ||
FullscreenDialog
<FullscreenDialog>
<Heading slot="title" />
<Header />
<Content />
<ButtonGroup />
</FullscreenDialog>
Name | Type | Default |
---|---|---|
variant | 'fullscreen' | 'fullscreenTakeover' | Default: "fullscreen"
|
The variant of fullscreen dialog to display. | ||
isKeyboardDismissDisabled | boolean | Default: — |
Whether pressing the escape key to close the dialog should be disabled. | ||
children | ReactNode | | Default: — |
Children of the dialog. A function may be provided to access a function to close the dialog. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
CustomDialog
Name | Type | Default |
---|---|---|
size | 'S'
| 'M'
| 'L'
| 'fullscreen'
| 'fullscreenTakeover' | Default: — |
The size of the Dialog. | ||
isDismissible | boolean | Default: — |
Whether the Dialog is dismissible. | ||
isKeyboardDismissDisabled | boolean | Default: — |
Whether pressing the escape key to close the dialog should be disabled. | ||
padding | 'default' | 'none' | Default: 'default'
|
The amount of padding around the contents of the dialog. | ||
children | ReactNode | | Default: — |
Children of the dialog. A function may be provided to access a function to close the dialog. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the style() macro. | ||
DialogTrigger
<DialogTrigger>
<Button />
<Dialog />
</DialogTrigger>
Name | Type | |
---|---|---|
children | ReactNode | |
DialogContainer
<DialogContainer>
<Dialog />
</DialogContainer>
Name | Type | |
---|---|---|
children | ReactNode | |
The Dialog to display, if any. | ||