Components / Overlays
Modal
Bare modal layer for custom panels (MUI's Modal). Esc and backdrop click call onClose.
import { Modal } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { Button, Modal, Paper, Stack, Text } from "@stylhero/ui";
function ModalExample() {
const [open, setOpen] = useState(false);
return (
<>
<Button onClick={() => setOpen(true)}>Open a custom panel</Button>
<Modal open={open} onClose={() => setOpen(false)} label="Custom panel">
<Paper padding={6} style={{ maxWidth: 360 }}>
<Stack gap={3}><Text variant="h3">Your own layout</Text><Button onClick={() => setOpen(false)}>Close</Button></Stack>
</Paper>
</Modal>
</>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children required |
ReactNode |
- | Your own content: Modal adds no header, padding or close button (use Dialog for that). |
onClose required |
() => void |
- | |
open required |
boolean |
- | |
label |
string |
- |
Also takes every <dialog> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.
Keyboard
| Key | Does |
|---|---|
| Tab | Stays inside it |
| 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. - There's no title, so give it a
label.
Generated from src/components/Backdrop.tsx. Something wrong or missing? Open an issue.