Alert Dialog
Installation
npx @mielui/svelte add alert-dialogyarn dlx @mielui/svelte add alert-dialogbunx @mielui/svelte add alert-dialogUsage
Confirm and Close call onclick before closing. Call event.preventDefault() to keep the alert dialog open, or set closeOnClick={false} for asynchronous work. Both support bind:element. Focus starts on Exit when the dialog opens. Set ariaBusy on Content while a confirmation is pending.
The theme's chrome.borders setting chooses single or double framing. single is the default.
<script lang="ts">
import * as AlertDialog from '@mielui/svelte/components/alert-dialog';
import Kbd from '@mielui/svelte/components/kbd';
</script>
<AlertDialog.Root error>
<AlertDialog.Trigger variant="destructive">Delete</AlertDialog.Trigger>
<AlertDialog.Content size="md">
<AlertDialog.Header>
<AlertDialog.Title>Delete this project?</AlertDialog.Title>
<AlertDialog.Description>This cannot be undone.</AlertDialog.Description>
</AlertDialog.Header>
<AlertDialog.Footer>
<AlertDialog.Close>Cancel <Kbd shortcut="esc" /></AlertDialog.Close>
<AlertDialog.Confirm>Delete <Kbd shortcut="enter" /></AlertDialog.Confirm>
</AlertDialog.Footer>
</AlertDialog.Content>
</AlertDialog.Root>Examples
Workspace deletion
The trigger and title carry an icon, and a status line reports the result.
Sample workspace is active.
Destructive confirmation
Sign out confirmation
Glass surface
Set surface="glass" on Content for a translucent, blurred background. Omit surface to inherit --mielui-surface from the theme, or set surface="solid" to override it. Glass falls back to an opaque surface when backdrop filtering is unavailable or reduced transparency is requested.
Keeping it open
An alert dialog never closes from a press outside. Escape still closes it. Set allowEscape={false} on Content when even that is too easy, such as a confirmation the person must read.
Confirm and Close close the dialog after onclick. Call event.preventDefault() there to keep it open while you work, and show progress with loading and labels. onOpenChange on Root tells you each time it opens or closes, whichever way that happened.
Nothing deleted yet
Buttons and text parts
Trigger, Close and Confirm are built on Button, so they accept its props. variant and size change the look, disabled blocks activation, and href renders a link. loading shows a spinner and ignores clicks, and labels sets the text for each state. unstyled removes the Button classes so class alone styles the part. onclick and onkeydown run before the part does its own work. Confirm is destructive when Root has error.
Header, Title, Description and Footer render their children and take class.
API reference
AlertDialog.Root
Controls alert dialog state.
openBindablebooleanWhether it is open. Bind it to control the state from outside.
Default
falseonOpenChange((open: boolean) => void)Called with the new state whenever it opens or closes.
errorbooleanSets supported browser chrome to red while the alert dialog is open.
Default
falsechildrenSnippet<[]>Content rendered inside.
AlertDialog.Close
Closes the dialog without confirming.
closeOnClickbooleanCloses the dialog after the button is clicked. Set false to keep it open while work finishes.
Default
truedisabledbooleanPrevents activation. A disabled link loses its destination and is skipped by Tab.
variantButtonVariantVisual style. Choose it for what the action means, not for decoration.
size"sm" | "md" | "lg" | "icon"Control height.
iconis a square button for a single icon.childrenSnippet<[]>Content rendered inside.
elementBindableHTMLButtonElement | HTMLAnchorElementBindable reference to the rendered DOM element. Type is the union of the two possible element types -- narrow at the use site:
unstyledbooleanSkip the variant/size base classes and render with
classalone.statusButtonStatusControlled visual state. Loading remains focusable and refuses activation.
loadingbooleanConvenience alias for
status="loading".labelsButtonLabelsOverrides the built-in text and accessible names. Every key is optional and English is the fallback.
onclick((event: MouseEvent) => void)Called when the button is activated. Loading and disabled buttons do not call it.
onkeydown((event: KeyboardEvent) => void)Called on key down, before the button handles the key itself.
hrefstringRenders a link to this address instead of a button.
AlertDialog.Confirm
Confirms and closes the dialog.
closeOnClickbooleanCloses the dialog after the button is clicked. Set false to keep it open while work finishes.
Default
truedisabledbooleanPrevents activation. A disabled link loses its destination and is skipped by Tab.
variantButtonVariantVisual style. Choose it for what the action means, not for decoration.
size"sm" | "md" | "lg" | "icon"Control height.
iconis a square button for a single icon.childrenSnippet<[]>Content rendered inside.
elementBindableHTMLButtonElement | HTMLAnchorElementBindable reference to the rendered DOM element. Type is the union of the two possible element types -- narrow at the use site:
unstyledbooleanSkip the variant/size base classes and render with
classalone.statusButtonStatusControlled visual state. Loading remains focusable and refuses activation.
loadingbooleanConvenience alias for
status="loading".labelsButtonLabelsOverrides the built-in text and accessible names. Every key is optional and English is the fallback.
onclick((event: MouseEvent) => void)Called when the button is activated. Loading and disabled buttons do not call it.
onkeydown((event: KeyboardEvent) => void)Called on key down, before the button handles the key itself.
hrefstringRenders a link to this address instead of a button.
AlertDialog.Content
Renders the dialog surface.
surface"solid" | "glass"Surface treatment. Omit it to inherit
--mielui-surfacefrom the theme.ariaBusybooleanMarks the dialog busy for assistive technology while an action runs.
allowEscapebooleanLets Escape dismiss the dialog.
Default
truesizeDialogSizeMaximum width of the panel. Defaults to
xs.Default
'xs'classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
AlertDialog.Description
Renders the dialog description.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
AlertDialog.Footer
Groups dialog actions.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
AlertDialog.Header
Groups dialog heading content.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
AlertDialog.Title
Renders the dialog title.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
AlertDialog.Trigger
Opens the alert dialog.
disabledbooleanPrevents activation. A disabled link loses its destination and is skipped by Tab.
variantButtonVariantVisual style. Choose it for what the action means, not for decoration.
size"sm" | "md" | "lg" | "icon"Control height.
iconis a square button for a single icon.childrenSnippet<[]>Content rendered inside.
elementBindableHTMLButtonElement | HTMLAnchorElementBindable reference to the rendered DOM element. Type is the union of the two possible element types -- narrow at the use site:
unstyledbooleanSkip the variant/size base classes and render with
classalone.statusButtonStatusControlled visual state. Loading remains focusable and refuses activation.
loadingbooleanConvenience alias for
status="loading".labelsButtonLabelsOverrides the built-in text and accessible names. Every key is optional and English is the fallback.
onclick((event: MouseEvent) => void)Called when the button is activated. Loading and disabled buttons do not call it.
onkeydown((event: KeyboardEvent) => void)Called on key down, before the button handles the key itself.
hrefstringRenders a link to this address instead of a button.
pnpm dlx @mielui/svelte add alert-dialog