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

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

PropTypeDefaultDescription
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

KeyDoes
TabStays inside it
EscCloses it (calls onClose)

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.
  • There's no title, so give it a label.

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