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.
size
isDismissible
isKeyboardDismissDisabled
import {Dialog, DialogTrigger, Button, ButtonGroup, Heading, Content, Footer, Checkbox, Image, Form, TextField} from'@react-spectrum/s2';
importheroImagefrom'url:./assets/preview.png';
function Example(props) {
return (
<DialogTrigger>
<Buttonvariant="primary">Open Dialog</Button>
<Dialog {...props}>
{({close}) => (
<>
<Imageslot="hero"src={heroImage} />
<Headingslot="title">Subscribe to our newsletter</Heading>
<Content>
<p>Enter your information to subscribe to our newsletter and receive updates about new features and announcements.</p>
<Form>
<TextFieldlabel="Name" />
<TextFieldlabel="Email"type="email" />
</Form>
</Content>
<Footer>
<Checkbox>Don't show this again</Checkbox>
</Footer>
<ButtonGroup>
<ButtononPress={close} variant="secondary">Cancel</Button>
<ButtononPress={close} variant="accent">Subscribe</Button>
</ButtonGroup>
</>
)}
</Dialog>
</DialogTrigger>
);
}
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.
size
isDismissible
import {Dialog, DialogTrigger, Button, ButtonGroup, Heading, Header, Content, Footer, Checkbox, Image, Form, TextField} from'@react-spectrum/s2';
importheroImagefrom'url:./assets/preview.png';
function Example(props) {
return (
<DialogTrigger>
<Buttonvariant="primary">Open Dialog</Button>
<Dialog {...props}>
{({close}) => (
<>
<Imageslot="hero"src={heroImage} />
<Headingslot="title">Dialog Title</Heading>
<Header>Header</Header>
<Content>
<p>Standard dialog description. This should briefly communicate any additional information or context about the standard dialog title, to help users make one of the decisions offered by the buttons. Make it no more than a few short sentences.</p>
</Content>
<Footer>
<Checkbox>Don't show this again</Checkbox>
</Footer>
<ButtonGroup>
<ButtononPress={close} variant="secondary">Cancel</Button>
<ButtononPress={close} variant="accent">Subscribe</Button>
</ButtonGroup>
</>
)}
</Dialog>
</DialogTrigger>
);
}
Alert Dialog
Use AlertDialog for confirmation, error messages, and other critical information that must be acknowledged.