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

Alert

A message announced when an action needs attention.

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 AlertExample from './AlertExample.svelte';
</script>

<AlertExample />
<script lang="ts">
  import { Alert, Button } from 'portal-bits';
  let message = $state('');
</script>

<div class="field">
  <Button onclick={() => (message = message ? '' : 'Enter a display name before saving.')}>
    {message ? 'Clear alert' : 'Show alert'}
  </Button>
  {#if message}<Alert {message} />{/if}
</div>

<style>
  .field {
    max-width: 340px;
  }
</style>

API reference

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

Props

NameTypeDefaultRequiredBindingDescription
messagestringNoneNoOne-wayThe text. Supply it or `children`, not both.
classstring""NoOne-wayExtra classes, added after the component classes.

Snippets

NameTypeDefaultRequiredBindingDescription
childrenSnippetNoneNoOne-wayShort inline content. Supply it or `message`, not both.

Forwarded attributes

  • Native paragraph attributes except `children` and `role`: `id`, `aria-*`, `data-*`, and handlers. They land on the `p` element.

No data attributes are documented as stable.

Limits

  • The type requires exactly one of `message` or `children`.
  • `role` is fixed at `alert`. Mount the component when an action fails, and remove it when cleared.
  • No dismiss button, icon, or heading. Alert is an adaptation.

Related

  • EmptyState
  • Input
Previous EmptyState Next Progress

On this page

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