Don't use Alert Box...
- For alert messages that apply to a specific section of the page. Use Status Message instead.
- For individual form field errors. Refer to Error guidelines for Forms.
accessibleText
and accessibleTextForIcon
are deprecated in SWAN 3.24. These prop will be removed in favor of SWAN's i18n system. Please opt in to the i18n system and remove these prop.
The preview has been updated.
Skin
skin='standard'
is deprecated in SWAN v3.3
Use skin='info'
instead, which aligns with new semantic roles on SWAN components.
Info
Use skin="info"
for standard messages. This is the default skin.
The preview has been updated.
Positive
skin='positive'
is deprecated in SWAN v3.3
Use skin='success'
instead, which aligns with new semantic roles on SWAN components.
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.
Legal Warning
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
width
is deprecated in SWAN v3.3
To maintain a high-quality user experience, we are no longer supporting this feature, and are not providing a direct replacement.
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.
Accessibility
If not using SWAN's i18n system, AlertBox
requires the following accessible props for a11y compliance:
- An accessible label for the icon must be provided using the
accessibleTextForIcon
prop. This will announce the severity to assistive technology. Ensure this is localized as it will be read out to the user. - If using
AlertBoxDismissButton
you must provide theaccessibleText
prop used to describe the action to screen readers e.g. "Dismiss alert". Ensure this is localized as it will be read out to the user.
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.