Skip to content

Commit

Permalink
fixup! fixup! Feat(web): Introduce the Toast component #DS-1112
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkudrna committed Feb 27, 2024
1 parent f7a1f87 commit 4a8b0f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions packages/web/src/scss/components/Toast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Toast is a composition of a few subcomponents:

## Toast

The Toast component is a container for the ToastBar component. It is responsible for positioning the
[ToastBar](#toastbar) component, even when there are [multiple of them](#toast-queue).
The Toast component is a container responsible for positioning the [ToastBar](#toastbar) component. It is capable of
handling even multiple toast messages at once, stacking them in a [queue](#toast-queue).

```html
<div class="Toast" aria-live="polite">
<div class="Toast" role="log">
<div class="Toast__queue">
<!-- ToastBar components go here -->
</div>
Expand All @@ -22,13 +22,14 @@ The Toast component is a container for the ToastBar component. It is responsible

### Accessibility

The wrapping Toast container has the [`aria-live="polite"`][mdn-aria-live] attribute set, which will announce any
**dynamic changes** inside the container as they happen. In order for this to work, the Toast component **must be
present in the DOM** on the initial page load, even when empty.
The wrapping Toast container has the [`role="log"`][mdn-role-log] attribute set (which results in an implicit
[`aria-live`][mdn-aria-live] value of `polite`). Assistive technologies then announce any **dynamic changes** inside the
container as they happen. In order for this to work, the Toast component **must be present in the DOM** on the initial
page load, even when empty.

👉 Unless you are absolutely sure that your toast messages are critical to interrupt the user, you should keep the
`polite` value of the `aria-live` attribute. When set to `assertive`, assistive technologies immediately notify the
user, potentially clearing the speech queue of previous updates.
👉 Unless you are absolutely sure that your toast messages are critical to interrupt the user, you should not change the
(implicit) `polite` value of the [`aria-live`][mdn-aria-live] attribute. When set to `assertive`, assistive technologies
immediately notify the user, potentially clearing the speech queue of previous updates.

### Alignment

Expand Down Expand Up @@ -56,7 +57,7 @@ middle of the screen.
Example:

```html
<div class="Toast Toast--bottom Toast--right" aria-live="polite">
<div class="Toast Toast--bottom Toast--right" role="log">
<div class="Toast__queue">
<!-- ToastBar components go here -->
</div>
Expand All @@ -72,7 +73,7 @@ modifiers to change the alignment of the Toast component starting on a specific
Example:

```html
<div class="Toast Toast--bottom Toast--center Toast--tablet--right" aria-live="polite">
<div class="Toast Toast--bottom Toast--center Toast--tablet--right" role="log">
<div class="Toast__queue">
<!-- ToastBar components go here -->
</div>
Expand Down Expand Up @@ -158,6 +159,10 @@ An action link can be added to the ToastBar component:
</div>
```

👉 **Do not put any important actions** like "Undo" in the ToastBar component (unless there are other means to perform
said action), as it is very hard (if not impossible) to reach for users with assistive technologies. Read more about
[Toast accessibility](#scott-o-hara-toast) at Scott O'Hara's blog.

### Colors

The ToastBar component is available in all [emotion colors][dictionary-color], plus the `inverted` variant (default).
Expand Down Expand Up @@ -203,7 +208,7 @@ To make the ToastBar dismissible, add the `ToastBar--dismissible` modifier class

```html
<!-- Toast: start -->
<div class="Toast Toast--bottom Toast--center" aria-live="polite">
<div class="Toast Toast--bottom Toast--center" role="log">
<div class="Toast__queue">
<!-- ToastBar: start -->
<div id="my-dismissible-toast" class="ToastBar ToastBar--inverted ToastBar--dismissible">
Expand Down Expand Up @@ -235,6 +240,8 @@ To make the ToastBar dismissible, add the `ToastBar--dismissible` modifier class
<!-- Toast: end -->
```

[mdn-role-log]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/log_role
[mdn-aria-live]: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-live
[dictionary-alignment]: https://github.com/lmc-eu/spirit-design-system/blob/main/docs/DICTIONARIES.md#alignment
[dictionary-color]: https://github.com/lmc-eu/spirit-design-system/blob/main/docs/DICTIONARIES.md#color
[scott-o-hara-toast]: https://www.scottohara.me/blog/2019/07/08/a-toast-to-a11y-toasts.html
2 changes: 1 addition & 1 deletion packages/web/src/scss/components/Toast/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ <h2 class="docs-Heading">Alignment</h2>
</form>
<!-- Toast and visual keyboard demo: end -->

<div id="toast-example" class="Toast Toast--bottom Toast--center" aria-live="polite">
<div id="toast-example" class="Toast Toast--bottom Toast--center" role="log">
<div class="Toast__queue">

<div id="my-dismissible-toast" class="ToastBar ToastBar--success ToastBar--dismissible">
Expand Down

0 comments on commit 4a8b0f3

Please sign in to comment.