From 220baef0d9f97b21748e51ec634d7171a267999b Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Wed, 19 Sep 2018 08:01:16 +0300 Subject: Clean up some docs for toasts - Add headings to examples section - Clarify styles and customization options in examples - Add dismiss buttons to all toasts - Missing period added for consistency - Update roles, tweak text --- site/docs/4.1/components/toasts.md | 138 ++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 57 deletions(-) diff --git a/site/docs/4.1/components/toasts.md b/site/docs/4.1/components/toasts.md index 553b79fbe4..6493cf520d 100644 --- a/site/docs/4.1/components/toasts.md +++ b/site/docs/4.1/components/toasts.md @@ -13,14 +13,16 @@ Toasts are lightweight notifications designed to mimic the push notifications th Things to know when using the toast plugin: - If you're building our JavaScript from source, it [requires `util.js`]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/javascript/#util). -- Toast are opt-in for performance reasons, so **you must initialize them yourself**. -- Toast will auto hide if you do not specify `autohide: false` - -Got all that? Great, let's see how they work with some examples. +- Toasts are opt-in for performance reasons, so **you must initialize them yourself**. +- Toasts will automatically hide if you do not specify `autohide: false`. ## Examples -A basic toast can include a header (though it doesn't strictly need one) with whatever contents you like. The header is also `display: flex`, so `.mr-auto` and `.ml-auto` can be used for easy pushing of content, as well as all our flexbox utilities. +### Basic + +To encourage extensible and predictable toasts, we recommend a header and body. Toast headers use `display: flex`, allowing easy alignment of content thanks to our margin and flexbox utilities. + +Toasts are as flexible as you need and have very little required markup. At a minimum, we require a single element to contain your "toasted" content and strongly encourage a dismiss button.
{% capture example %} @@ -41,7 +43,9 @@ A basic toast can include a header (though it doesn't strictly need one) with wh {% include example.html content=example %}
-They're slightly translucent, too, so they blend over whatever they might appear over. For browsers that support `backdrop-filter`, we'll also attempt to blur the elements under a toast. +### Translucent + +Toasts are slightly translucent, too, so they blend over whatever they might appear over. For browsers that support the `backdrop-filter` CSS property, we'll also attempt to blur the elements under a toast.
{% capture example %} @@ -62,7 +66,9 @@ They're slightly translucent, too, so they blend over whatever they might appear {% include example.html content=example %}
-Plus, they'll easily stack. +### Stacking + +When you have multiple toasts, we default to vertiaclly stacking them in a readable manner.
{% capture example %} @@ -71,6 +77,9 @@ Plus, they'll easily stack. Bootstrap just now +
See? Just like this. @@ -82,44 +91,12 @@ Plus, they'll easily stack. Bootstrap 2 seconds ago -
-
- Heads up, toasts will stack automatically -
- -{% endcapture %} -{% include example.html content=example %} - - -## Accessibility - -Toasts are intended to be small interruptions to your visitors or users, so to help those on screen readers, you should wrap your toasts in an [`aria-live` region](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions). This allows screen readers the ability to see suggested interruptions without any visual cues. If the information needed is important for the process, e.g. for a list of errors in a form, then use the [alert component]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/alerts/) instead of toast. - -You also need to adapt the `role` and `aria-live` level depending on the content. If it's an important message like an error, use `role="alert" aria-live="assertive"`, otherwise use `role="status" aria-live="polite"` attributes. - -As the content you're displaying changes, be sure to update the [`delay` timeout](#options) to ensure people have enough time to read the toast. - -{% highlight html %} - -{% endhighlight %} - -When using `autohide: false`, you must add a close button to allow users to dismiss the toast. - -
-{% capture example %} - {% endcapture %} @@ -128,16 +105,19 @@ When using `autohide: false`, you must add a close button to allow users to dism ## Placement -Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast.` +Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.
{% capture example %} -
+
Bootstrap 11 mins ago +
Hello, world! This is a toast message. @@ -152,7 +132,7 @@ For systems that generate more notifications, consider using a wrapping element
{% capture example %} -
+
@@ -162,6 +142,9 @@ For systems that generate more notifications, consider using a wrapping element Bootstrap just now +
See? Just like this. @@ -173,6 +156,9 @@ For systems that generate more notifications, consider using a wrapping element Bootstrap 2 seconds ago +
Heads up, toasts will stack automatically @@ -184,24 +170,25 @@ For systems that generate more notifications, consider using a wrapping element {% include example.html content=example %}
-You can also get fancy with flexbox utilities. +You can also get fancy with flexbox utilities to align toasts horizontally and/or vertically.
{% capture example html %} -
- -
+ +
- - @@ -209,6 +196,43 @@ You can also get fancy with flexbox utilities. {% include example.html content=example %}
+## Accessibility + +Toasts are intended to be small interruptions to your visitors or users, so to help those with screen readers and similar assistive technologies, you should wrap your toasts in an [`aria-live` region](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions). Changes to live regions (such as injecting/updating a toast component) are automatically announced by screen readers without needing to move the user's focus or otherwise interrupt the user. Additionally, include `aria-atomic="true"` to ensure that the entire toast is always announced as a single (atomic) unit, rather than announcing what was changed (which could lead to problems if you only update part of the toast's content, or if displaying the same toast content at a later point in time). If the information needed is important for the process, e.g. for a list of errors in a form, then use the [alert component]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/alerts/) instead of toast. + +Note that the live region needs to be present in the markup *before* the toast is generated or updated. If you dynamically generate both at the same time and inject them into the page, they will generally not be announced by assistive technologies. + +You also need to adapt the `role` and `aria-live` level depending on the content. If it's an important message like an error, use `role="alert" aria-live="assertive"`, otherwise use `role="status" aria-live="polite"` attributes. + +As the content you're displaying changes, be sure to update the [`delay` timeout](#options) to ensure people have enough time to read the toast. + +{% highlight html %} + +{% endhighlight %} + +When using `autohide: false`, you must add a close button to allow users to dismiss the toast. + +
+{% capture example %} + +{% endcapture %} +{% include example.html content=example %} +
+ ## JavaScript behavior ### Usage -- cgit v1.2.3