Components / Overlays
Backdrop
Dims the whole screen, e.g. while saving. Built on native <dialog>, so it blocks clicks and traps focus.
import { Backdrop } from "@stylhero/ui";
Example
Code
import { useState } from "react";
import { Backdrop, Button, Spinner } from "@stylhero/ui";
function BackdropExample() {
const [saving, setSaving] = useState(false);
const save = () => { setSaving(true); setTimeout(() => setSaving(false), 1500); };
return (
<>
<Button onClick={save}>Save (1.5 s)</Button>
<Backdrop open={saving} label="Saving"><Spinner size="lg" label="Saving" /></Backdrop>
</>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
open required |
boolean |
- | |
children |
ReactNode |
- | Usually a Spinner, or your own panel. |
label |
string |
- | Accessible name, e.g. "Saving". |
onClose |
() => void |
- | Clicking the dimmed area (or Esc) calls this. Leave it out for a blocking "please wait". |
Also takes every <dialog> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.
Keyboard
| Key | Does |
|---|---|
| Esc | Calls onClose if you pass one |
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. - Without
onCloseit setsaria-busy; give it alabelsuch as "Saving".
Generated from src/components/Backdrop.tsx. Something wrong or missing? Open an issue.