Problem/Motivation
In a set of links such as a menu, the currently-active link has the is-active class added so it can be styled to make it visually apparent that this link goes to the current page. This information should also be made available programmatically. In order to do this, the aria-current attribute can be set to "page."
The attribute should be added to the link, not a list item or other element. If the currently-active item is not linked to (for example, if the link is removed when the target is the current page, such as in breadcrumbs where the page title is displayed), then the aria-current attribute is not required.
References:
- https://www.w3.org/TR/wai-aria-1.2/#aria-current
- https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attribut...
Steps to reproduce
- Install the latest version of Drupal using the standard profile.
- Create three basic pages and add them to the main menu. Note they appear as links in the main menu region.
- Follow one of the links in the main menu.
- Inspect the code of the link to the current page. Note that it is still a link and it has the is-active class. Note that it does not have an aria-current attribute.
Proposed resolution
Add aria-current="page" to all links where the is-active class is being added. Do not add the attribute to non-links; do not add it when the current item is not a page (for example, tab panels, steps in a form, etc).
Remaining tasks
Manual testing of other places where the is-active class is added. Test pagination links in Views etc.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
TBD.
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | 3038523-aria-current-link-core-10.2.x-40.patch | 12.98 KB | cboyden |
| #30 | Screenshot 2023-10-18 at 2.09.31 PM.png | 418.7 KB | lauriii |
Issue fork drupal-3038523
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mgiffordTagging & adding related links. This isn't a well used pattern. Could be useful, but not sure that it is. Combination of browser support & user patterns.
That said, it's increased semantics and could be useful for many things in the future.
Comment #4
alphex commentedThis is a w3c recommendation from December 2017 - and my clients are starting to get this flagged by their accessibility compliance audits.
hoping to see
aria-current="true"+1 hoping this gets rolled in to core.
Comment #5
idebr commentedThis contrib module adds the aria-current attribute to active items in
<nav>elements: https://www.drupal.org/project/aria_currentComment #9
luke.leberMight this be something to add into
\Drupal\Core\EventSubscriber\ActiveLinkResponseFilterto catch more instances?Comment #14
mgiffordAdding https://www.w3.org/WAI/WCAG21/Understanding/name-role-value
Comment #16
gauravvvv commentedComment #18
gauravvvv commentedAdded aria-current attribute on pager and breadcrumb. Still needs to be added on menu items.
Comment #19
gauravvvv commentedComment #20
cboyden commentedRather than each theme needing to implement this, would it be possible to do as Luke.Leber suggests and have the attribute added more globally? It should probably be done anywhere the is-active class is applied to a menu link. For example, in the JS file /core/misc/active-link.es6.js and in the ActiveLinkResponseFilter.php class.
Comment #22
cboyden commentedI've created a new MR with the approach of adding the aria-current="page" attribute everywhere (that I can find) that the is-active class is being added to a menu link. I've also created two patches, one for 10.1.x/10.0.x, and one for 9.5.x, in case anyone wants to use them.
According to the ARIA spec for the aria-current attribute, it should be added to a set of navigation links to programmatically indicate the current page among that set of links. It needs to be added to the link, not the list item or other element. And if the current item is not a link, the aria-current attribute is not needed. For reference see https://www.w3.org/TR/wai-aria-1.2/#aria-current and https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attribut....
Comment #23
irene_dobbs commentedOn the latest patch for 3038523-aria-current-link-core-9.5.x-22.patch and 3038523-aria-current-link-core-10.x-22.patch,
I added menu items to the main navigation and looked at the is-active class and I do not see the aria-current attribute added.
Comment #24
dsnopekI tested the Drupal 9.5 patch from #22, and it worked for me locally! I'm not sure why it didn't work for @irene_dobbs?
However, it looks like this also needs to update
web/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.phpbecause there's a test failure in CI.Comment #25
cboyden commentedI've updated the MR to include a fix for ActiveLinkResponseFilterTest. I'm also attaching new patches for 9.5.x and 10.1.x/10.0.x.
Comment #26
smustgrave commentedBefore testing the issue summary seem incomplete. Added the template for reference.
Comment #27
cboyden commentedUpdated issue summary.
Comment #28
smustgrave commentedFor clarity I'm hiding the patches as MR 4959 is what would be committed.
Following the steps in the IS I can confirm the links with is-active don't have an aria attribute
Applying the MR
Can confirm the links do have aria-attribute now
Worth noting that the is-active class being set by the toolbar is unaffected with this MR. *Edit* Which is expected
Comment #29
cboyden commentedThanks for the review @smustgrave. I took a look at the admin toolbar on the standard install and noted that aria-current is being set to "page" for the active link in the toolbar. To reproduce:
This seems like the appropriate behavior to me - the links in the hierarchy above where you are have the visual styling, but only the actual current page has the aria-current attribute.
Comment #30
lauriiiShould the
aria-currentattribute be used only on menus or should this also work on other kinds of links too?For example, if I click "Find out more", should that have

aria-current?If that's the case, should we do it in a follow-up or should it be done here?
Comment #31
smustgrave commentedFrom reading https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attribut...
I don't think the Find out more link mentioned would count.
Comment #32
luke.leberI've always believed that ad-hoc self-referencing links can be avoided by a solid content strategy.
...however I did want to raise one other question: what about Single Page Application-type use cases? Is this an outlier, or should we confirm that same page links don't have a fragment?
Comment #33
cboyden commented@Luke.Leber because all we're doing is adding the aria-current attribute in places where core is already adding the is-active class, I would hope that the ActiveLinkResponseFilter class would do the right thing with menus that contain anchor links. If core is not already adding the is-active class where it needs adding, or if it's adding the class to multiple anchor links in the same menu, it might be best to fix that in a separate issue.
Comment #35
larowlanIssue credits
Comment #38
larowlanTook this for a manual test, tested menu links, breadcrumbs, local tasks, pagers. All looked good.
Read the MDN spec on it and it looks like we're doing things the correct way.
Committed to 11.x
Added and published a change-record
Comment #39
frankdesign commentedThanks for fixing this for D11. Is there any chance that the patch will be updated for D10.2 (the patch at #25 fails to apply)
Comment #40
cboyden commentedThe 10.0/10.1 patch still applies manually to 10.2.x with a bunch of offsets. I've uploaded a new version that should apply to 10.2.x cleanly.
Comment #42
aaronpinero commentedThank you @cboyden for the 10.2.x patch. I have applied this to my v10.2.5 Drupal site using composer. The patch applied cleanly and appears to provide the expected a11y enhancement.
Comment #43
chri5tia commentedI checked out the patch #40 for 10.2.x to reroll it for 10.3 and all the changes seem to be in core, though I don't see it noted. In case this is helpful to anyone else.