From 92e8900804bfe971f55a2ce54ad78c8b93f10632 Mon Sep 17 00:00:00 2001 From: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> Date: Mon, 7 Nov 2022 15:20:48 +0000 Subject: [PATCH] [docs] Revise and expand Joy UI "Alert" page (#34838) --- docs/data/joy/components/alert/AlertBasic.js | 11 ++++ docs/data/joy/components/alert/AlertBasic.tsx | 11 ++++ .../components/alert/AlertBasic.tsx.preview | 1 + docs/data/joy/components/alert/AlertColors.js | 2 +- .../data/joy/components/alert/AlertColors.tsx | 2 +- docs/data/joy/components/alert/AlertSizes.js | 6 +- docs/data/joy/components/alert/AlertSizes.tsx | 6 +- .../components/alert/AlertSizes.tsx.preview | 6 +- docs/data/joy/components/alert/AlertUsage.js | 2 +- .../joy/components/alert/AlertVariants.js | 8 +-- .../joy/components/alert/AlertVariants.tsx | 8 +-- .../alert/AlertVariants.tsx.preview | 8 +-- .../components/alert/AlertVariousStates.js | 2 +- .../components/alert/AlertVariousStates.tsx | 2 +- docs/data/joy/components/alert/alert.md | 66 +++++++++++++++---- 15 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 docs/data/joy/components/alert/AlertBasic.js create mode 100644 docs/data/joy/components/alert/AlertBasic.tsx create mode 100644 docs/data/joy/components/alert/AlertBasic.tsx.preview diff --git a/docs/data/joy/components/alert/AlertBasic.js b/docs/data/joy/components/alert/AlertBasic.js new file mode 100644 index 00000000000000..4ea4240f63481c --- /dev/null +++ b/docs/data/joy/components/alert/AlertBasic.js @@ -0,0 +1,11 @@ +import * as React from 'react'; +import Box from '@mui/joy/Box'; +import Alert from '@mui/joy/Alert'; + +export default function AlertBasic() { + return ( + + This is a basic Alert. + + ); +} diff --git a/docs/data/joy/components/alert/AlertBasic.tsx b/docs/data/joy/components/alert/AlertBasic.tsx new file mode 100644 index 00000000000000..4ea4240f63481c --- /dev/null +++ b/docs/data/joy/components/alert/AlertBasic.tsx @@ -0,0 +1,11 @@ +import * as React from 'react'; +import Box from '@mui/joy/Box'; +import Alert from '@mui/joy/Alert'; + +export default function AlertBasic() { + return ( + + This is a basic Alert. + + ); +} diff --git a/docs/data/joy/components/alert/AlertBasic.tsx.preview b/docs/data/joy/components/alert/AlertBasic.tsx.preview new file mode 100644 index 00000000000000..1bb53c2f4d77ea --- /dev/null +++ b/docs/data/joy/components/alert/AlertBasic.tsx.preview @@ -0,0 +1 @@ +This is a basic Alert. \ No newline at end of file diff --git a/docs/data/joy/components/alert/AlertColors.js b/docs/data/joy/components/alert/AlertColors.js index 597a6ef3ed1749..42d37cc6db85a7 100644 --- a/docs/data/joy/components/alert/AlertColors.js +++ b/docs/data/joy/components/alert/AlertColors.js @@ -20,7 +20,7 @@ export default function AlertColors() { diff --git a/docs/data/joy/components/alert/AlertColors.tsx b/docs/data/joy/components/alert/AlertColors.tsx index 98e4904edd9d9c..6faf248a6b43ec 100644 --- a/docs/data/joy/components/alert/AlertColors.tsx +++ b/docs/data/joy/components/alert/AlertColors.tsx @@ -20,7 +20,7 @@ export default function AlertColors() { diff --git a/docs/data/joy/components/alert/AlertSizes.js b/docs/data/joy/components/alert/AlertSizes.js index 6b9f35c2d85b5e..210d40b142d697 100644 --- a/docs/data/joy/components/alert/AlertSizes.js +++ b/docs/data/joy/components/alert/AlertSizes.js @@ -5,9 +5,9 @@ import Alert from '@mui/joy/Alert'; export default function AlertSizes() { return ( - This is an alert in the small size. - This is an alert in the medium size. - This is an alert in the large size. + This is a small Alert. + This is a medium Alert. + This is a large Alert. ); } diff --git a/docs/data/joy/components/alert/AlertSizes.tsx b/docs/data/joy/components/alert/AlertSizes.tsx index 6b9f35c2d85b5e..210d40b142d697 100644 --- a/docs/data/joy/components/alert/AlertSizes.tsx +++ b/docs/data/joy/components/alert/AlertSizes.tsx @@ -5,9 +5,9 @@ import Alert from '@mui/joy/Alert'; export default function AlertSizes() { return ( - This is an alert in the small size. - This is an alert in the medium size. - This is an alert in the large size. + This is a small Alert. + This is a medium Alert. + This is a large Alert. ); } diff --git a/docs/data/joy/components/alert/AlertSizes.tsx.preview b/docs/data/joy/components/alert/AlertSizes.tsx.preview index 662704300e2d2b..696477eedb8407 100644 --- a/docs/data/joy/components/alert/AlertSizes.tsx.preview +++ b/docs/data/joy/components/alert/AlertSizes.tsx.preview @@ -1,3 +1,3 @@ -This is an alert in the small size. -This is an alert in the medium size. -This is an alert in the large size. \ No newline at end of file +This is a small Alert. +This is a medium Alert. +This is a large Alert. \ No newline at end of file diff --git a/docs/data/joy/components/alert/AlertUsage.js b/docs/data/joy/components/alert/AlertUsage.js index ecbcd1f2d4b938..eec905401c9bfa 100644 --- a/docs/data/joy/components/alert/AlertUsage.js +++ b/docs/data/joy/components/alert/AlertUsage.js @@ -26,7 +26,7 @@ export default function AlertUsage() { }, ]} renderDemo={(props) => ( - This is a Joy UI alert — check it out! + This is a Joy UI Alert — check it out! )} /> ); diff --git a/docs/data/joy/components/alert/AlertVariants.js b/docs/data/joy/components/alert/AlertVariants.js index 3a9b0d9b3f8059..4066da65b64af9 100644 --- a/docs/data/joy/components/alert/AlertVariants.js +++ b/docs/data/joy/components/alert/AlertVariants.js @@ -5,10 +5,10 @@ import Alert from '@mui/joy/Alert'; export default function AlertVariants() { return ( - This is an alert using the solid variant. - This is an alert using the soft variant. - This is an alert using the outlined variant. - This is an alert using the plain variant. + This is an Alert using the solid variant. + This is an Alert using the soft variant. + This is an Alert using the outlined variant. + This is an Alert using the plain variant. ); } diff --git a/docs/data/joy/components/alert/AlertVariants.tsx b/docs/data/joy/components/alert/AlertVariants.tsx index 3a9b0d9b3f8059..4066da65b64af9 100644 --- a/docs/data/joy/components/alert/AlertVariants.tsx +++ b/docs/data/joy/components/alert/AlertVariants.tsx @@ -5,10 +5,10 @@ import Alert from '@mui/joy/Alert'; export default function AlertVariants() { return ( - This is an alert using the solid variant. - This is an alert using the soft variant. - This is an alert using the outlined variant. - This is an alert using the plain variant. + This is an Alert using the solid variant. + This is an Alert using the soft variant. + This is an Alert using the outlined variant. + This is an Alert using the plain variant. ); } diff --git a/docs/data/joy/components/alert/AlertVariants.tsx.preview b/docs/data/joy/components/alert/AlertVariants.tsx.preview index ca9c0114aead70..c4e9b08796ce03 100644 --- a/docs/data/joy/components/alert/AlertVariants.tsx.preview +++ b/docs/data/joy/components/alert/AlertVariants.tsx.preview @@ -1,4 +1,4 @@ -This is an alert using the solid variant. -This is an alert using the soft variant. -This is an alert using the outlined variant. -This is an alert using the plain variant. \ No newline at end of file +This is an Alert using the solid variant. +This is an Alert using the soft variant. +This is an Alert using the outlined variant. +This is an Alert using the plain variant. \ No newline at end of file diff --git a/docs/data/joy/components/alert/AlertVariousStates.js b/docs/data/joy/components/alert/AlertVariousStates.js index 02b4db7ed1e9b6..126bb23397392b 100644 --- a/docs/data/joy/components/alert/AlertVariousStates.js +++ b/docs/data/joy/components/alert/AlertVariousStates.js @@ -40,7 +40,7 @@ export default function AlertVariousStates() { {title} - This is a {title} message. + This is a time-sensitive {title} Alert. diff --git a/docs/data/joy/components/alert/AlertVariousStates.tsx b/docs/data/joy/components/alert/AlertVariousStates.tsx index deb0ce499cc74f..0a7e1dce4949ed 100644 --- a/docs/data/joy/components/alert/AlertVariousStates.tsx +++ b/docs/data/joy/components/alert/AlertVariousStates.tsx @@ -44,7 +44,7 @@ export default function AlertVariousStates() { {title} - This is a {title} message. + This is a time-sensitive {title} Alert. diff --git a/docs/data/joy/components/alert/alert.md b/docs/data/joy/components/alert/alert.md index b15c32df0ebbe0..333f6ac7416dcf 100644 --- a/docs/data/joy/components/alert/alert.md +++ b/docs/data/joy/components/alert/alert.md @@ -7,15 +7,22 @@ waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/alert/ # Alert -

An alert displays a short, important message in a way that attracts the user's attention without interrupting the user's task.

+

Alerts display brief messages for the user without interrupting their use of the app.

## Introduction +The Alert component can be used to provide important and potentially time-sensitive information in a way that does not interfere with the user's tasks. (Source: [ARIA APG](https://www.w3.org/WAI/ARIA/apg/patterns/alert/).) + +:::warning +Alerts should not be confused with alert _dialogs_ ([ARIA](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/)), which _are_ intended to interrupt the user to obtain a response. +Use the Joy UI [Modal](https://mui.com/joy-ui/react-modal/) if you need the behavior of a dialog. +::: + {{"demo": "AlertUsage.js", "hideToolbar": true}} {{"component": "modules/components/ComponentLinkHeader.js", "design": false}} -## Component +## Usage After [installation](/joy-ui/getting-started/installation/), you can start building with this component using the following basic elements: @@ -27,28 +34,60 @@ export default function MyApp() { } ``` +## Basics + +The Alert component wraps around its content, and stretches to fill its enclosing container, as shown below: + +{{"demo": "AlertBasic.js"}} + +## Anatomy + +The Alert component is composed of a single root `
` element with its `role` set to `alert`: + +```html + +``` + +### Overriding the root slot + +Use the `component` prop to override the root slot with a custom element. +For example, the following code snippet replaces the default `
` with a ``: + +```jsx +Alert content + +// renders as: + + Alert content + +``` + +## Customization + ### Variants -The alert component supports the four global variants: `solid` (default), `soft`, `outlined` and `plain`. +The Alert component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `soft` (default), `solid`, `outlined`, and `plain`. {{"demo": "AlertVariants.js"}} ### Colors Every palette included in the theme is available via the `color` prop. -Play around combining different colors with different variants. +The demo below shows how the values for the `color` prop are affected by the global variants: {{"demo": "AlertColors.js"}} ### Sizes -The alert components comes with three sizes out of the box: `sm`, `md` (the default), and `lg`. +The Alert component comes with three sizes out of the box: `sm`, `md` (the default), and `lg`: {{"demo": "AlertSizes.js"}} ### Decorators -Use the `startDecorator` and/or `endDecorator` props to insert actionable buttons or icon buttons on the Alert. +Use the `startDecorator` and `endDecorator` props to append actions and icons to either side of the Alert: {{"demo": "AlertWithDecorators.js"}} @@ -64,12 +103,11 @@ Use the `startDecorator` and/or `endDecorator` props to insert actionable button ## Accessibility -Here are a few tips to make sure you have an accessible alert component: - -- When the component is dynamically displayed, the content is automatically announced by most screen readers. - At this time, screen readers do not inform users of alerts that are present when the page loads. - -- Using color to add meaning only provides a visual indication, which will not be conveyed to users of assistive technologies such as screen readers. - Ensure that information denoted by the color is either obvious from the content itself (for example the visible text), or is included through alternative means, such as additional hidden text. +Here are some factors to consider to ensure that your Alert is accessible: -- Actions must have a tab index of 0 so that they can be reached by keyboard-only users. +- Because alerts are not intended to interfere with the use of the app, your Alert component should _never_ affect the keyboard focus. +- If an alert contains an action, that action must have a `tabindex` of `0` so it can be reached by keyboard-only users. +- Essential alerts should not disappear automatically—[timed interactions](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits-no-exceptions.html) can make your app inaccessible to users who need extra time to understand or locate the alert. +- Alerts that occur too frequently can [inhibit the usability](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits-postponed.html) of your app. +- Dynamically rendered alerts are announced by screen readers; alerts that are already present on the page when it loads are _not_ announced. +- Color does not add meaning to the UI for users who require assistive technology. You must ensure that any information conveyed through color is also denoted in other ways, such as within the text of the alert itself, or with additional hidden text that's read by screen readers.