Skip to content

HyToast ​

Usage examples on this page are written for Lit / plain HTML (<hy-toast>). The same component ships as HyToast in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A toast notification component for displaying transient messages with auto-dismiss.

Toast or alert? ​

A toast is feedback on an action the user just took — saved, deleted, couldn't save — and leaves on its own. A message that belongs to a place on the page and stays until it no longer applies is hy-alert; a region whose content failed to load is hy-empty-state with a retry.

Key Features:

  • Multiple semantic variants (info, success, warning, danger)
  • Auto-dismiss with configurable duration
  • Pause timer on hover and window focus loss
  • Optional dismiss button
  • Automatic variant-appropriate icons
  • Custom icon support
  • Action slot for buttons/links
  • Accessible with proper ARIA live region attributes

Accessibility: built in ​

  • Semantic ARIA roles (role="alert" for danger, role="status" for others)
  • Visually-hidden variant labels announced by screen readers
  • aria-atomic ensures entire toast is announced on updates
  • Keyboard accessible dismiss button
  • High contrast mode support
  • Reduced motion support

Accessibility: your part ​

  • Raise duration for a longer message, never lower it below the default, and keep pause-on-hover and pause-on-focus-loss on.
  • Never move keyboard focus into a toast.

When to use

  • Confirming something that just happened and needs no answer: saved, sent, copied, deleted.
  • Offering a quick undo for an action that just ran.

Do

  • Show one toast at a time for one event.
  • Keep it to one short sentence.

When not to use

  • Information or an action people must not lose: an hy-alert on the page, or hy-dialog. A toast can leave unseen, so anything in its action slot must also be reachable elsewhere.
  • A decision needed before going on: hy-dialog.
  • A form field's error: the field's own error-message, beside the field.

Examples ​

Basic Usage ​

html
<hy-toast variant="success" open> Your changes have been saved. </hy-toast>

With Title ​

html
<hy-toast variant="info" open label="New Update"> A new version is available. </hy-toast>

Custom Duration ​

html
<hy-toast variant="warning" open duration="10000"> Session expiring in 5 minutes. </hy-toast>

Persistent Toast (no auto-dismiss) ​

html
<hy-toast variant="danger" open duration="0" dismissible>
  Connection lost. Please check your network.
</hy-toast>

With Action ​

html
<hy-toast variant="info" open>
  File deleted.
  <hy-button slot="action" size="small">Undo</hy-button>
</hy-toast>

Viewport Positioning (top-right corner) ​

html
<hy-toast variant="success" open anchor-vertical="top" anchor-horizontal="right">
  Settings saved successfully.
</hy-toast>

Viewport Positioning (bottom-center) ​

html
<hy-toast variant="info" open anchor-vertical="bottom" anchor-horizontal="center">
  New message received.
</hy-toast>

API ​

Properties ​

PropertyAttributeTypeDefaultDescription
variantvariant'info' | 'success' | 'warning' | 'danger''info'Visual style variant determining the toast's color scheme and semantic meaning.
emphasisemphasis'solid' | 'soft' | 'outlined' | 'tinted''tinted'Visual chrome weight on top of the role.
dismissibledismissiblebooleantrueWhether the toast can be dismissed by the user. When true, a close button is displayed.
openopenbooleanfalseWhether the toast is currently visible. Set to true to show the toast, false to hide it.
iconiconstring | undefined—Icon name to display. If not provided, a variant-appropriate default icon is used. Set to empty string to hide the icon entirely.
labellabelstring | undefined—Title/label for the toast. Displayed as a heading above the message.
variantLabelvariant-labelstring | undefined—The visually hidden word read before the message, naming the toast's kind. Unset, it is the English word for the variant with its colon: Information:, Success:, Warning:, Error:. The punctuation is part of the string, so a translation writes its own (Erreur :). Use for internationalization.
dismissLabeldismiss-labelstring'Dismiss toast'Accessible label for the dismiss button. Use for internationalization.
durationdurationnumber5000Auto-dismiss duration in milliseconds. Set to 0 or Infinity to disable auto-dismiss.
pauseOnHoverpause-on-hoverbooleantrueWhether to pause the auto-dismiss timer when hovering over the toast.
pauseOnFocusLosspause-on-focus-lossbooleantrueWhether to pause the auto-dismiss timer when the window loses focus.
anchorVerticalanchor-vertical'top' | 'bottom'undefined (no viewport positioning)Vertical anchor position for viewport positioning. When set, the toast uses fixed positioning relative to the viewport. Combine with anchorHorizontal to position in any of 6 screen locations.
anchorHorizontalanchor-horizontal'left' | 'center' | 'right'undefined (no viewport positioning)Horizontal anchor position for viewport positioning. When set, the toast uses fixed positioning relative to the viewport. Combine with anchorVertical to position in any of 6 screen locations.

Events ​

EventDetailDescription
show—Fired when the toast becomes visible. Detail: { source: HyVisibilitySource }
hide—Fired when the toast is hidden. Detail: { source: HyVisibilitySource }
request-close—Fired before hiding; cancelable to prevent close. Detail: { source: HyVisibilitySource }

Slots ​

SlotDescription
defaultThe main toast message content
actionOptional action buttons or links

CSS Parts ​

PartDescription
baseThe toast's base wrapper element
iconThe icon container
contentThe content wrapper (title + message)
titleThe title element
messageThe message element
actionThe action slot container
close-buttonThe dismiss button (when dismissible)

CSS Custom Properties ​

The documented hooks. Every override hook the component reads — one per token it paints — is listed in @whitespaceux/harmony/theme-api.json, and @whitespaceux/harmony/component-bindings.json (the Harmony MCP get-bindings tool) says which part and state each one paints.

PropertyDefaultDescription
--hy-toast-background-info-tinted-restvar(--hy-background-info-tinted-rest)One of the generated color hooks (paint/toast.mjs): --hy-toast[-<part>]-<family>-<variant>-<emphasis-or-on>-<state> (family: background, foreground or border), one per cell and state, each falling back to the job token of the same name (the default cell is info tinted). Components ▸ Add an override lists them all.
--hy-toast-action-background-info-soft-restvar(--hy-background-info-soft-rest)One of the slotted action's re-points: --hy-toast-action-background-<role>-<emphasis>-<state> for every tint-reading job of a role-matched hy-button (every soft / tinted state, the outlined / plain hover and press).
--hy-toast-border-info-restvar(--hy-border-info-rest)Info variant border color
--hy-toast-border-danger-restvar(--hy-border-danger-rest)Danger variant border color
--hy-toast-border-success-restvar(--hy-border-success-rest)Success variant border color
--hy-toast-border-warning-restvar(--hy-border-warning-rest)Warning variant border color
--hy-toast-gap-container-lgvar(--hy-gap-container-lg)Gap between main toast sections
--hy-toast-content-gap-container-smvar(--hy-gap-container-sm)Gap between content elements (title/message)
--hy-toast-action-gap-container-smvar(--hy-gap-container-sm)Gap between action items
--hy-toast-padding-container-smvar(--hy-padding-container-sm)Padding inside the toast
--hy-toast-radius-container-mdvar(--hy-radius-container-md)Border radius of the toast
--hy-toast-stroke-smvar(--hy-stroke-sm)Border width
--hy-toast-overlay-shadow-colorvar(--hy-overlay-shadow-color)Close button hover background
--hy-toast-shadow-elevation-4var(--hy-shadow-elevation-4)Box shadow for the toast
--hy-toast-icon-size-lgvar(--hy-icon-size-lg)Size of the toast icon
--hy-toast-body-md-font-familyvar(--hy-body-md-font-family)Font family override for toast message
--hy-toast-min-width—Minimum width of the toast
--hy-toast-surface-width-lgvar(--hy-surface-width-lg)Maximum width of the toast

Methods ​

show() ​

Shows the toast programmatically.

hide() ​

Hides the toast programmatically. Emits a cancelable request-close event first.

Parameters:

  • source - How the close was triggered (for event detail)

Built with Lit. Documented with VitePress.