Locating the final focusable link within a secondary navigation modal

Our website features four primary menu items (Shirts, Pants, Footwear, Headgear), each with a subnavigation menu that opens when clicked. For instance, selecting Shirts reveals options from ABC Brand to Z Brand.

The main navigation class is .mainNav

The sub navigation class is .subNav

We aim for an intuitive user experience where navigating through the subNav and reaching the end will automatically transition the user to the next mainNav item. For example, if a user is on Shirts > Z Brand and presses tab, we want the subNav for Shirts to close, directing the user to Pants.

To achieve this functionality, how can we identify the final focusable item in the subNav so that the desired action takes place upon hitting tab?

<div class="mainNav">
  <a="#">Shirts</a>
  <a="#">Pants</a>
  <a="#">Footwear</a>
  <a="#">Headgear</a>
</div>

<div class="subNav-0">
  <h1>Shirts</h1>
  <a="#">ABC Brand</a>
  <a="#">Guess</a>
  <a="#">Levis</a>
  <a="#">Z Brand</a>
</div>

<div class="subNav-1">
  <h1>Pants</h1>
  <a="#">ABC Brand</a>
  <a="#">Guess</a>
  <a="#">Levis</a>
  <a="#">Z Brand</a>
</div>

<div class="subNav-2">
  <h1>Headgear</h1>
  <a="#">Big Caps</a>
  <a="#">Levis</a>
  <a="#">Pacific Hatwear</a>
  <a="#">Polo</a>
  <a="#">Stetson</a>
</div>

<div class="subNav-3">
  <h1>Footwear</h1>
  <a="#">Adidas</a>
  <a="#">Asics</a>
  <a="#">Brooks</a>
  <a="#">Converse</a>
  <a="#">New Balance</a>
  <a="#">Nike</a>
  <a="#">Puma</a>
  <a="#">Saucony</a>
</div>

Answer №1

The comments were piling up in the section, so I decided to share some code here. The original code provided doesn't place each subnav immediately after its corresponding main nav element, causing a potential issue with tabbing order in browsers.

If the code was revised as follows, it would improve accessibility:

<div class="mainNav">
  <a href="#">Shirts</a>
    <div class="subNav-0">
      <h1>Shirts</h1>
      <a href="#">ABC Brand</a>
      <a href="#">Guess</a>
      <a href="#">Levis</a>
      <a href="#">Z Brand</a>
    </div>
  <a href="#">Pants</a>
    <div class="subNav-1">
      <h1>Pants</h1>
      <a href="#">ABC Brand</a>
      <a href="#">Guess</a>
      <a href="#">Levis</a>
      <a href="#">Z Brand</a>
    </div>
  <a href="#">Footwear</a>
    <div class="subNav-3">
      <h1>Footwear</h1>
      <a href="#">Adidas</a>
      <a href="#">Asics</a>
      <a href="#">Brooks</a>
    </div>
</div>

Each subnav should initially have display:none until the respective main nav is activated to open it. This way, when hidden, it won't interfere with tabbing. When shown (display:block), the browser will automatically include it in the tab order.

The original post didn't cover all accessibility aspects, such as ensuring each main nav element includes aria-expanded attribute for screen readers to recognize collapsible sections that can be expanded.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for uploading a text file into JavaScript?

I'm currently facing an issue with importing a text file from my local computer into JavaScript in order to populate HTML dropdowns based on the content of the file. Despite spending considerable time searching for solutions on stack overflow, I haven ...

Styling radio buttons with customized CSS borders

I'm attempting to style some radio buttons with a bold red border, but I'm having trouble getting it to display correctly in the latest versions of Firefox and Chrome. It works fine in IE9/IE8. For each input element that is required on my form, ...

Tips for retrieving a value from a JSON file that has been refreshed with AJAX and converting it into a PHP variable

json.php: $array['item1'] = 100; $array['item2'] = 500; echo json_encode($array); javascript: $.getJSON('json.php', function(data) { var value1 = data.item1; var value2 = data.item2; $.ajax({ url: "scr ...

MVC HTML implementing automatic line breaks

<h2>Order</h2> <h1> @Html.ActionLink("Create Order", "CreateOrder", "Home")</h1> When I place the above code in the cshtml file within the View of MVC, the output shows: Order Create Order Is there a way to display it like this ...

Record numerous button clicks in the database

Currently, I am developing a web application designed for parents to care for their newborns. Within the app, there are three buttons allocated for each task forming a progress flow, which indicates the completion status of each task (for example, steps fo ...

The battle between nested flexbox heights and max-heights

Note: I am observing some unusual behavior on Chrome 72. FireFox 64 seems to be working fine! I am experiencing an issue with a nested flexbox. In the code snippet below, I have added an artificial XL height to .root.container in order to achieve the des ...

Sending Data from Ajax to C# Backend via Dictionary

Currently, I am utilizing ASP.Net and jquery/ajax. Below is the jquery script that I am working with: var sizes = []; sizes.push({ key: "1", value: "3"}); $.ajax({ type: "POST", url: pageUrl, data: '{"sizeList":' + sizes + '}&a ...

Applying CSS to the second level of nested div within a container div

I have a parent div with nested child divs that I want to style using one class. The challenge is getting the styles to apply correctly to specific child divs. <div class='aa-callout aa-prime'> <div class='row p-1 h-100'> ...

Creating a tooltip for new list items: A step-by-step guide

I'm currently working on creating a tooltip using JQuery for incoming list items. Users will input text in a textfield, press enter, and those values will be displayed in a visible list on the website. I intend to have a tooltip associated with each i ...

Unlocking Restricted Functions Through Angular Factories

I have been working on an Angular factory that utilizes the revealing module pattern to expose a service interface. The factory relies on injected dependencies to support the public service, which are not explicitly included in the public service itself. ...

Loading web pages using ajax and handling relative paths

My method involves using ajax to load HTML files when links on my page are clicked. The process is simplified as follows: links.click(function () { var href = $(this).attr("href"); history.pushState(null, null, href); $.get($(this).attr("href" ...

Modify the tax price color on the shopping cart page using CSS

I'm attempting to modify the appearance of the VAT cost in the cart and checkout section of my Woocommerce website. Specifically, I want to change the color and size of the VAT display without affecting the total amount. Here is the CSS code I am usi ...

Issue with relative templateUrl in Angular 2 not resolving paths

As I embark on creating my first Angular 2 app, I'm faced with the task of setting my template in an HTML file using `templateUrl`. Currently, both the component.ts and view.html are stored in the same folder under src/ directory. Here's what I ...

The child div can be scrolled horizontally, while the parent window remains fixed

I am facing a challenge with my HTML and CSS setup. I want to create a child div that scrolls horizontally, but I do not want the parent window to scroll along with it. Below is my current code: <div id="parent"> <div id="div1"> . ...

Optimal method to confirm if a div is displaying all its content

My div contains dynamic text with a specified max-height, potentially leading to some content not being visible. How can I determine if all the content is displayed after it's been rendered? Therefore, my inquiry is: In terms of best practice, shoul ...

Is it possible to display a thumbnail image in a separate full-sized window by using CSS or JavaScript?

I am currently utilizing a program called WebWorks 2020.1 that automatically creates <img> tags from my FrameMaker source input when published to DHTML. Unfortunately, I do not have the ability to directly modify the HTML <img> or <a> tag ...

Storing a collection of subdocuments in Mongoose

I am encountering difficulties in saving a subdocument array. The data just won't save: On the front end, a Day object is sent with an array of headings, and each heading can contain a content array (which is a mongoose schema). var DaySchema = mong ...

What are some tactics for avoiding movement in the presence of a border setting?

I created a webpage that has the following structure: .topbar-container { width: 100%; position: fixed; top: 0; background-color: #2d3e50; z-index: 999; display: flex; transition: height 500ms; } @media (min-width: 992px) { .topbar-cont ...

Is there a way for me to identify when I am "traveling" along the same path?

I want to create a toggle effect where a view is hidden if the user tries to revisit it. This can be useful for showing/hiding modal boxes. Here's the code I attempted: /* Root Instance */ const app = new Vue({ router, watch: { '$route&a ...

Creating a code script for the purpose of automating npm commands

Currently, I am immersed in an angular js project and I have a desire to streamline the execution of the following two commands. ./node_modules/protractor/bin/webdriver-manager update ./node_modules/protractor/bin/webdriver-manager start The challenge li ...