Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

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

PropTypeDefaultDescription
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

KeyDoes
EscCalls onClose if you pass one

Accessibility

  • Built on the native <dialog> opened with showModal(): the browser traps focus, makes the page behind it inert and returns focus to the opener on close.
  • Without onClose it sets aria-busy; give it a label such as "Saving".

Generated from src/components/Backdrop.tsx. Something wrong or missing? Open an issue.