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 / 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

PropTypeDefaultDescription
onClose required () => void -
open required boolean -
title required ReactNode -
children ReactNode -

Also takes every <dialog> attribute (id, style, data-*, aria-*, event handlers…), passed to that element.

Keyboard

KeyDoes
TabStays inside the dialog
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.
  • Labelled by its title.

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