Success alert description. This should tell the user more information about the alert.{' '}
This is a link.
@@ -80,21 +86,18 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
alert('Clicked the close button')} />}
- actionLinks={
-
- alert('Clicked on View details')}>View details
- alert('Clicked on Ignore')}>Ignore
-
- }
- />
- alert('Clicked the close button')} />} />
+ // eslint-disable-next-line no-console
+ actionClose={ console.log('Clicked the close button')} />}
+ >
+
Short alert description.
+
-
-
Short alert description
+
+
Short alert description.
-
+;
```
+
### Alert timeout
Use the `timeout` property to automatically dismiss an alert after a period of time. If set to `true`, the `timeout` will be 8000 milliseconds. Provide a specific value to dismiss the alert after a different number of milliseconds.
@@ -105,29 +108,46 @@ import { Alert, AlertActionLink, AlertGroup, Button } from '@patternfly/react-co
const AlertTimeout: React.FunctionComponent = () => {
const [alerts, setAlerts] = React.useState([]);
+ const [newAlertKey, setNewAlertKey] = React.useState(0);
+
const onClick = () => {
const timeout = 8000;
- setAlerts(prevAlerts => {
- return [...prevAlerts,
-
- View details
- Ignore
-
- }>
+ setNewAlertKey((key) => key + 1);
+ setAlerts((prevAlerts) => {
+ return [
+ ...prevAlerts,
+
+
+ View details
+
+ console.log('Clicked on Ignore')}
+ >
+ Ignore
+
+
+ }
+ key={newAlertKey}
+ >
This alert will dismiss after {`${timeout / 1000} seconds`}
- ]
+ ];
});
- }
+ };
return (
-
-
-
- {alerts}
-
+
+
+ {alerts}
);
};
@@ -137,7 +157,7 @@ const AlertTimeout: React.FunctionComponent = () => {
An alert can contain additional, hidden information that is made visible when users click a caret icon. This information can be expanded and collapsed each time the icon is clicked.
-It is not recommended to use an expandable alert with a `timeout` in a [toast alert group](/components/alert#toast-alert-group) because the alert could timeout before users have time to interact with and view the entire alert.
+It is not recommended to use an expandable alert with a `timeout` in a [toast alert group](/components/alert#toast-alert-group) because the alert could timeout before users have time to interact with and view the entire alert.
See the [toast alert considerations](/components/alert/accessibility#toast-alerts) section of the alert accessibility documentation to understand the accessibility risks associated with using toast alerts.
@@ -150,13 +170,8 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
isExpandable
variant="success"
title="Success alert title"
- actionClose={ alert('Clicked the close button')} />}
- actionLinks={
-
- alert('Clicked on View details')}>View details
- alert('Clicked on Ignore')}>Ignore
-
- }
+ // eslint-disable-next-line no-console
+ actionClose={ console.log('Clicked the close button')} />}
>
Success alert description. This should tell the user more information about the alert.
@@ -165,17 +180,22 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
isInline
variant="success"
title="Success alert title"
- actionClose={ alert('Clicked the close button')} />}
actionLinks={
- alert('Clicked on View details')}>View details
- alert('Clicked on Ignore')}>Ignore
+
+ View details
+
+ console.log('Clicked on Ignore')}
+ >
+ Ignore
+
- }
+ }
>
Success alert description. This should tell the user more information about the alert.
-
+;
```
### Truncated alerts
@@ -187,16 +207,28 @@ import React from 'react';
import { Alert } from '@patternfly/react-core';
-
-
+
-
+
-
+ `}
+ />
+;
```
### Custom icons
@@ -218,7 +250,7 @@ import LaptopIcon from '@patternfly/react-icons/dist/esm/icons/laptop-icon';
} variant="success" title="Success alert title" />
} variant="warning" title="Warning alert title" />
} variant="danger" title="Danger alert title" />
-
+;
```
### Inline alerts variants
@@ -234,8 +266,9 @@ import { Alert } from '@patternfly/react-core';
-
+;
```
+
### Inline alert variations
All general alert variations can use the `isInline` property to apply inline styling.
@@ -248,17 +281,22 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
isInline
variant="success"
title="Success alert title"
- actionClose={ alert('Clicked the close button')} />}
actionLinks={
- alert('Clicked on View details')}>View details
- alert('Clicked on Ignore')}>Ignore
+
+ View details
+
+ console.log('Clicked on Ignore')}
+ >
+ Ignore
+
}
>
Success alert description. This should tell the user more information about the alert.
- alert('Clicked the close button')} />}>
+
Success alert description. This should tell the user more information about the alert.{' '}
This is a link.
@@ -268,22 +306,16 @@ import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/reac
isInline
variant="success"
title="Success alert title"
- actionClose={ alert('Clicked the close button')} />}
- actionLinks={
-
- alert('Clicked on View details')}>View details
- alert('Clicked on Ignore')}>Ignore
-
- }
- />
- alert('Clicked the close button')} />}
- />
-
-
+ // eslint-disable-next-line no-console
+ actionClose={ console.log('Clicked the close button')} />}
+ >
+
Short alert description.
+
+
+
+
Short alert description.
+
+;
```
### Plain inline alert variants
@@ -299,7 +331,7 @@ import { Alert } from '@patternfly/react-core';
-
+;
```
### Plain inline alert variations
@@ -308,15 +340,10 @@ It is not recommended to use a plain inline alert with `actionClose` nor `action
```ts
import React from 'react';
-import { Alert, AlertActionCloseButton, AlertActionLink } from '@patternfly/react-core';
-
+import { Alert } from '@patternfly/react-core';
+
Success alert description. This should tell the user more information about the alert.
-
+;
```
### Static live region alerts
@@ -334,7 +361,8 @@ import { Alert, AlertActionCloseButton } from '@patternfly/react-core';
isLiveRegion
variant="info"
title="Default live region configuration"
- actionClose={ alert('Clicked the close button')} />}
+ // eslint-disable-next-line no-console
+ actionClose={ console.log('Clicked the close button')} />}
>
This alert uses the recommended isLiveRegion prop to automatically set ARIA attributes and CSS classes.
@@ -344,12 +372,13 @@ import { Alert, AlertActionCloseButton } from '@patternfly/react-core';
aria-atomic="true"
variant="info"
title="Customized live region"
- actionClose={ alert('Clicked the close button')} />}
+ // eslint-disable-next-line no-console
+ actionClose={ console.log('Clicked the close button')} />}
>
- You can alternatively omit the isLiveRegion prop to specify ARIA attributes and CSS manually on
- the containing element.
+ You can alternatively omit the isLiveRegion prop to specify ARIA attributes and CSS manually on the
+ containing element.
-
+;
```
### Dynamic live region alerts
@@ -357,19 +386,22 @@ import { Alert, AlertActionCloseButton } from '@patternfly/react-core';
Alerts that are asynchronously appended into dynamic [alert groups](/components/alert/#alert-group-examples) via the `isLiveRegion` property will be announced to assistive technology the moment the change happens, following the strategy used for `aria-atomic`, which defaults to false. This means only changes of type "addition" will be announced.
```ts file="AlertDynamicLiveRegion.tsx"
+
```
-### Asynchronous live region alerts
+### Asynchronous live region alerts
+
+This example shows how an alert could be triggered by an asynchronous event in the application. Note that you can customize how the alert will be announced to assistive technology. See the [alert accessibility](/components/alert/accessibility/) for more information.
-This example shows how an alert could be triggered by an asynchronous event in the application. Note that you can customize how the alert will be announced to assistive technology. See the [https://www.patternfly.org/v4/components/alert/accessibility](alert accessibility) for more information.
```ts file="AlertAsyncLiveRegion.tsx"
+
```
## Alert group examples
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.
-### Alert group variants
+### Alert group variants
Alert groups can be one of the following variants:
@@ -386,15 +418,17 @@ Dynamic alerts that are generated after the page initially loads must be appende
All alert group variants may combine multiple [alert variants](/components/alert) For example, the following static inline alert group includes one "success" alert and one "info" alert.
```ts file="./AlertGroupStatic.tsx"
+
```
### Toast alert group
-Toast alert groups are created by passing in the `isToast` and `isLiveRegion` properties.
+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.
```ts file="./AlertGroupToast.tsx"
+
```
### Toast alert group with overflow capture
@@ -403,11 +437,12 @@ Users will see an overflow message once a predefined number of alerts are displa
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.
+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.
+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.
```ts file="AlertGroupToastOverflowCapture.tsx"
+
```
### Asynchronous alert groups
@@ -417,6 +452,7 @@ The following example shows how alerts can be triggered by an asynchronous event
See the [alert accessibility tab](/components/alert/accessibility) for more information on customizing this behavior.
```ts file="./AlertGroupAsync.tsx"
+
```
### Dynamic alert groups
@@ -424,13 +460,15 @@ See the [alert accessibility tab](/components/alert/accessibility) for more info
Click the buttons in the example below to add dynamic alerts to a group.
```ts file="./AlertGroupSingularDynamic.tsx"
+
```
### Dynamic alert group with overflow message
-In the following example, there can be a maximum of 4 alerts shown at once.
+In the following example, there can be a maximum of 4 alerts shown at once.
```ts file="AlertGroupSingularDynamicOverflow.tsx"
+
```
### Multiple dynamic alert groups
@@ -438,4 +476,5 @@ In the following example, there can be a maximum of 4 alerts shown at once.
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.
```ts file="./AlertGroupMultipleDynamic.tsx"
+
```
diff --git a/packages/react-integration/demo-app-ts/src/components/demos/AlertGroupDemo/AlertGroupTimeoutFromBottomDemo.tsx b/packages/react-integration/demo-app-ts/src/components/demos/AlertGroupDemo/AlertGroupTimeoutFromBottomDemo.tsx
index 03210eb40c3..015ed51ea93 100644
--- a/packages/react-integration/demo-app-ts/src/components/demos/AlertGroupDemo/AlertGroupTimeoutFromBottomDemo.tsx
+++ b/packages/react-integration/demo-app-ts/src/components/demos/AlertGroupDemo/AlertGroupTimeoutFromBottomDemo.tsx
@@ -6,14 +6,20 @@ export const AlertGroupTimeoutFromBottomDemo: React.FunctionComponent = () => {
const [count, setCount] = React.useState(0);
const onClick = () => {
const timeout = 3000;
- setAlerts(prevAlerts => [
+ setAlerts((prevAlerts) => [
- View details
- Ignore
+
+ View details
+
+ console.log('Clicked on Ignore')}
+ >
+ Ignore
+
}
key={`Alert no. ${count}`}