<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-5HGSQD2L" height="0" width="0" style="display:none;visibility:hidden" title="GTM"></iframe>

Alert Box

A prominent method of messaging users about important information.
scriptKeys: alertBoxstyleKeys: alertBox

Use Alert Box...

  • For alert messages that apply to an entire page, or to a section of a page.
  • For alert messages that float over page content. Refer to Toasts.
  • For destructible and interruptible tasks. Refer to Warning and Error skins.

Don't use Alert Box...

  • For individual form field errors. Refer to Error guidelines for Forms.

The preview has been updated.

Skin

Info

Use skin="info" for standard messages. This is the default skin.

The preview has been updated.

Positive

Use skin="positive" for positive or success messages.

The preview has been updated.

Success

Use skin="success" for positive or success messages.

The preview has been updated.

Warning

Use skin="warning" for cautionary messages.

The preview has been updated.

Error

Use skin="error" for error or critical messages.

The preview has been updated.

Use skin="legal-warning" when required for legal compliance messages such as those covered by California's Prop 65. There are specific legal requirements governing this messages icon, font size, and font color. They should not be dismissible.

The preview has been updated.

Dismissible

Dismissible alerts give users agency to remove messages after they have read them. For React, use AlertBoxDismissButton to make Alert Box dismissible. For vanilla JS, use a button with class="swan-alert-box-close-button" to make Alert Box dismissible.

The preview has been updated.

Controlled

For React, use dismissed to take control of the dismissed state. Use onRequestDismiss in order to be notified when the Alert Box wants to be dismissed.

The preview has been updated.

Narrow

Use narrow to apply a maximum width of 550px, or 344px on < md breakpoints, to an Alert Box.

The preview has been updated.

Toast

Use toast for an Alert Box that pops upward over the page content, usually as an immediate response to user actions. Alert Box does not provide positioning or animation. Position them near the edge of the viewport.

The preview has been updated.

Implementation

Preserving user input

When an Alert Box occurs, it is important to preserve as much user input as possible. This allows the user to modify any incorrect information without having to re-enter it from scratch.

Alerts added page load

When dynamically adding an alert after initial page load, the content area where the alert will appear will need to already have role="status" aria-live="polite" on it. These inform assistive technologies that they need to notify the user when any content inside that area changes, and thus the browser will announce the alert when it appears.

Positioning

  • Place warnings or error alerts near the relevant issue to help users identify any specific actions they need to take.
  • Avoid covering information that users need to move forward in their experience (e.g. CTAs, input fields, checkboxes).
  • Page positioning is not included with Alert Box. Alerts that float above the page content, or those that have an animated pop-up toast style, must be setup during implementation.

Content

  • Use clear, concise messages that inform and guide users.
  • Users with vision issues may not be able to see the color of the Alert Box. The nature of the alert must be clear via text alone. It may be useful to add some visually-hidden text to the alert that won't show up on screens. For example, a positive alert indicating that an operation has succeeded might have the visually hidden text "Success:" at the start of the message.

Props

AlertBox
This component is implemented using the <div /> as the root element. You can utilize the native attributes supported by <div /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
width"standard" | "narrow" | nullfalse
⚠️ Deprecated - This is deprecated without a replacement.
The width of the AlertBox
"standard"
skin"standard" | "info" | "success" | "warning" | "error" | "positive" | "legal-warning" | nullfalse
The visual style of the AlertBox The 'standard' skin is deprecated; use 'info' instead The 'positive' skin is deprecated; use 'success' instead
info
toastboolean | nullfalse
Whether or not the alert is a toast
null
dismissedboolean | nullfalse
Whether or not the alert is presently dismissed
null
onRequestDismiss(() => void) | nullfalse
Callback fired when the user has requested that the alert be dismissed
null
AlertBoxDismissButton
This component is implemented using the <button /> as the root element. You can utilize the native attributes supported by <button /> tag. The ref is directly assigned to the root element, allowing you to access and manipulate it as needed.
See core props for additional props that can be applied to this component.
proptyperequireddescriptiondefault
visuallyHiddenLabelReactNodeLikefalse
A localized label which describes the dismiss button to screen-reader users Typically it is just a string like "Close" or "Dismiss alert" but can accept a ReactNode as well
null
accessibleTextstring | nullfalse
Serves same purpose as `visuallyHiddenLabel` but accepts only string. In the long run, we prefer this over the former.
null