Nested Interactive Elements: A Nightmare in Accessibility

Rate this content
Bookmark

There have been numerous remarkable new UX experiences developed over the years, such as cards displaying an array of products and clickable list items with dynamic menu options, among others. However, only a few are aware of the challenges involved in building structures with nested interactive elements, and unfortunately, some of them are completely inaccessible. 


In today's talk, we will explore some of these prevalent web UX patterns and delve into the hidden challenges they present. While we may be able to mitigate some of these issues, others serve as cautionary tales in accessibility.

This talk has been presented at React Summit 2024, check out the latest edition of this React Conference.

FAQ

The speaker of the presentation is Kat Johnson, a senior front-end engineer at Khan Academy.

Nested Interactive Elements are interactive elements nested within each other, such as a link within a link or a button within a button.

Nested Interactive Elements are problematic because they are incorrect HTML and can confuse screen readers and other assistive tools, leading to errors and miscommunication.

Nested Interactive Elements can affect accessibility by causing screen readers and other assistive tools to misread the HTML, making it difficult for users to interact with the website.

You should not remove the role attribute or use a generic HTML div with on-click functionality as it hides interactive elements from screen readers and other assistive tools, degrading the user experience.

One way to fix Nested Interactive Elements if you are starting a new website is to unnest the interactive elements and ensure they are not inside each other.

CSS can help by overlaying buttons on top of each other to create the visual effect of nesting while keeping them semantically separated in the DOM structure.

You should be cautious about accidentally hiding clickable functionality on your website when modifying roles to fix Nested Interactive Elements.

It is important to host focus groups with users of various assistive tools to get feedback on whether the website is clear, concise, and easily navigable.

After finding a solution, you should document your approach and share your learnings online to help others create better and more accessible solutions.

Cat Johnson
Cat Johnson
9 min
18 Jun, 2024

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Nested Interactive Elements in Nightmare Accessibility can cause issues with screen readers and other assistive tools, making it difficult for users to interact with websites. Mitigation strategies include unnesting elements, using CSS overlay, and being cautious when modifying roles. It is recommended to involve users of assistive tools in focus groups and share solutions online.

1. Introduction to Nested Interactive Elements

Short description:

Welcome, everyone. Today I'm going to talk about Nested Interactive Elements in Nightmare Accessibility. Nested Interactive Elements are interactive elements nested within each other, like a link within a link or a button within a button. This structure is problematic because it's incorrect HTML and can cause issues with screen readers and other assistive tools, making it difficult for users to interact with your website. Simply removing the role attribute or using a generic HTML div won't fix the issue and can hide interactive elements from certain assistive tools, degrading the user experience.

Welcome, everyone. Thank you for joining me here today.

Today I'm going to be talking about Nested Interactive Elements in Nightmare Accessibility. We only have so much time for this talk, so we're going to jump in really quick and get started.

But before we really get started, let me just tell you about myself. My name is Kat Johnson. I'm a senior front-end engineer at Khan Academy and I love talking about accessibility and how to create accessible websites.

So let's dive right in. But before we get into sort of the meat of how to fix this issue, let's talk about what are Nested Interactive Elements? Because you might not have heard about them.

Nested Interactive Elements in very simplistic terms is just interactive elements nested within each other. So, for instance, it's having a link within a link or a button within a button.

Here's a little slice of code that kind of shows this. The reason this structure is really problematic is because it's incorrect HTML.

In the really early days of websites and the web, it didn't really make sense to nest buttons inside of buttons or links inside of links. There really wasn't a use case for this. But as the web has evolved, we are seeing this more and more in a lot of our user experiences around the web, from Google to this website that I really like using called The Mountaineers.

You'll find a lot of buttons or links inside of links and some of these little button menus.

But you might be asking the question, what's the big deal? It might be semantically incorrect HTML, but me as a user, I never had any issues using this experience. I'm able to click and navigate and use a lot of these nested buttons. So it doesn't seem to really be a big problem.

The bigger problem is because it's incorrect HTML, it really messes with a lot of screen readers and other assistive tooling. Because it's incorrect HTML, a lot of screen readers and other assistive tools, when they read your HTML, it doesn't know how to read out that information and how to convey it to the user.

Usually this will cause a lot of errors and a lot of miscommunication for a lot of assistive tooling, making it really difficult for users to interact with your website.

So now you must be thinking, well, I could probably fix this. I'll just remove the role equals button or I'll use a generic HTML div and leave on click functionality. That should fix this accessibility issue, right? Well, wrong. Do not do this.

You might be fixing the issue of nested interactive elements, but now you're hiding interactive elements from other screen readers and other assistive tools.

So when a user navigates your website with narrator or NVDA, they'll go over this element within your HTML, and it won't announce that it's a button that they need to click on. They'll hide that information and really degrade the experience for your website and cause more accessibility issues.

2. Mitigating Nested Interactive Elements

Short description:

If you have nested interactive elements on your website, there are ways to mitigate the issue. You can unnest the elements and make them separate interactive elements. If you can't unnest them, you can use CSS properties to overlay the elements, creating the visual effect of nesting without the semantic nesting. Be cautious when modifying roles to avoid hiding clickable functionality. It is recommended to host focus groups with users of assistive tools and share your learnings and solutions online.

So if your website does have buttons and links, please ensure that they are denoted as buttons and links in your HTML. So we're going to really have to find another way to fix this issue. But it's okay, because I have experienced this issue. On a previous website I work on, after building out a lot of the functionality in the R component library, we realized that we had this issue all over the place from our card components to different lists to other form fields inside our website. There was nested interactive elements all over the place causing issues with all our assistive tools.

The big question is, how do we mitigate this issue? How do we solve this? How do we make this better for our users? Well, there are several ways we can approach this problem. First, if you haven't started your website or haven't developed your component library, there's a lot of things you can do before you start. First thing you can do is, if it's at all possible, unnest these interactive elements. Really make sure they're not inside each other. Really move it outside of the nested interactive elements and make it a separate interactive element on its own.

And if you own a component library, something I'd recommend is if you're first starting out, please ensure that you're limiting developer configurations for your component library. Like setting strong typing and role properties so that if someone passes in some functionality, you're really limiting the scope and ensuring that they're not going to create a lot of accessibility issues. But you're probably asking the question, what if I've already written my whole website? What if I've already written my whole website or my whole component library and it's all over the place and I don't know how to fix this for my company without it being very costly?

Well, there's some other things we can do here. Let's look at the example with Google. Let's say your designer say that this layout has to look exactly like this, that we really need to have this interactive button card experience with a button inside of it for a drop down menu and we can't really change the user experience for that. Well, one thing you can try is you first are going to unnest those elements and then you can use CSS properties to really overlay that button on top of each other. It will create the visual effect of them being nested but semantic wise, it's not nested and they're separated out in the DOM structure. So that will reduce the issue of creating accessibility bugs on your website.

But let's say you can't unnest them for whatever reason. Well, and I encourage you to be very careful here, you can try modifying some of the roles. Now this I want you to be very careful about because you could accidentally hide a lot of clickable functionality on your website. But with this example, what we were able to do is within that drop down menu, there was already a click target to activate the whole card. So for us, we were able to set the whole outside div to something, a generic role of group or we could even like remove the whole role entirely and make it that click target, a very generic type. But knowing that users who use screen readers or other assistive tools can use that drop down button to click on the action for the whole button. So there's some things you can play around there. But whenever you're playing around with roles, I encourage you to be very careful about it.

But overall, if you're trying any of this functionality, whatever option you go with, I encourage you to host some focus groups with users who use various different assistive tools. They'll give you feedback on whether it's really clear, whether it's really concise, whether it works with your tool or functionality, and they can really easily navigate your website without any issues. And overall, no matter what option you pick, I encourage you to share your learning about what approach you took. Write documentation within your company, share your learnings online because overall, accessible solutions are constantly evolving. I know when I encountered this issue years ago, there was no documentation online about how to navigate this problem. So whatever option you go with for your company or for your website, please document it and share it online so we can constantly create better and more accessible solutions. And if you've really enjoyed my presentation here and want to see more, my name is Kat Johnson, and I hope you reach out and follow me on my website, katinamachines.com, or my LinkedIn, and thank you so much for joining me for this presentation, and I hope you have a great rest of your time at the React Summit. Thank you.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Accessibility at Discord
React Advanced Conference 2021React Advanced Conference 2021
22 min
Accessibility at Discord
This Talk discusses the accessibility efforts at Discord, focusing on keyboard navigation and the challenges faced with implementing focus rings and outlines. The speaker showcases a unified focus ring system and a saturation slider to address accessibility concerns. They also highlight the implementation of role colors and the use of CSS filters for accessibility improvements. The Talk concludes with insights on runtime accessibility checking and the development of a performant core runtime system for checking accessibility issues.
Less Cruft, More Power: Leverage the Power of the Web Platform
C3 Dev Festival 2024C3 Dev Festival 2024
30 min
Less Cruft, More Power: Leverage the Power of the Web Platform
This talk focuses on the powerful features of CSS and HTML that can level up developer skills and enhance web UI. Scroll-driven animations, popover API, and anchor positioning are explored as ways to create dynamic effects, improve performance, and increase accessibility. The talk also emphasizes the benefits of building presentations with CSS and HTML, separating logic from styling, and leveraging core platform features. Wishlist features for the web platform and the challenges of pushing updates across browsers are discussed.
Configuring Axe Accessibility Tests
TestJS Summit 2021TestJS Summit 2021
30 min
Configuring Axe Accessibility Tests
Top Content
AXe is an accessibility engine for automated web UI testing that runs a set of rules to test for accessibility problems. It can be configured to disable or enable specific rules and run based on tags. Axe provides various options, but axe linter does not support all options. The importance of investing time and resources in accessibility is emphasized, as it benefits not only those with disabilities but improves the web for everyone. Manual testing is also highlighted as a necessary complement to automated tests for addressing accessibility issues.
Nested Interactive Elements: An Nightmare in Accessibility
React Advanced Conference 2023React Advanced Conference 2023
23 min
Nested Interactive Elements: An Nightmare in Accessibility
Watch video: Nested Interactive Elements: An Nightmare in Accessibility
Nested interactive elements can cause accessibility issues on websites, and the speaker shares a personal experience with an accessibility bug involving a list component. Mitigating nested interactive structures involves limiting these patterns during development and restructuring existing elements. The speaker provides recommendations for improving accessibility, such as adjusting role properties and gathering user feedback. The conclusion emphasizes the importance of accessible solutions and encourages sharing resources to build more inclusive experiences.
Dialog Dilemmas and Modal Mischief: A Deep Dive Into Pop-Ups
JSNation 2023JSNation 2023
10 min
Dialog Dilemmas and Modal Mischief: A Deep Dive Into Pop-Ups
The Talk discusses the use of dialogues and popovers in web development. Dialogues can be modal or non-modal and are now accessibility-supported. Popovers are versatile and can be added to any element without JavaScript. They provide suggestions, pickers, teaching UI, list boxes, and action menus. Modal and non-modal dialogues and popovers have different behaviors and dismissal methods. Browser support for these features is expanding, but there are still open questions about positioning, semantics, and other use cases.
a11y and TDD: A Perfect Match
JSNation 2022JSNation 2022
24 min
a11y and TDD: A Perfect Match
This Talk explores the intersection of accessibility and test-driven development (TDD) in software development. TDD is a process that involves writing tests before writing production code, providing a safety net for code changes. The Talk demonstrates how to apply TDD principles to real-life examples, such as filling out a form, and emphasizes the importance of user-centric testing. By using atomic design principles, code can be organized in a clean and easy way. The Talk also discusses the use of labels and test IDs in tests for improved accessibility.

Workshops on related topic

Web Accessibility for Ninjas: A Practical Approach for Creating Accessible Web Applications
React Summit 2023React Summit 2023
109 min
Web Accessibility for Ninjas: A Practical Approach for Creating Accessible Web Applications
Workshop
Asaf Shochet Avida
Eitan Noy
2 authors
In this hands-on workshop, we’ll equip you with the tools and techniques you need to create accessible web applications. We’ll explore the principles of inclusive design and learn how to test our websites using assistive technology to ensure that they work for everyone.
We’ll cover topics such as semantic markup, ARIA roles, accessible forms, and navigation, and then dive into coding exercises where you’ll get to apply what you’ve learned. We’ll use automated testing tools to validate our work and ensure that we meet accessibility standards.
By the end of this workshop, you’ll be equipped with the knowledge and skills to create accessible websites that work for everyone, and you’ll have hands-on experience using the latest techniques and tools for inclusive design and testing. Join us for this awesome coding workshop and become a ninja in web accessibility and inclusive design!
Automated accessibility testing with jest-axe and Lighthouse CI
TestJS Summit 2021TestJS Summit 2021
85 min
Automated accessibility testing with jest-axe and Lighthouse CI
Workshop
Bonnie Schulkin
Bonnie Schulkin
Do your automated tests include a11y checks? This workshop will cover how to get started with jest-axe to detect code-based accessibility violations, and Lighthouse CI to validate the accessibility of fully rendered pages. No amount of automated tests can replace manual accessibility testing, but these checks will make sure that your manual testers aren't doing more work than they need to.
Web Accessibility in JavaScript Apps
React Summit 2022React Summit 2022
161 min
Web Accessibility in JavaScript Apps
Workshop
Sandrina Pereira
Sandrina Pereira
Often we see JavaScript damaging the accessibility of a website. In this workshop, you’ll learn how to avoid common mistakes and how to use JS in your favor to actually enhance the accessibility of your web apps!
In this workshop we’ll explore multiple real-world examples with accessibility no-nos, and you'll learn how to make them work for people using a mouse or a keyboard. You’ll also learn how screen readers are used, and I'll show you that there's no reason to be afraid of using one!
Join me and let me show you how accessibility doesn't limit your solutions or skills. On the contrary, it will make them more inclusive!
By the end, you will:- Understand WCAG principles and how they're organized- Know common cases where JavaScript is essential to accessibility- Create inclusive links, buttons and toggleble elements- Use live regions for errors and loading states- Integrate accessibility into your team workflow right away- Realize that creating accessible websites isn’t as hard as it sounds ;)