Components / Core
Dialog
Modal built on the native <dialog>: focus trapping, Esc to close and the backdrop come from the browser.
import { Dialog } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { Button, Dialog } from "@stylhero/ui";
function DialogExample() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Delete build</Button>
<Dialog open={open} onClose={() => setOpen(false)} title="Delete this build?"
footer={<><Button variant="secondary" onClick={() => setOpen(false)}>Cancel</Button><Button variant="danger" onClick={() => setOpen(false)}>Delete</Button></>}>
It's removed from your account. This can't be undone.
</Dialog>
</>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
onClose required |
() => void |
- | |
open required |
boolean |
- | |
title required |
ReactNode |
- | |
children |
ReactNode |
- | |
footer |
ReactNode |
- | Buttons, right-aligned. Put the main action last. |
Also takes every <dialog> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.
Keyboard
| Key | Does |
|---|---|
| Tab | Stays inside the dialog |
| Esc | Closes it (calls onClose) |
Accessibility
- Built on the native
<dialog>opened withshowModal(): the browser traps focus, makes the page behind it inert and returns focus to the opener on close. - Labelled by its
title.
Generated from src/components/Dialog.tsx. Something wrong or missing? Open an issue.