Support all aria-current values

Created on 19 August 2021, over 3 years ago
Updated 18 November 2024, about 2 months ago

Problem/Motivation

While #3228566: Support aria-current="location" for breadcrumbs was a feature request with a narrow scope, this issue is about a flexible way to support all allowed aria-current values on a variety of elements.

Proposed resolution

I would like this module to be as flexible as possible, but preferably without the complexity of admin config forms and user-configurable element selectors. That's why I propose a declarative approach. A data-aria-current-type attribute on a wrapper (eg. a nav or menu ul) declares the aria-current value that active links within that wrapper should get. For example: <ul class="menu" data-aria-current-type="page">...</ul> tells the JS that active links within this ul should get a aria-current="page" attribute.

Two theme preprocess functions take care of out-of-the-box support for menus and breadcrumbs. Other components can easily hook into this system by setting the appropriate data attribute. For instance, if you have a progress indicator on a custom multi-step wizard, just add data-aria-current-type="step".

This all assumes that the active link has a "is-active" class, as is built into Drupal core.

A downside of this solution is that is changes the behavior in existing installations. Currently, all <nav> elements are targeted by the module's JS. In the proposed solution, only elements rendered by the 'menu' and 'breadcrumb' theme hooks are supported out-of-the-box. I think this is a minor issue because menus are the primary goal anyway.

Remaining tasks

Discuss.

User interface changes

None.

API changes

Introduction of a declarative interface using a data attribute.

Data model changes

None.

Feature request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

🇳🇱Netherlands marcvangend Amsterdam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024