Skip to content
PatternFly logo

Alert group

An alert group stacks and positions 2 or more alerts in a live region, either in a layer over the main content of a page or inline with the page content. Alert groups should always rank alerts by age, stacking new alerts on top of old ones as they surface.

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 groups

Click the buttons in the example below to add dynamic alerts to a group.

    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

      The main alert component.
      *required
      NameTypeDefaultDescription
      titlerequiredReact.ReactNodeTitle of the alert.
      actionCloseReact.ReactNodeClose button; use the alert action close button component.
      actionLinksReact.ReactNodeAction links; use a single alert action link component or multiple wrapped in an array or React.Fragment.
      aria-labelstring`${capitalize(variant)} Alert`Adds accessible text to the alert.
      childrenReact.ReactNode''Content rendered inside the alert.
      classNamestring''Additional classes to add to the alert.
      componentunknown'h4'Sets the element to use as the alert title. Default is h4.
      customIconReact.ReactNodeSet a custom icon to the alert. If not set the icon is set according to the variant.
      idstringUniquely identifies the alert.
      isExpandablebooleanfalseFlag indicating that the alert is expandable.
      isInlinebooleanfalseFlag to indicate if the alert is inline.
      isLiveRegionbooleanfalseFlag to indicate if the alert is in a live region.
      isPlainbooleanfalseFlag to indicate if the alert is plain.
      onMouseEnterNo type info() => {}
      onMouseLeaveNo type info() => {}
      onTimeout() => void() => {}Function to be executed on alert timeout. Relevant when the timeout prop is set.
      ouiaIdnumber | stringValue to overwrite the randomly generated data-ouia-component-id.
      ouiaSafebooleantrueSet 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.
      timeoutnumber | booleanfalseIf set to true, the timeout is 8000 milliseconds. If a number is provided, alert will be dismissed after that amount of time in milliseconds.
      timeoutAnimationnumber3000If 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.
      toggleAriaLabelstring`${capitalize(variant)} alert details`Adds accessible text to the alert toggle.
      tooltipPositionTooltipPosition | '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.
      truncateTitlenumber0Truncate title to number of lines.
      variant'success' | 'danger' | 'warning' | 'info' | 'default'AlertVariant.defaultAdds alert variant styles.
      variantLabelstring`${capitalize(variant)} alert:`Variant label text for screen readers.

      AlertGroup

      *required
      NameTypeDefaultDescription
      appendToHTMLElement | (() => HTMLElement)Determine where the alert is appended to
      childrenReact.ReactNodeAlerts to be rendered in the AlertGroup
      classNamestringAdditional classes added to the AlertGroup
      isLiveRegionbooleanTurns 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.
      isToastbooleanToast notifications are positioned at the top right corner of the viewport
      onOverflowClick() => voidFunction to call if user clicks on overflow message
      overflowMessagestringCustom text to show for the overflow message

      AlertActionCloseButton

      Renders a close button for a dismissable alert when this sub-component is passed into the alert's actionClose property.
      *required
      NameTypeDefaultDescription
      aria-labelstring''Accessible label for the close button
      classNamestringAdditional classes added to the alert action close button.
      onClose() => void() => undefined as anyA callback for when the close button is clicked.
      variantLabelstringVariant Label for the close button.
      Renders buttons styled as links beneath the alert title and description when this sub-component is passed into the alert's actionLinks property.
      *required
      NameTypeDefaultDescription
      childrenstringContent rendered inside the alert action link.
      classNamestring''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