Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Alert Dialog

A modal dialog that interrupts the user with important content and expects a response.

Installation

pnpm add @heyramzi/ui bits-ui

Usage

import * as AlertDialog from "@heyramzi/ui/shadcn/alert-dialog";
<AlertDialog.Root>
  <AlertDialog.Trigger>Delete project</AlertDialog.Trigger>
  <AlertDialog.Content>
    <AlertDialog.Header>
      <AlertDialog.Title>Are you absolutely sure?</AlertDialog.Title>
      <AlertDialog.Description>This action cannot be undone.</AlertDialog.Description>
    </AlertDialog.Header>
    <AlertDialog.Footer>
      <AlertDialog.Cancel>Cancel</AlertDialog.Cancel>
      <AlertDialog.Action>Continue</AlertDialog.Action>
    </AlertDialog.Footer>
  </AlertDialog.Content>
</AlertDialog.Root>

Keyboard and accessibility

Key Does
Tab Moves focus to the next button. Focus loops inside the dialog.
Shift Tab Moves focus to the previous button.
Esc Closes the dialog, the same as Cancel.
  • It's an alertdialog, so a screen reader reads its title and description when it opens.
  • Focus lands on the dialog itself, not on the confirm button, so Enter can't confirm by accident.
  • A click outside doesn't close it. The person has to pick an answer.

API reference

AlertDialog.Root

open bindable boolean
Default false
...rest
Every prop of AlertDialog.Root from bits-ui
Prop Type Default
open bindable boolean false
...rest Every prop of AlertDialog.Root from bits-ui

AlertDialog.Trigger

ref bindable HTMLElement | null
Default null
...rest
Every prop of AlertDialog.Trigger from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
...rest Every prop of AlertDialog.Trigger from bits-ui

AlertDialog.Content

portalProps WithoutChildrenOrChild<ComponentProps<typeof AlertDialogPortal>>
ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Content from bits-ui except child
Prop Type Default
portalProps WithoutChildrenOrChild<ComponentProps<typeof AlertDialogPortal>>
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Content from bits-ui except child

AlertDialog.Header

ref bindable HTMLDivElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
ref bindable HTMLDivElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

AlertDialog.Title

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Title from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Title from bits-ui

AlertDialog.Description

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Description from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Description from bits-ui
band boolean
Default false
A hairline and a quiet surface out to both edges and the bottom corners. Last child only.
ref bindable HTMLDivElement | null
Default null
class string
children Snippet
...rest
Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements
Prop Type Default
band

A hairline and a quiet surface out to both edges and the bottom corners. Last child only.

boolean false
ref bindable HTMLDivElement | null null
class string
children Snippet
...rest Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements

AlertDialog.Cancel

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Cancel from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Cancel from bits-ui

AlertDialog.Action

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Action from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Action from bits-ui

AlertDialog.Portal

...rest
Every prop of AlertDialog.Portal from bits-ui
Prop Type Default
...rest Every prop of AlertDialog.Portal from bits-ui

AlertDialog.Overlay

ref bindable HTMLElement | null
Default null
class string
...rest
Every prop of AlertDialog.Overlay from bits-ui
Prop Type Default
ref bindable HTMLElement | null null
class string
...rest Every prop of AlertDialog.Overlay from bits-ui