Alert Dialog
A modal dialog that interrupts the user with important content and expects a response.
Installation
pnpm add @heyramzi/ui bits-uiUsage
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
openbindableboolean- Default
false ...rest- Every prop of
AlertDialog.Rootfrombits-ui
| Prop | Type | Default |
|---|---|---|
open bindable | boolean | false |
...rest | Every prop of AlertDialog.Root from bits-ui | |
AlertDialog.Trigger
refbindableHTMLElement | null- Default
null ...rest- Every prop of
AlertDialog.Triggerfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
...rest | Every prop of AlertDialog.Trigger from bits-ui | |
AlertDialog.Content
portalPropsWithoutChildrenOrChild<ComponentProps<typeof AlertDialogPortal>>refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Contentfrombits-uiexceptchild
| 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
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/elements
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLDivElement | null | null |
class | string | |
children | Snippet | |
...rest | Every prop of HTMLAttributes<HTMLDivElement> from svelte/elements | |
AlertDialog.Title
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Titlefrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of AlertDialog.Title from bits-ui | |
AlertDialog.Description
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Descriptionfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of AlertDialog.Description from bits-ui | |
AlertDialog.Footer
bandboolean- Default
false - A hairline and a quiet surface out to both edges and the bottom corners. Last child only.
refbindableHTMLDivElement | null- Default
null classstringchildrenSnippet...rest- Every prop of
HTMLAttributes<HTMLDivElement>fromsvelte/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
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Cancelfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of AlertDialog.Cancel from bits-ui | |
AlertDialog.Action
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Actionfrombits-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.Portalfrombits-ui
| Prop | Type | Default |
|---|---|---|
...rest | Every prop of AlertDialog.Portal from bits-ui | |
AlertDialog.Overlay
refbindableHTMLElement | null- Default
null classstring...rest- Every prop of
AlertDialog.Overlayfrombits-ui
| Prop | Type | Default |
|---|---|---|
ref bindable | HTMLElement | null | null |
class | string | |
...rest | Every prop of AlertDialog.Overlay from bits-ui | |