Skip to content

Commit f3d4238

Browse files
hellobrianmarijohannessen
authored andcommitted
fix(notifications): replace role="alert" with aria-live="polite" (#268)
* fix(a11y): replace role="alert" with aria-live="polite" for Notifications * fix(Notification): warning uses alert role * docs(Notification): usage for alert roles and aria-live
1 parent 346de46 commit f3d4238

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/components/notification/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,26 @@ Use these modifiers with `.bx--inline-notification` class.
4141
| selectorButton | `[data-notification-btn]` | The selector to find the close button in the component |
4242
| eventBeforeDeleteNotification | `notification-before-delete` | Event before deleting the notification |
4343
| eventAfterDeleteNotification | `notification-after-delete` | Event after deleting the notification |
44+
45+
46+
### FAQ
47+
48+
#### Using aria live regions and alert roles
49+
50+
Using `role="alert"` is an aggressive call to action that the prompts a screen reader user to take immediate action on something that changed in the UI. This is usually reserved for things that are important or time-sensitive like:
51+
52+
- An invalid value was entered into a form field
53+
- The user's login session is about to expire
54+
- The connection to the server was lost, local changes will not be saved
55+
56+
Use the alert role sparingly and only in situations where the user's immediate attention is required.
57+
Dynamic changes that are less urgent should use a less aggressive method, such as `aria-live="polite"` or other live region roles.
58+
59+
Don't use an alert role on all notifications.
60+
61+
By default, we recommend that error and warning notifications use `role="alert"`, while success and info notifications use `aria-live="polite"`.
62+
But as always, this will depend on the urgency of the notification.
63+
64+
**Sources:**
65+
- [Use the alert role - MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alert_role)
66+
- [ARIA Live Regions - MDN](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions)

src/components/notification/inline-notification.html

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!--replace xlink:href with correct svg icon API endpoint-->
21
<div data-notification class="bx--inline-notification bx--inline-notification--error" role="alert">
32
<div class="bx--inline-notification__details">
43
<svg class="bx--inline-notification__icon" width="16" height="16" viewBox="0 0 16 16" fill-rule="evenodd">
@@ -16,8 +15,7 @@
1615
</button>
1716
</div>
1817

19-
<!--replace xlink:href with correct svg icon API endpoint-->
20-
<div data-notification class="bx--inline-notification bx--inline-notification--info" role="alert">
18+
<div data-notification class="bx--inline-notification bx--inline-notification--info" aria-live="polite">
2119
<div class="bx--inline-notification__details">
2220
<svg class="bx--inline-notification__icon" width="16" height="16" viewBox="0 0 16 16" fill-rule="evenodd">
2321
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zm0 4c.6 0 1 .4 1 1s-.4 1-1 1-1-.4-1-1 .4-1 1-1zm2 8H6v-1h1V8H6V7h3v4h1v1z"></path>
@@ -34,8 +32,7 @@
3432
</button>
3533
</div>
3634

37-
<!--replace xlink:href with correct svg icon API endpoint-->
38-
<div data-notification class="bx--inline-notification bx--inline-notification--success" role="alert">
35+
<div data-notification class="bx--inline-notification bx--inline-notification--success" aria-live="polite">
3936
<div class="bx--inline-notification__details">
4037
<svg class="bx--inline-notification__icon" width="16" height="16" viewBox="0 0 16 16" fill-rule="evenodd">
4138
<path d="M8 0C3.6 0 0 3.6 0 8s3.6 8 8 8 8-3.6 8-8-3.6-8-8-8zM6.7 11.5L3.4 8.1l1.4-1.4 1.9 1.9 4.1-4.1 1.4 1.4-5.5 5.6z"></path>
@@ -52,7 +49,6 @@
5249
</button>
5350
</div>
5451

55-
<!--replace xlink:href with correct svg icon API endpoint-->
5652
<div data-notification class="bx--inline-notification bx--inline-notification--warning" role="alert">
5753
<div class="bx--inline-notification__details">
5854
<svg class="bx--inline-notification__icon" width="16" height="16" viewBox="0 0 16 16" fill-rule="evenodd">

src/components/notification/toast-notification.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!--replace xlink:href with correct svg icon API endpoint-->
21
<div data-notification class="bx--toast-notification bx--toast-notification--error" role="alert">
32
<div class="bx--toast-notification__details">
43
<h3 class="bx--toast-notification__title">Title: 'App Name' is stopped</h3>
@@ -15,7 +14,7 @@ <h3 class="bx--toast-notification__title">Title: 'App Name' is stopped</h3>
1514
</button>
1615
</div>
1716

18-
<div data-notification class="bx--toast-notification bx--toast-notification--info" role="alert">
17+
<div data-notification class="bx--toast-notification bx--toast-notification--info" aria-live="polite">
1918
<div class="bx--toast-notification__details">
2019
<h3 class="bx--toast-notification__title">Title: 'App Name' is stopped</h3>
2120
<p class="bx--toast-notification__subtitle">Subtitle: Your application was stopped.</p>
@@ -28,7 +27,7 @@ <h3 class="bx--toast-notification__title">Title: 'App Name' is stopped</h3>
2827
</button>
2928
</div>
3029

31-
<div data-notification class="bx--toast-notification bx--toast-notification--success" role="alert">
30+
<div data-notification class="bx--toast-notification bx--toast-notification--success" aria-live="polite">
3231
<div class="bx--toast-notification__details">
3332
<h3 class="bx--toast-notification__title">Title: 'App Name' is stopped</h3>
3433
<p class="bx--toast-notification__subtitle">Subtitle: Your application was stopped.</p>

0 commit comments

Comments
 (0)