Dialog
Modal dialog that becomes a bottom sheet on phones.
Example
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogTitle, DialogTrigger, Field, Input } from "@porcelana/ui";
export default function Example() {
return (
<Dialog>
<DialogTrigger asChild>
<Button>Edit alarm</Button>
</DialogTrigger>
<DialogContent>
<DialogTitle>Edit alarm</DialogTitle>
<DialogDescription>Changes apply to every device.</DialogDescription>
<Field label="Label">
<Input defaultValue="Morning run" />
</Field>
<DialogFooter>
<Button>Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}Import
import { DialogContent, Dialog } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.
DialogContent
Centered modal on desktop; bottom sheet under 640px. Focus is trapped and restored.
| Prop | Type | Default | Description |
|---|---|---|---|
aria-label | string | – | Defines a string value that labels the current element. @see aria-labelledby. |
asChild | boolean | – | Render the single child element instead, merging props and behaviour onto it. |
centered | boolean | – | Keep the centered modal on phones instead of the bottom sheet. |
closeLabel | string | Close | Accessible label for the close button. |
deferPointerDownOutside | boolean | – | When `true`, a `'pointerdown'` event outside of the layered element will wait for the interaction's click event before dispatching, allowing third-party code to stop propagation of later events and cancel dismissal. |
forceMount | true | – | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. |
id | string | – | Element id. Generated automatically when omitted. |
onCloseAutoFocus | ((event: Event) => void) | – | Event handler called when auto-focusing on close. Can be prevented. |
onEscapeKeyDown | ((event: KeyboardEvent) => void) | – | Event handler called when the escape key is down. Can be prevented. |
onFocusOutside | ((event: FocusOutsideEvent) => void) | – | Event handler called when the focus moves outside of the `DismissableLayer`. Can be prevented. |
onInteractOutside | ((event: PointerDownOutsideEvent | FocusOutsideEvent) => void) | – | Event handler called when an interaction happens outside the `DismissableLayer`. Specifically, when a `pointerdown` event happens outside or focus moves outside of it. Can be prevented. |
onOpenAutoFocus | ((event: Event) => void) | – | Event handler called when auto-focusing on open. Can be prevented. |
onPointerDownOutside | ((event: PointerDownOutsideEvent) => void) | – | Event handler called when the a `pointerdown` event happens outside of the `DismissableLayer`. Can be prevented. |
showClose | boolean | true | Show the × close button. Defaults to true. |
Dialog
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | – | Initial open state when uncontrolled. |
modal | boolean | – | Block interaction with the rest of the page while open. |
onOpenChange | ((open: boolean) => void) | – | Called when the open state changes. |
open | boolean | – | Controlled open state. Use with onOpenChange. |
Accessibility
- Focus is trapped inside and returns to the trigger on close; Escape closes.
- DialogTitle names it and DialogDescription describes it.
- The × button has a translatable label (closeLabel).
Mobile
- Under 640px it slides up as a bottom sheet with a grab handle, and footer buttons stack full-width.
- Pass centered to keep the modal layout.