Section Heading
Please fill in the details below...
An alert notifies a user to high-priority or time-sensitive information.
@twilio-paste/core/alert — or — @twilio-paste/alertUse an alert to notify a user about high-priority or time-sensitive changes in the system. Alerts communicate system-level information that isn't triggered by a user action.
Use an alert for one of these types of information:
To communicate feedback on a user action, use a toast or in-page validation (e.g., full-page confirmation, inline error) instead.
To interrupt a user flow or provide the user with more than one action, use an alert dialog.
role="alert" or role="status" through props.Our alerts have icons that both announce the type of alert it is to screen readers and visually indicate what type of alert it is. That way the background color isn't the only distinguishing feature between alert types.
Here are ways that you can compose neutral, warning, error, and dismissible alerts.
Use a neutral alert to notify a user of a change that's relevant for them to achieve their current goal. Don't use an alert to communicate general promotional information.
In most cases, a neutral alert should be dismissible (i.e., have a close button) and should be assigned role="status"
A notification sent irrespective of the current user goal would likely be ignored, and may even annoy users because it will disrupt their current task and be irrelevant to their current needs.
Use a warning alert to help a user avoid an issue. If the user can take an immediate action to avoid the issue, provide a way to do that.
Be cautious about using a warning alert because they can be stressful for a user to see. In most cases, a warning alert should be assigned role="alert".
Use an error alert to help a user understand a critical issue at the system level. Provide a way to resolve the issue in the alert.
Be cautious about using an error alert because they can be stressful for a user to see. In most cases, error alerts should be assigned role="error".
There's a good chance you need to use an error alert if both these conditions are met:
Add a close button to the alert if it doesn't communicate a persistent status of the system or the account. If you make an alert dismissible, provide another way for the user to retrieve the alert information.
Don't add a close button to the alert if all these conditions are true:
Keep in mind that the longer an alert is present, the more it starts looking like part of the page and loses its interruptive intent. This might make users start to ignore important alert information.
Keep alert text brief by placing only the highest priority information in an alert. Too much text in an alert can overwhelm a user. A good rule of thumb is to keep alert text to a single line in a desktop-sized container, or limiting it to 90 characters.
Regardless of screen width, the optimal line length is still 45–90 characters. As you test your layout, make sure that text elements stay within this range.
Compose an alert with:
Place an alert where it makes the most contextual sense. Don't cover other UI elements with an alert.
In general, the persistence and behavior on scroll of an alert should match the element it's scoped to. For example, if an alert is scoped to a navigation bar that is sticky on scroll and persists across several pages, the alert should similarly be sticky and persist across several pages. However, don't persist the alert across too many pages in a user session since it may lose its interruptive intent.
Use only 1 alert per page. Use 2 alerts only if absolutely necessary and if the alerts are placed in different containers.
Don't use more than 2 alerts per page.
Please fill in the details below...
Place global alerts at the top of the page. Place all other alerts at the top of the container it relates to beneath the heading.
Don't cover other UI elements with an alert.
Use anchors to link to more information that may be helpful for users to resolve or clarify an alert message.
Avoid using buttons in alerts unless it triggers an action.
Be cautious about using alerts since they can be stressful for users to see.
Don't use alerts to communicate every change in a product (e.g., marketing messages, trial status) so that important messaging isn't diluted.
| Property | Default token | Modifiable? |
|---|---|---|
| background-color |
| No |
| border-color |
| No |
| border-radius | border-radius-0 | No |
| border-width | Bottom border: border-width-20 | No |
| icon color |
| No |
| icon size |
| No |
| spacing |
| No |
yarn add @twilio-paste/alert - or - yarn add @twilio-paste/coreimport {Alert} from '@twilio-paste/alert';const Component = () => ( <Alert variant="error"> <Text>There is an error in the system.</Text> </Alert>);| Prop | Type | Description | Default |
|---|---|---|---|
| children? | ReactNode | null | |
| onDismiss? | () => void | Create dismissable alerts by providing an onDismiss callback | null |
| role? | string | Provide a specific ARIA role to the alert that overrides the calculated one set by the component | null |
| variant? | string | error / neutral / warning | null |