Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snackbar] Improve accessibility #19043

Merged
merged 5 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. |
| <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={[
<Button key="undo" color="secondary" size="small" onClick={handleClose}>
UNDO
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={[
<Button key="undo" color="secondary" size="small" onClick={handleClose}>
UNDO
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 @@ -38,10 +38,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={[
<Button key="undo" color="secondary" size="small" onClick={handleClose}>
UNDO
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 @@ -40,10 +40,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={[
<Button key="undo" color="secondary" size="small" onClick={handleClose}>
UNDO
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
21 changes: 7 additions & 14 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,20 @@ 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`.
- By default, the toast won't auto-hide. However, if you decide to use the `autoHideDuration` prop, it's recommended giving users [enough time](https://www.w3.org/TR/UNDERSTANDING-WCAG20/time-limits.html).
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
- Since alerts are not required to receive focus, content authors should not require users to close a Snackbar if the role is set to `role="alert"` through the SnackbarContent. This is the default role.
- If a Snackbar requires focus to close it, then content authors should use `role= "alertdialog"`.
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved

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

```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>
}
message="Archived"
action={<Button color="inherit" size="small">Undo</Button>}
/>
```
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