Skip to content
portalbits
Home Docs GitHub(opens in a new tab)

Guides

Get startedFoundationsMotion

Components

All components

Buttons

ButtonIconButton

Inputs

InputSelectTextareaSlider

Selection

CheckboxToggleToggleGroupSwitchRadioGroup

Identity

AvatarBadge

Overlays

DialogPopoverTooltipDropdownMenuAlertDialog

Disclosure

TabsAccordion

Cards

AppCardArticleCardFeatureCard

Content

CarouselSectionHeaderEmptyStateAlertProgressSeparatorRowListRow

Chrome

PortalShellSidebarNavMobileNavTopBarAuthFrameColorSelectorFloatingNav

AlertDialog

A confirmation that holds focus until the person decides.

3 drafts left

Variations

Source

<script lang="ts">
  import 'portal-bits/styles.css';
  import 'portal-bits/tokens.css';
  import type { Snippet } from 'svelte';

  let { children }: { children: Snippet } = $props();
</script>

{@render children()}
<script lang="ts">
  import AlertDialogExample from './AlertDialogExample.svelte';
</script>

<AlertDialogExample tone={"danger"} />
<script lang="ts">
  import { AlertDialog } from 'portal-bits';
  let { tone = 'danger' }: { tone?: 'neutral' | 'danger' } = $props();
  let drafts = $state(3);
</script>

<div class="stack">
  <AlertDialog
    title={tone === 'danger' ? 'Delete this draft?' : 'Publish this draft?'}
    description={tone === 'danger'
      ? 'The draft and its comments are removed for everyone. This cannot be undone.'
      : 'Everyone with the link can read it. You can unpublish later.'}
    confirmLabel={tone === 'danger' ? 'Delete draft' : 'Publish'}
    {tone}
    onConfirm={() => (drafts = Math.max(0, drafts - 1))}
  >
    {#snippet trigger()}{tone === 'danger' ? 'Delete draft' : 'Publish draft'}{/snippet}
  </AlertDialog>
  <p aria-live="polite">{drafts} {drafts === 1 ? 'draft' : 'drafts'} left</p>
</div>

<style>
  .stack {
    display: grid;
    justify-items: center;
    gap: 12px;
  }
  p {
    margin: 0;
  }
</style>

API reference

These tables list the props and snippets that AlertDialog declares. Attributes passed through to an element or primitive are listed under Forwarded attributes, not here.

Props

NameTypeDefaultRequiredBindingDescription
openbooleanfalseNoBindableWhether the dialog is open.
titlestringNoneYesOne-wayThe question. It names the dialog.
descriptionstringNoneYesOne-wayWhat happens when the person confirms.
confirmLabelstringNoneYesOne-wayThe confirm button text. Name the action.
cancelLabelstringCancelNoOne-wayThe cancel button text.
tone'neutral' | 'danger'neutralNoOne-wayDanger paints the confirm button red.
onConfirm() => voidNoneNoOne-wayRuns when the person confirms. The dialog then closes.
triggerLabelstringNoneNoOne-waySets `aria-label` on the trigger.
triggerClassstringSecondary 40px buttonNoOne-wayReplaces the trigger classes.
theme'light' | 'dark'lightNoOne-wayTheme scope for the portaled content. Portaled content does not inherit the page scope.

Snippets

NameTypeDefaultRequiredBindingDescription
triggerSnippetNoneNoOne-wayThe trigger content. Without it, bind `open`.

Forwarded attributes

None. AlertDialog forwards no attributes.

The primitive underneath is a Bits UI peer dependency. Its own options are documented in the Bits UI Alert Dialog documentation. Only the props listed on this page are part of the AlertDialog contract. No data attributes are documented as stable.

Limits

  • Escape and Cancel close it. A click outside does not, unlike Dialog.
  • Cancel takes focus when it opens, so the safe choice is the default.
  • The danger fill is an adaptation that uses the error token.

Related

  • Dialog
  • DropdownMenu
Previous DropdownMenu Next Tabs

On this page

  • Preview
  • Source
  • API reference
  • Props
  • Snippets
  • Forwarded attributes
  • Limits