AlertDialog
A modal dialog that interrupts the user for a decision and can't be dismissed by a press outside.
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Schema } from "effect"
import { buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogBasicMessage = UiSchema.TaggedEnum({
RequestedOpenAlertDialog: {},
RequestedCloseAlertDialog: {},
ClickedDelete: {},
ClickedRestore: {}
})
export const AlertDialogBasic = Html.component({
name: "AlertDialogBasic",
model: Schema.Struct({ open: Schema.Boolean, deleted: Schema.Boolean }),
message: AlertDialogBasicMessage
}).make({
init: () => ({ open: false, deleted: false }),
update: {
RequestedOpenAlertDialog: ($) => $.evolve({ open: true }),
RequestedCloseAlertDialog: ($) => $.evolve({ open: false }),
ClickedDelete: ($) => $.evolve({ open: false, deleted: true }),
ClickedRestore: ($) => $.evolve({ deleted: false })
},
view: (h, model) =>
model.deleted
? h.div.class("flex flex-col items-center gap-3.5").children(
h.p.class("m-0 text-xs text-muted-foreground tabular-nums").children("The project was deleted."),
h.button.class(buttonVariants({ variant: "outline" }))
.on("click", AlertDialogBasicMessage.ClickedRestore())
.children("Undo")
)
: AlertDialog(h, {
props: { open: model.open },
onEmit: {
RequestedOpen: () => AlertDialogBasicMessage.RequestedOpenAlertDialog(),
RequestedClose: () => AlertDialogBasicMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div(
alertDialog.trigger(h.button.class(buttonVariants({ variant: "destructive" }))).children(
"Delete project"
),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog).children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children("Delete this project?"),
AlertDialogDescription(h, alertDialog).children(
"The project, its deployments and its logs are removed for everyone. You can't undo this."
)
),
AlertDialogFooter(h).children(
// Focus starts on the safe choice, and a press outside doesn't close an alert dialog.
alertDialog.initialFocus(
alertDialog.close(h.button.class(buttonVariants({ variant: "outline" })))
).children("Cancel"),
h.button.class(buttonVariants({ variant: "destructive" }))
.on("click", AlertDialogBasicMessage.ClickedDelete())
.children("Delete project")
)
)
)
)
)
})
})
Installation
Set up the project
Once per project: the packages, Tailwind CSS, the theme tokens and the
cnhelper. Follow Installation.Copy the component into your project
The kit owns behaviour, ARIA and data attributes. This file is the look, written with Tailwind classes, and it is yours to change.
src/ui/alert-dialog.ts import type { Html } from "@effect/ui/html" import type { AlertDialogParts } from "@effect/ui-kit" import { cn } from "#lib/cn" interface ClassOption { readonly class?: string | undefined } const sizes = { sm: "w-full max-w-[340px]", default: "w-full max-w-[440px]" } as const export type AlertDialogSize = keyof typeof sizes /** The layer that dims the page. A press on it doesn't close an alert dialog. */ export const AlertDialogBackdrop = <Msg>(h: Html.H<Msg>, alertDialog: AlertDialogParts, options: ClassOption = {}) => alertDialog.backdrop( h.div.class(cn( "fixed inset-0 bg-[color-mix(in_oklab,var(--shadow-color)_45%,transparent)] transition-opacity duration-200", "data-[ending-style]:opacity-0 data-[starting-style]:opacity-0", options.class )) ) /** Centres the popup in the screen. */ export const AlertDialogViewport = <Msg>(h: Html.H<Msg>, alertDialog: AlertDialogParts, options: ClassOption = {}) => alertDialog.viewport(h.div.class(cn("pointer-events-none fixed inset-0 grid place-items-center p-4", options.class))) export const AlertDialogPopup = <Msg>( h: Html.H<Msg>, alertDialog: AlertDialogParts, options: ClassOption & { readonly size?: AlertDialogSize | undefined } = {} ) => alertDialog.popup( h.div.class(cn( "pointer-events-auto relative flex max-h-full flex-col gap-4 rounded-lg border bg-popover p-6 text-sm", "text-foreground shadow-float outline-none", "transition-[opacity,scale] duration-200 ease-out", "data-[ending-style]:scale-95 data-[ending-style]:opacity-0", "data-[starting-style]:scale-95 data-[starting-style]:opacity-0", sizes[options.size ?? "default"], options.class )) ) export const AlertDialogHeader = <Msg>(h: Html.H<Msg>, options: ClassOption = {}) => h.div.class(cn("flex flex-col gap-1.5", options.class)) export const AlertDialogTitle = <Msg>(h: Html.H<Msg>, alertDialog: AlertDialogParts, options: ClassOption = {}) => alertDialog.title( h.h2.class(cn("m-0 border-0 p-0 text-[16px] leading-snug font-semibold tracking-tight", options.class)) ) export const AlertDialogDescription = <Msg>(h: Html.H<Msg>, alertDialog: AlertDialogParts, options: ClassOption = {}) => alertDialog.description( h.p.class(cn( "m-0 text-[13px] leading-normal text-muted-foreground", "[&_code]:rounded-xs [&_code]:bg-muted [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-xs " + "[&_code]:text-foreground", options.class )) ) export const AlertDialogFooter = <Msg>(h: Html.H<Msg>, options: ClassOption = {}) => h.div.class(cn("flex flex-wrap items-center justify-end gap-2", options.class))Import it
import { AlertDialogBackdrop, AlertDialogViewport, AlertDialogPopup, AlertDialogHeader, AlertDialogTitle, AlertDialogDescription, AlertDialogFooter } from "#ui/alert-dialog"
Usage
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Schema } from "effect"
import { buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogBasicMessage = UiSchema.TaggedEnum({
RequestedOpenAlertDialog: {},
RequestedCloseAlertDialog: {},
ClickedDelete: {},
ClickedRestore: {}
})
export const AlertDialogBasic = Html.component({
name: "AlertDialogBasic",
model: Schema.Struct({ open: Schema.Boolean, deleted: Schema.Boolean }),
message: AlertDialogBasicMessage
}).make({
init: () => ({ open: false, deleted: false }),
update: {
RequestedOpenAlertDialog: ($) => $.evolve({ open: true }),
RequestedCloseAlertDialog: ($) => $.evolve({ open: false }),
ClickedDelete: ($) => $.evolve({ open: false, deleted: true }),
ClickedRestore: ($) => $.evolve({ deleted: false })
},
view: (h, model) =>
model.deleted
? h.div.class("flex flex-col items-center gap-3.5").children(
h.p.class("m-0 text-xs text-muted-foreground tabular-nums").children("The project was deleted."),
h.button.class(buttonVariants({ variant: "outline" }))
.on("click", AlertDialogBasicMessage.ClickedRestore())
.children("Undo")
)
: AlertDialog(h, {
props: { open: model.open },
onEmit: {
RequestedOpen: () => AlertDialogBasicMessage.RequestedOpenAlertDialog(),
RequestedClose: () => AlertDialogBasicMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div(
alertDialog.trigger(h.button.class(buttonVariants({ variant: "destructive" }))).children(
"Delete project"
),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog).children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children("Delete this project?"),
AlertDialogDescription(h, alertDialog).children(
"The project, its deployments and its logs are removed for everyone. You can't undo this."
)
),
AlertDialogFooter(h).children(
// Focus starts on the safe choice, and a press outside doesn't close an alert dialog.
alertDialog.initialFocus(
alertDialog.close(h.button.class(buttonVariants({ variant: "outline" })))
).children("Cancel"),
h.button.class(buttonVariants({ variant: "destructive" }))
.on("click", AlertDialogBasicMessage.ClickedDelete())
.children("Delete project")
)
)
)
)
)
})
})
Examples
Async confirm
The dialog stays open, and refuses Escape, until the request finishes.
Signed in on 4 devices
import { Command, UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Effect, Schema } from "effect"
import { Button, buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogAsyncMessage = UiSchema.TaggedEnum({
RequestedOpenAlertDialog: {},
RequestedCloseAlertDialog: {},
PressedRevoke: {},
CompletedRevokeSessions: {}
})
const RevokeSessions = Command.make(
"RevokeSessions",
{ args: {}, mode: "switch" },
() => Effect.as(Effect.sleep("1500 millis"), AlertDialogAsyncMessage.CompletedRevokeSessions())
)
export const AlertDialogAsync = Html.component({
name: "AlertDialogAsync",
model: Schema.Struct({ open: Schema.Boolean, revoking: Schema.Boolean, sessions: Schema.Number }),
message: AlertDialogAsyncMessage
}).make({
init: () => ({ open: false, revoking: false, sessions: 4 }),
update: {
RequestedOpenAlertDialog: ($) => $.evolve({ open: true }),
// Escape and Cancel are refused while the request runs.
RequestedCloseAlertDialog: ($) => $.model.revoking ? $.model : $.evolve({ open: false }),
PressedRevoke: ($) => $.evolve({ revoking: true }).run(RevokeSessions.make({})),
CompletedRevokeSessions: ($) => $.evolve({ open: false, revoking: false, sessions: 1 })
},
view: (h, model) =>
AlertDialog(h, {
props: { open: model.open },
onEmit: {
RequestedOpen: () => AlertDialogAsyncMessage.RequestedOpenAlertDialog(),
RequestedClose: () => AlertDialogAsyncMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div.class("flex flex-col items-center gap-3.5").children(
alertDialog.trigger(
h.button.class(buttonVariants({ variant: "outline" })).disabled(model.sessions === 1)
).children("Sign out everywhere"),
h.p.class("m-0 text-xs text-muted-foreground tabular-nums").children(
model.sessions === 1 ? "Signed in on this device only" : `Signed in on ${model.sessions} devices`
),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog).children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children("Sign out of all other devices?"),
AlertDialogDescription(h, alertDialog).children(
"Every other session ends at once. You stay signed in here."
)
),
AlertDialogFooter(h).children(
Button(h, {
element: alertDialog.close(h.button),
variant: "outline",
props: { disabled: model.revoking }
}).children("Cancel"),
// While loading it is disabled but still focusable, so focus doesn't fall out of the dialog.
Button(h, { loading: model.revoking, onPress: AlertDialogAsyncMessage.PressedRevoke() })
.children(model.revoking ? "Signing out" : "Sign out")
)
)
)
)
)
})
})
Discard changes
A small confirmation in front of a draft the user would lose.
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Schema } from "effect"
import { buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogDiscardMessage = UiSchema.TaggedEnum({
UpdatedDraft: { value: Schema.String },
RequestedOpenAlertDialog: {},
RequestedCloseAlertDialog: {},
ClickedDiscard: {}
})
const labelClass = "flex flex-col gap-1.5 text-[13px] font-medium"
const textareaClass =
"min-h-24 w-full resize-y rounded-md border border-input bg-background px-2.5 py-2 text-[13px] font-normal shadow-sm " +
"outline-none transition-[border-color,box-shadow] duration-150 focus-visible:border-ring focus-visible:ring-3 " +
"focus-visible:ring-ring/20"
export const AlertDialogDiscard = Html.component({
name: "AlertDialogDiscard",
model: Schema.Struct({ draft: Schema.String, open: Schema.Boolean }),
message: AlertDialogDiscardMessage
}).make({
init: () => ({ draft: "Thanks for the review. I've pushed the fixes and", open: false }),
update: {
UpdatedDraft: ($, { value }) => $.evolve({ draft: value }),
RequestedOpenAlertDialog: ($) => $.evolve({ open: true }),
RequestedCloseAlertDialog: ($) => $.evolve({ open: false }),
ClickedDiscard: ($) => $.evolve({ draft: "", open: false })
},
view: (h, model) =>
AlertDialog(h, {
props: { open: model.open },
onEmit: {
RequestedOpen: () => AlertDialogDiscardMessage.RequestedOpenAlertDialog(),
RequestedClose: () => AlertDialogDiscardMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div.class("flex w-full max-w-sm flex-col gap-3.5").children(
h.label.class(labelClass).children(
"Reply",
h.textarea.class(textareaClass)
.attr("placeholder", "Write a reply")
.value(model.draft)
.on("input", ({ value }) => AlertDialogDiscardMessage.UpdatedDraft({ value }))
),
h.div.class("flex flex-wrap items-center justify-center gap-2.5").children(
alertDialog.trigger(
h.button.class(buttonVariants({ variant: "ghost" })).disabled(model.draft === "")
).children("Discard"),
h.button.class(buttonVariants()).disabled(model.draft === "").children("Send")
),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog, { size: "sm" }).children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children("Discard this reply?"),
AlertDialogDescription(h, alertDialog).children(
"What you wrote isn't saved anywhere else."
)
),
AlertDialogFooter(h).children(
alertDialog.initialFocus(
alertDialog.close(h.button.class(buttonVariants({ variant: "outline" })))
).children("Keep writing"),
h.button.class(buttonVariants({ variant: "destructive" }))
.on("click", AlertDialogDiscardMessage.ClickedDiscard())
.children("Discard")
)
)
)
)
)
})
})
Type to confirm
The confirm button is disabled until the name matches, and Enter submits.
You own acme-production
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Schema } from "effect"
import { Button, buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogTypeToConfirmMessage = UiSchema.TaggedEnum({
RequestedOpenAlertDialog: {},
RequestedCloseAlertDialog: {},
UpdatedConfirmation: { value: Schema.String },
SubmittedConfirmation: {}
})
const workspace = "acme-production"
const labelClass = "flex flex-col gap-1.5 text-[13px] font-medium"
const inputClass =
"h-8.5 w-full rounded-md border border-input bg-background px-2.5 text-[13px] font-normal shadow-sm outline-none " +
"transition-[border-color,box-shadow] duration-150 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/20"
export const AlertDialogTypeToConfirm = Html.component({
name: "AlertDialogTypeToConfirm",
model: Schema.Struct({ open: Schema.Boolean, typed: Schema.String, transferred: Schema.Boolean }),
message: AlertDialogTypeToConfirmMessage
}).make({
init: () => ({ open: false, typed: "", transferred: false }),
update: {
RequestedOpenAlertDialog: ($) => $.evolve({ open: true, typed: "" }),
RequestedCloseAlertDialog: ($) => $.evolve({ open: false }),
UpdatedConfirmation: ($, { value }) => $.evolve({ typed: value }),
SubmittedConfirmation: ($) =>
$.model.typed === workspace ? $.evolve({ open: false, transferred: true }) : $.model
},
view: (h, model) =>
AlertDialog(h, {
props: { open: model.open },
onEmit: {
RequestedOpen: () => AlertDialogTypeToConfirmMessage.RequestedOpenAlertDialog(),
RequestedClose: () => AlertDialogTypeToConfirmMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div.class("flex flex-col items-center gap-3.5").children(
alertDialog.trigger(h.button.class(buttonVariants({ variant: "outline" }))).children(
"Transfer ownership"
),
h.p.class("m-0 text-xs text-muted-foreground tabular-nums").children(model.transferred ? "Ownership transferred" : `You own ${workspace}`),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog).children(
h.form.class("flex flex-col gap-4")
.on("submit", AlertDialogTypeToConfirmMessage.SubmittedConfirmation())
.children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children("Transfer this workspace?"),
AlertDialogDescription(h, alertDialog).children(
"The new owner can remove you. Type ",
h.code(workspace),
" to confirm."
)
),
h.label.class(labelClass).children(
"Workspace name",
alertDialog.initialFocus(h.input.class(inputClass).attrs({ autocomplete: "off", spellcheck: "false" }))
.value(model.typed)
.on("input", ({ value }) => AlertDialogTypeToConfirmMessage.UpdatedConfirmation({ value }))
),
AlertDialogFooter(h).children(
alertDialog.close(h.button.class(buttonVariants({ variant: "outline" }))).children("Cancel"),
Button(h, { variant: "destructive", props: { type: "submit", disabled: model.typed !== workspace } })
.children("Transfer")
)
)
)
)
)
)
})
})
One dialog for a list
Each row's trigger reports its id, so one alert dialog serves every row.
- CI deploys
sk_live_8f2a… - Staging
sk_test_c41d… - Ada's laptop
sk_live_02be…
import { UiSchema } from "@effect/ui"
import { Html } from "@effect/ui/html"
import { AlertDialog } from "@effect/ui-kit"
import { Schema } from "effect"
import { buttonVariants } from "#ui/button"
import {
AlertDialogBackdrop,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogPopup,
AlertDialogTitle,
AlertDialogViewport
} from "#ui/alert-dialog"
const AlertDialogRowsMessage = UiSchema.TaggedEnum({
RequestedOpenAlertDialog: { triggerId: Schema.NullOr(Schema.String) },
RequestedCloseAlertDialog: {},
ClickedRevoke: {},
ClickedReset: {}
})
const allKeys = [
{ id: "key-ci", name: "CI deploys", prefix: "sk_live_8f2a" },
{ id: "key-staging", name: "Staging", prefix: "sk_test_c41d" },
{ id: "key-laptop", name: "Ada's laptop", prefix: "sk_live_02be" }
] as const
export const AlertDialogRows = Html.component({
name: "AlertDialogRows",
model: Schema.Struct({
open: Schema.Boolean,
triggerId: Schema.NullOr(Schema.String),
revoked: Schema.Array(Schema.String)
}),
message: AlertDialogRowsMessage
}).make({
init: () => ({ open: false, triggerId: null, revoked: [] }),
update: {
RequestedOpenAlertDialog: ($, { triggerId }) => $.evolve({ open: true, triggerId }),
RequestedCloseAlertDialog: ($) => $.evolve({ open: false }),
ClickedRevoke: ($) =>
$.evolve({
open: false,
revoked: (revoked) => $.model.triggerId === null ? revoked : [...revoked, $.model.triggerId]
}),
ClickedReset: ($) => $.evolve({ revoked: [] })
},
view: (h, model) => {
const keys = allKeys.filter(({ id }) => !model.revoked.includes(id))
const current = allKeys.find(({ id }) => id === model.triggerId)
// One alert dialog for the whole list: each row's trigger reports its id.
return AlertDialog(h, {
props: { open: model.open, triggerId: model.triggerId },
onEmit: {
RequestedOpen: ({ triggerId }) => AlertDialogRowsMessage.RequestedOpenAlertDialog({ triggerId }),
RequestedClose: () => AlertDialogRowsMessage.RequestedCloseAlertDialog(),
Settled: () => undefined
},
view: (alertDialog) =>
h.div.class("flex w-full max-w-sm flex-col gap-3.5").children(
keys.length === 0
? h.div.class("flex flex-wrap items-center justify-center gap-2.5").children(
h.span.class("m-0 text-xs text-muted-foreground tabular-nums").children("No API keys left."),
h.button.class(buttonVariants({ variant: "outline", size: "sm" }))
.on("click", AlertDialogRowsMessage.ClickedReset())
.children("Start over")
)
: h.ul.class("m-0 flex list-none flex-col divide-y rounded-lg border p-0").children(
...keys.map(({ id, name, prefix }) =>
h.li.key(id).class("flex items-center justify-between gap-4 py-2 pr-2 pl-3.5").children(
h.span.class("flex flex-col text-[13px]").children(
h.strong.class("font-medium").children(name),
h.code.class("font-mono text-xs text-muted-foreground").children(`${prefix}…`)
),
alertDialog.trigger(
h.button.class(buttonVariants({ variant: "ghost", size: "sm" })).attr("id", id)
).children("Revoke")
)
)
),
alertDialog.portal(h.dialog)?.children(
AlertDialogBackdrop(h, alertDialog),
AlertDialogViewport(h, alertDialog).children(
AlertDialogPopup(h, alertDialog).children(
AlertDialogHeader(h).children(
AlertDialogTitle(h, alertDialog).children(
`Revoke “${current?.name ?? "this key"}”?`
),
AlertDialogDescription(h, alertDialog).children(
"Requests signed with this key start failing right away."
)
),
AlertDialogFooter(h).children(
alertDialog.initialFocus(
alertDialog.close(h.button.class(buttonVariants({ variant: "outline" })))
).children("Cancel"),
h.button.class(buttonVariants({ variant: "destructive" }))
.on("click", AlertDialogRowsMessage.ClickedRevoke())
.children("Revoke key")
)
)
)
)
)
})
}
})
Anatomy
The parts the view closure receives. Apply each one to an element of your own.
| Part | Description |
|---|---|
trigger | A <button> that opens it. Give it an id to tell several triggers apart. |
portal | The <dialog> in the top layer, around the parts below. undefined while closed, unless keepMounted. |
backdrop | A <div> that covers the page. undefined when nested, unless forceRenderBackdrop. |
viewport | A <div> that positions the popup. Optional. |
popup | A <div> with the content. |
title | A heading, <h1> to <h6>, that labels it. |
description | A <p> that describes it. |
close | A <button> that asks it to close. |
initialFocus | Any element, focused when it opens. |
finalFocus | Any element, focused when it closes instead of the trigger. |
API reference
Props
| Prop | Type | Description |
|---|---|---|
open | boolean | Whether the alert dialog shows. Required: the consumer owns it. |
triggerId | string | null | The id of the trigger it is open for, when it has several. |
keepMounted | boolean | The portal stays in the page, hidden, while it is closed. |
initialFocus | boolean | false leaves focus where it is when it opens. |
finalFocus | boolean | false leaves focus where it is when it closes. |
holdExit | boolean | Keeps it in its ending state while an exit animation of your own runs. |
Events
| Event | Description |
|---|---|
RequestedOpen | A trigger was pressed. Carries the trigger's id, or null. |
RequestedClose | Carries the reason: trigger-press, escape-key, close-press or close-watcher. Never outside-press. |
Settled | The transitions of an open or a close finished. |
Data attributes
| Attribute | Description |
|---|---|
data-popup-open | On the trigger while the popup is open for it. |
data-open / data-closed | On the backdrop, viewport and popup. |
data-starting-style | For the first frame after it opens, to transition from. |
data-ending-style | While it closes. It stays shown until the popup's transitions finish. |
data-nested | On the viewport and popup of one drawn inside another. |
data-nested-dialog-open | On the viewport and popup while a nested one is open. --nested-dialogs counts them. |
Related components
The components this page's file and examples import.
- Button: A native button that can stay focusable while disabled.