Skip to content

Commit

Permalink
[Snackbar] Improve accessibility (mui#19043)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored and m4theushw committed Jan 6, 2020
1 parent 8a0ddb9 commit 34ab259
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 81 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api/snackbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
|:-----|:-----|:--------|:------------|
| <span class="prop-name">action</span> | <span class="prop-type">node</span> | | The action to display. It renders after the message, at the end of the snackbar. |
| <span class="prop-name">anchorOrigin</span> | <span class="prop-type">{ horizontal: 'left'<br>&#124;&nbsp;'center'<br>&#124;&nbsp;'right', vertical: 'top'<br>&#124;&nbsp;'bottom' }</span> | <span class="prop-default">{ vertical: 'bottom', horizontal: 'center' }</span> | The anchor of the `Snackbar`. |
| <span class="prop-name">autoHideDuration</span> | <span class="prop-type">number</span> | | The number of milliseconds to wait before automatically calling the `onClose` function. `onClose` should then set the state of the `open` prop to hide the Snackbar. This behavior is disabled by default with the `null` value. |
| <span class="prop-name">autoHideDuration</span> | <span class="prop-type">number</span> | <span class="prop-default">null</span> | The number of milliseconds to wait before automatically calling the `onClose` function. `onClose` should then set the state of the `open` prop to hide the Snackbar. This behavior is disabled by default with the `null` value. |
| <span class="prop-name">children</span> | <span class="prop-type">element</span> | | Replace the `SnackbarContent` component. |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">ClickAwayListenerProps</span> | <span class="prop-type">object</span> | | Props applied to the `ClickAwayListener` element. |
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/ConsecutiveSnackbars.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ export default function ConsecutiveSnackbars() {
autoHideDuration={6000}
onClose={handleClose}
onExited={handleExited}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">{messageInfo ? messageInfo.message : undefined}</span>}
message={messageInfo ? messageInfo.message : undefined}
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/ConsecutiveSnackbars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ export default function ConsecutiveSnackbars() {
autoHideDuration={6000}
onClose={handleClose}
onExited={handleExited}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">{messageInfo ? messageInfo.message : undefined}</span>}
message={messageInfo ? messageInfo.message : undefined}
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/DirectionSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export default function DirectionSnackbar() {
open={open}
onClose={handleClose}
TransitionComponent={transition}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/DirectionSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default function DirectionSnackbar() {
open={open}
onClose={handleClose}
TransitionComponent={transition}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
7 changes: 2 additions & 5 deletions docs/src/pages/components/snackbars/FabIntegrationSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,8 @@ export default function FabIntegrationSnackbar() {
</Fab>
<Snackbar
open
autoHideDuration={4000}
ContentProps={{
'aria-describedby': 'snackbar-fab-message-id',
}}
message={<span id="snackbar-fab-message-id">Archived</span>}
autoHideDuration={6000}
message="Archived"
action={
<Button color="inherit" size="small">
Undo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ export default function FabIntegrationSnackbar() {
</Fab>
<Snackbar
open
autoHideDuration={4000}
ContentProps={{
'aria-describedby': 'snackbar-fab-message-id',
}}
message={<span id="snackbar-fab-message-id">Archived</span>}
autoHideDuration={6000}
message="Archived"
action={
<Button color="inherit" size="small">
Undo
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/PositionedSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ export default function PositionedSnackbar() {
key={`${vertical},${horizontal}`}
open={open}
onClose={handleClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/PositionedSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ export default function PositionedSnackbar() {
key={`${vertical},${horizontal}`}
open={open}
onClose={handleClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/SimpleSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export default function SimpleSnackbar() {
open={open}
autoHideDuration={6000}
onClose={handleClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">Note archived</span>}
message="Note archived"
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/SimpleSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ export default function SimpleSnackbar() {
open={open}
autoHideDuration={6000}
onClose={handleClose}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">Note archived</span>}
message="Note archived"
action={
<React.Fragment>
<Button color="secondary" size="small" onClick={handleClose}>
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/TransitionsSnackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ export default function TransitionsSnackbar() {
open={state.open}
onClose={handleClose}
TransitionComponent={state.Transition}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/snackbars/TransitionsSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ export default function TransitionsSnackbar() {
open={state.open}
onClose={handleClose}
TransitionComponent={state.Transition}
ContentProps={{
'aria-describedby': 'message-id',
}}
message={<span id="message-id">I love snacks</span>}
message="I love snacks"
/>
</div>
);
Expand Down
27 changes: 2 additions & 25 deletions docs/src/pages/components/snackbars/snackbars.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ When multiple snackbar updates are necessary, they should appear one at a time.

Snackbars should appear above FABs (on mobile).

{{"demo": "pages/components/snackbars/FabIntegrationSnackbar.js", "iframe": true, "maxWidth": 500}}
{{"demo": "pages/components/snackbars/FabIntegrationSnackbar.js", "iframe": true, "maxWidth": 400}}

### Change Transition

Expand Down Expand Up @@ -86,27 +86,4 @@ It also enables you to **stack** them on top of one another (although this is di

(WAI-ARIA: https://www.w3.org/TR/wai-aria-1.1/#alert)

- Since alerts are not required to receive focus, content authors should not require users to close a Snackbar if the role is set to `alert` through the SnackbarContent `role` prop. This is the default role.
- If a Snackbar requires focus to close it, then content authors should use the `role` of `alertdialog`.

```jsx
<SnackbarContent
message="This is a Snackbar message."
role="alert"
/>
```

```jsx
<Snackbar
ContentProps={{
'aria-describedby': 'snackbar-fab-message-id',
'role': 'alertdialog',
}}
message={<span id="snackbar-fab-message-id">Archived</span>}
action={
<Button color="inherit" size="small">
Undo
</Button>
}
/>
```
- By default, the snackbar won't auto-hide. However, if you decide to use the `autoHideDuration` prop, it's recommended to give the user [sufficient time](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits.html) to respond.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ function Snackbar(props) {
return (
<MuiSnackbar
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
autoHideDuration={6e3}
autoHideDuration={6000}
transition={Transition}
ContentProps={{
'aria-describedby': 'snackbar',
classes: {
root: classes.content,
message: classes.contentMessage,
Expand All @@ -59,7 +58,7 @@ function Snackbar(props) {
message={
<React.Fragment>
<InfoIcon className={classes.info} />
<span id="snackbar">{message}</span>
<span>{message}</span>
</React.Fragment>
}
action={[
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Snackbar/Snackbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const Snackbar = React.forwardRef(function Snackbar(props, ref) {
const {
action,
anchorOrigin: { vertical, horizontal } = { vertical: 'bottom', horizontal: 'center' },
autoHideDuration,
autoHideDuration = null,
children,
classes,
className,
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/test/typescript/components.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ const SnackbarTest = () => (
horizontal: 'left',
}}
open={true}
autoHideDuration={6e3}
autoHideDuration={6000}
onClose={e => log(e)}
ContentProps={
{
Expand Down

0 comments on commit 34ab259

Please sign in to comment.