Accessible progressive disclosure revisited

I wrote a little while back about making an accessible progressive disclosure pattern. It’s very basic—just a few ARIA properties and a bit of JavaScript sprinkled onto some basic HTML. The HTML contains a button element that toggles the aria-hidden property on a chunk of markup.

Earlier this week I had a chance to hang out with accessibility experts Derek Featherstone and Devon Persing so I took the opportunity to pepper them with questions about this pattern. My main question was “Should I automatically focus the toggled content?”

Derek’s response was very perceptive. He wanted to know why I was using a button. Good question. When you think about it, what I’m doing is pointing from one element to another. On the web, we point with links.

There are no hard’n’fast rules about this kind of thing, but as Derek put it, it helps to think about whether the action involves controlling something (use a button) or taking the user somewhere (use a link). At first glance, the progressive disclosure pattern seems to be about controlling something—toggling the appearance of another element. But if I’m questioning whether to automatically focus that element, then really I’m asking whether I want to take the user to that place in the document—in other words, linking to it.

I decided to update the markup. Here’s what I had before:

<button aria-controls="content">Reveal</button>
<div id="content"></div>

Here’s what I have now:

<a href="#content" aria-controls="content">Reveal</a>
<div id="content"></div>

The logic in the JavaScript remains exactly the same:

  1. Find any elements that have an aria-controls attribute (these were buttons, now they’re links).
  2. Grab the value of that aria-controls attribute (an ID).
  3. Hide the element with that ID by applying aria-hidden="true" and make that element focusable by adding tabindex="-1".
  4. Set aria-expanded="false" on the associated link (this attribute can be a bit confusing—it doesn’t mean that this element is not expanded; it means the element it controls is not expanded).
  5. Listen for click events on those links.
  6. Toggle the aria-hidden and aria-expanded when there’s a click event.
  7. When aria-hidden is set to false on an element (thereby revealing it), focus that element.

You can see it in action on CodePen.

See the Pen Accessible toggle (link) by Jeremy Keith (@adactio) on CodePen.

Have you published a response to this? :

Responses

3 Shares

# Shared by Nina Gerling on Tuesday, May 3rd, 2016 at 9:52am

# Shared by Sara Soueidan on Tuesday, May 3rd, 2016 at 10:06am

# Shared by jerbi ahmed [Ξ] on Tuesday, May 3rd, 2016 at 3:08pm

27 Likes

# Liked by David Moulton on Tuesday, May 3rd, 2016 at 11:01am

# Liked by Rachel Andrew on Tuesday, May 3rd, 2016 at 11:02am

# Liked by Sara Soueidan on Tuesday, May 3rd, 2016 at 11:36am

# Liked by Brett Jankord on Tuesday, May 3rd, 2016 at 11:37am

# Liked by Pim Derks on Tuesday, May 3rd, 2016 at 11:38am

# Liked by Ines Teles on Tuesday, May 3rd, 2016 at 11:38am

# Liked by 황규연 / Kyooyeon Hwang on Tuesday, May 3rd, 2016 at 12:07pm

# Liked by Melissa Em on Tuesday, May 3rd, 2016 at 12:08pm

# Liked by Liam Coates on Tuesday, May 3rd, 2016 at 12:08pm

# Liked by Heath Flohre on Tuesday, May 3rd, 2016 at 12:35pm

# Liked by Johanna Bates on Tuesday, May 3rd, 2016 at 1:01pm

# Liked by Mizan :) on Tuesday, May 3rd, 2016 at 1:01pm

# Liked by Brian Reeves on Tuesday, May 3rd, 2016 at 1:01pm

# Liked by Christopher Janzen on Tuesday, May 3rd, 2016 at 1:36pm

# Liked by Jeremias Menichelli on Tuesday, May 3rd, 2016 at 1:36pm

# Liked by Chris Cid on Tuesday, May 3rd, 2016 at 1:36pm

# Liked by Monika Spielman on Tuesday, May 3rd, 2016 at 2:08pm

# Liked by Mina Markham on Tuesday, May 3rd, 2016 at 2:09pm

# Liked by Jem Bijoux on Tuesday, May 3rd, 2016 at 2:44pm

# Liked by Henrik Ammer on Tuesday, May 3rd, 2016 at 2:44pm

# Liked by jerbi ahmed [Ξ] on Tuesday, May 3rd, 2016 at 4:20pm

# Liked by roycifer on Tuesday, May 3rd, 2016 at 4:45pm

# Liked by Beau Davis on Tuesday, May 3rd, 2016 at 5:18pm

# Liked by derheap on Tuesday, May 3rd, 2016 at 6:44pm

# Liked by Fred Carlsen on Tuesday, May 3rd, 2016 at 10:48pm

# Liked by Michael Lecke on Wednesday, May 4th, 2016 at 1:55am

# Liked by Mike Cheshire on Wednesday, May 4th, 2016 at 9:43am

Related posts

The intersectionality of web performance

Business, sustainability, and inclusivity.

Assumption

Separate your concerns.

Alt writing

Aiming for originality and creativity in alt text.

Image previews with the FileReader API

Adding `alt` text to uploaded images.

Even more writing on web.dev

Five more articles on modern responsive design to close out the course.

Related links

The Folly of Chasing Demographics - YouTube

I just attended this talk from Heydon at axe-con and it was great! Of course it was highly amusing, but he also makes a profound and fundamental point about how we should be going about working on the web.

Tagged with

Cameron Dutro on ruby.social

Here’s the inside scoop on why Github is making a bizarre move from working web components to a legacy React stack.

Most of what I heard in favor of React was a) it’s got a good DX, b) it’s easy to hire for, and c) we only want to use it for a couple of features, not the entire website.

It’s all depressingly familiar, but it’s very weird to come across this kind of outdated thinking in 2023.

My personal prediction is that, eventually, the company (and many other companies) will realize how bad React is for most things, and abandon it. I guess we’ll see.

Tagged with

Let’s reinvent the wheel ⚒ Nerd

Vasilis gives the gist of his excellent talk at the border:none event that just wrapped up in Nuremberg. The rant at the end chimed very much with my feelings on this topic:

I showed a little interaction experiment that one of my students made, with incredible attention to detail. Absolutely brilliant in so many ways. You would expect that all design agencies would be fighting to get someone like that into their design team. But to my amazement she now works as a react native developer.

I have more of these very talented, very creative designers who know how to code, who really understand how the web works, who can actually design things for the web, with the web as a medium, who understand the invisible details, who know about the UX of HTML, who know what’s possible with modern HTML and CSS. Yet when they start working they have to choose: you either join our design team and are forced to use a tool that doesn’t get it, or you join the development team and are forced to use a ridiculous framework and make crap.

Tagged with

Bruce Lawson’s personal site  : HTML popover, videos and display:blackhole

Bruce raises an interesting question with media playing in popovers—shouldn’t the media pause when the popover is closed? I agree with Bruce that this is a common use case that should be covered declaratively.

Tagged with

Aaron Gustafson

Progressive enhancement begins with constructing a robust and universally accessible foundation, designed to cater to all users, regardless of individual or technological circumstances. From here, advanced features can be strategically layered to enhance the user experience wherever feasible. Even as these enhancements roll out, guided by the capacities of different devices, the quality of network connections, or the availability of specific APIs, the core functionalities should remain steadfast and accessible to all.

Tagged with

Previously on this day

9 years ago I wrote 100 words 016

Day sixteen.

10 years ago I wrote The tragedy of the commons

Digital destruction courtesy of the Brooklyn Museum.

10 years ago I wrote Connections #2

Come along to chat about organisational stuff’n’shit.

13 years ago I wrote Skillful stories

An excellent night of narrative exploration in Brighton.

15 years ago I wrote Inkosaurs

Moving from the denial phase into anger.

16 years ago I wrote Mi.gration

Moving bookmarks.

18 years ago I wrote Further comment

Following up on the comments controversy.

19 years ago I wrote Junk not found

If only this were a server response instead of a message count…

20 years ago I wrote What is Web Design?

"Who are we? Why are we here?"

20 years ago I wrote Beatallica on the brat

Beatallica perform Beatles songs in the style of Metallica.