

Accessible forms with ARIA live regions
source link: https://tink.uk/accessible-forms-with-aria-live-regions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Accessible forms with ARIA live regions
Сообщение для российских читателей
When a form is used to update information on the page, it can be troublesome for screen reader users. Unless the screen reader is focused on the relevant bit of the page, the update goes by un-noticed. ARIA live regions are a simple way to improve the experience for screen reader users.
Quick recap: Screen readers rely almost entirely on the HTML of the page, and focus is moved from one element to another using a range of navigation commands. In other words, a screen reader can only focus on one element at a time.
That's where the trouble starts. If a screen reader is focused on a form field, it can't be focused on the bit of the page being updated as well.
Dynamic updates
The Marks & Spencer website is a good example. When an item is added to the shopping basket, the basket summary at the top right of the page gets updated. In fact it's the only confirmation that the item has been successfully added.
The update is easy to see at a glance, but not at all easy with a screen reader. First you have to discover that something has changed, then you have to find out where it happened. Even once you know this, you still need to move focus back and forth between the summary and the product information, every time you add an item to the basket.
Code example: without ARIA
A massively simplified version of this interaction might look like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tequila</title>
<script>
var items = 0;
function updateItems () {
items = items + 1;
document.getElementById("quantity").innerHTML=items;
}
</script>
</head>
<body>
<h1>Tequila</h1>
<p>Tequila makes me happy...</p>
<p><button onclick="updateItems()">Add tequila to basket</button></p>
<h2>Basket summary</h2>
<div>
<p>Your basket contains <span id="quantity">0</span> items.</p>
</div>
</body>
</html>
When the button is activated with a screen reader, nothing appears to happen. The page doesn't reload, so focus remains on the button and the screen reader stays silent. The basket summary is updated, but the screen reader user remains oblivious.
The aria-live attribute
The aria-live attribute can be used to turn the basket summary into an ARIA live region. ARIA enabled screen readers can monitor ARIA live regions for changes, and automatically announce them as they happen. The monitoring is done in the background, so even if the screen reader is focused somewhere else on the page at the time, changes within the live region are still announced.
Code example/: with aria-live
Adding the aria-live
attribute to the basket summary:
<h2>Basket summary</h2>
<div aria-live="assertive">
<p>Your basket contains <span id="quantity">0</span> items.</p>
</div>
The aria-live
attribute takes three possible values: off (default), polite and assertive. The polite value means that the screen reader will wait until its finished it’s current task before announcing the update, and the assertive value means the update is announced as soon as the screen reader encounters a slight pause (in reality it's almost always immediate).
The aria-atomic attribute
The aria-atomic attribute defines whether all of the content in the ARIA live region should be announced, or only the part that's changed.
Code example: with aria-atomic
Adding the aria-atomic attribute to the basket summary:
<h2>Basket summary</h2>
<div aria-live="assertive" aria-atomic="true">
<p>Your basket contains <span id="quantity">0</span> items.</p>
</div>
The aria-atomic
attribute has two possible values: true and false (default). Using aria-atomic="true"
means that all of the content within the ARIA live region will be announced, even though only a small part of it has changed. So screen readers will announce something like "Your basket contains 3 items", instead of just "3".
The All Star route deviation calculator is one of the best examples of this technique in the wild. Developed by Matt Lawson of Nomensa, the form is used to calculate cost savings based on reduced mileage.
As you manipulate information within the form, your potential cost saving is dynamically updated on the page. Because the updated information is an ARIA live region, using the form with a screen reader couldn't be easier.
Recommend
-
24
Many web pages today have their content dynamically changed using Javascript. An example of this is thesearch page on this blog. When the page is initially loaded, the only content in the <main> sec...
-
9
Accessible Rich Internet Applications (WAI-ARIA) 1.2↑ → Accessible Rich Internet Applications (WAI-ARIA) 1.2 ...
-
17
ARIA 1.1 Combobox with Listbox Popup ExamplesARIA 1.1 Combobox with Listbox Popup Examples The following three example comboboxes implement the ARIA 1.1 form of the
-
9
aria-expanded does not require a fallback 22 January 2018 ・ category: code When b...
-
11
Webinar – Structuring Accessible FormsPresented on December 14, 2021 at 12pm ETCreating accessible forms is the science of constructing form fields that provide the correct name, role, and state thro...
-
5
Сообщение для российских читателейRich Internet Application (RIA) websites encourage people to generate content, collaborate online and make choices about the information they receive. Unsurprisingly, RIA websites can represent a consid...
-
10
What is a Live Region? Accessible Rich Internet Applications (ARIA) is a set of roles and attributes you can add to HTML elements to give more information to the acc...
-
7
React-ing to accessibility: Building accessible forms that everyone can useWhen designing or developing a form, how high is accessibility on your priority list?As frontend/produ...
-
6
Accessible notifications with ARIA Live Regions (Part 1) Published on 15 Jan, 2024 | Takes approximately 22 min to read This post is a text-only excerpt from my...
-
4
Hey all you wonderful developers out there! In this post, I am going to take you through creating a simple contact form using semantic HTML and an awesome CSS pseudo class known as :focus-within. The :focus-within class a...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK