Examples
Variants
Alert groups can be one of the following variants:
Variant | Description |
---|---|
Static inline | Static inline alert groups contain alerts that appear when the page loads, and are seen within the normal page content flow. These groups should not contain alerts that will dynamically appear or update. |
Toast | Toast alert groups contain alerts that typically appear in response to an asynchronous event or user action. These groups are positioned on top of other content at the top right of the page. |
Dynamic | Dynamic alert groups contain alerts that typically appear in response to a user action, and are seen within the normal page content flow. |
Dynamic alerts that are generated after the page initially loads must be appended to either a toast or dynamic AlertGroup
, both of which must use the isLiveRegion
property. New alerts appended to a toast or dynamic group will be announced by assistive technologies the moment the change happens. For information about customizing this announcement, read the aria-atomic and aria-relevant section of the alert group accessibility documentation.
Static inline alert group
All alert group variants may combine multiple alert variants For example, the following static inline alert group includes one "success" alert and one "info" alert.
Success alert:Success alert
Info alert:Info alert
Toast alert group
Toast alert groups are created by passing in the isToast
and isLiveRegion
properties.
Click the buttons in the example below to add alerts to a toast group.
Toast alert group with overflow capture
Users will see an overflow message once a predefined number of alerts are displayed. They will not see any alerts beyond the display limit, which must be explicitly set.
In the following example, an overflow message will appear when more than 4 alerts would be shown. When a 5th alert would appear, an overflow message is shown instead.
When an overflow message appears in an AlertGroup
using the isLiveRegion
property, the "view 1 more alert" text label will be announced, but the alert message will not.
Users navigating via keyboard or another assistive technology will need a way to navigate to and reveal hidden alerts before they disappear. Alternatively, there should be a place where notifications or alerts are collected to be viewed or read later.
Asynchronous alert groups
The following example shows how alerts can be triggered by an asynchronous event in the application. You can customize how an alert will be announced to assistive technology by adjusting the value of the aria-live
property. Click the "start async" alert button below and then click the buttons in the above toast examples to demonstrate how asynchronous events add alerts to a group. Click the "stop async alerts" button to halt this behavior.
See the alert group accessibility tab for more information on customizing this behavior.
Dynamic alert group with overflow message
In the following example, there can be a maximum of 4 alerts shown at once.
Multiple dynamic alert groups
You may add multiple alerts to an alert group at once. Click the "add alert collection" button in the example below to add a batch of 3 toast alerts to a group.
Props
Alert
Name | Type | Default | Description |
---|---|---|---|
titlerequired | React.ReactNode | Title of the alert. | |
actionClose | React.ReactNode | Close button; use the alert action close button component. | |
actionLinks | React.ReactNode | Action links; use a single alert action link component or multiple wrapped in an array or React.Fragment. | |
aria-label | string | `${capitalize(variant)} Alert` | Adds accessible text to the alert. |
children | React.ReactNode | '' | Content rendered inside the alert. |
className | string | '' | Additional classes to add to the alert. |
component | unknown | 'h4' | Sets the element to use as the alert title. Default is h4. |
customIcon | React.ReactNode | Set a custom icon to the alert. If not set the icon is set according to the variant. | |
id | string | Uniquely identifies the alert. | |
isExpandable | boolean | false | Flag indicating that the alert is expandable. |
isInline | boolean | false | Flag to indicate if the alert is inline. |
isLiveRegion | boolean | false | Flag to indicate if the alert is in a live region. |
isPlain | boolean | false | Flag to indicate if the alert is plain. |
onMouseEnter | No type info | () => {} | |
onMouseLeave | No type info | () => {} | |
onTimeout | () => void | () => {} | Function to be executed on alert timeout. Relevant when the timeout prop is set. |
ouiaId | number | string | Value to overwrite the randomly generated data-ouia-component-id. | |
ouiaSafe | boolean | true | Set the value of data-ouia-safe. Only set to true when the component is in a static state, i.e. no animations are occurring. At all other times, this value must be false. |
timeout | number | boolean | false | If set to true, the timeout is 8000 milliseconds. If a number is provided, alert will be dismissed after that amount of time in milliseconds. |
timeoutAnimation | number | 3000 | If the user hovers over the alert and `timeout` expires, this is how long to wait before finally dismissing the alert. |
Deprecated: titleHeadingLevel | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | Sets the heading level to use for the alert title. Default is h4. | |
toggleAriaLabel | string | `${capitalize(variant)} alert details` | Adds accessible text to the alert toggle. |
tooltipPosition | TooltipPosition | 'auto' | 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end' | 'right-start' | 'right-end' | Position of the tooltip which is displayed if text is truncated. | |
truncateTitle | number | 0 | Truncate title to number of lines. |
variant | 'success' | 'danger' | 'warning' | 'info' | 'default' | AlertVariant.default | Adds alert variant styles. |
variantLabel | string | `${capitalize(variant)} alert:` | Variant label text for screen readers. |
AlertGroup
Name | Type | Default | Description |
---|---|---|---|
appendTo | HTMLElement | (() => HTMLElement) | Determine where the alert is appended to | |
children | React.ReactNode | Alerts to be rendered in the AlertGroup | |
className | string | Additional classes added to the AlertGroup | |
isLiveRegion | boolean | Turns the container into a live region so that changes to content within the AlertGroup, such as appending an Alert, are reliably announced to assistive technology. | |
isToast | boolean | Toast notifications are positioned at the top right corner of the viewport | |
onOverflowClick | () => void | Function to call if user clicks on overflow message | |
overflowMessage | string | Custom text to show for the overflow message |
AlertActionCloseButton
Name | Type | Default | Description |
---|---|---|---|
aria-label | string | '' | Accessible label for the close button |
className | string | Additional classes added to the alert action close button. | |
onClose | () => void | () => undefined as any | A callback for when the close button is clicked. |
variantLabel | string | Variant Label for the close button. |
AlertActionLink
Name | Type | Default | Description |
---|---|---|---|
children | string | Content rendered inside the alert action link. | |
className | string | '' | Additional classes added to the alert action link. |
CSS variables
.pf-c-alert-group | --pf-c-alert-group__item--MarginTop | 0.5rem | ||
.pf-c-alert-group | --pf-c-alert-group--m-toast--Top | 3rem | ||
.pf-c-alert-group | --pf-c-alert-group--m-toast--Right | 2rem | ||
.pf-c-alert-group | --pf-c-alert-group--m-toast--MaxWidth | 37.5rem | ||
.pf-c-alert-group | --pf-c-alert-group--m-toast--ZIndex | 600 | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--BorderWidth | 0 | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--PaddingTop | 1.5rem | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--PaddingRight | 1rem | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--PaddingBottom | 1.5rem | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--PaddingLeft | 1rem | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--Color | #06c | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08) | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--BackgroundColor | #fff | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--hover--Color | #004080 | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--hover--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--focus--Color | #004080 | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--focus--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--active--Color | #004080 | ||
.pf-c-alert-group | --pf-c-alert-group__overflow-button--active--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
.pf-c-alert-group__overflow-button:hover | --pf-c-alert-group__overflow-button--Color | #004080 | ||
.pf-c-alert-group__overflow-button:hover | --pf-c-alert-group__overflow-button--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
.pf-c-alert-group__overflow-button:focus | --pf-c-alert-group__overflow-button--Color | #004080 | ||
.pf-c-alert-group__overflow-button:focus | --pf-c-alert-group__overflow-button--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
.pf-c-alert-group__overflow-button:active | --pf-c-alert-group__overflow-button--Color | #004080 | ||
.pf-c-alert-group__overflow-button:active | --pf-c-alert-group__overflow-button--BoxShadow | 0 0.5rem 1rem 0 rgba(3, 3, 3, 0.16), 0 0 0.375rem 0 rgba(3, 3, 3, 0.08), 0 0.75rem 0.75rem -0.5rem rgba(3, 3, 3, 0.18) | ||
View source on GitHub