WordPress.org

Make WordPress Core

Opened 4 months ago

Closed 3 months ago

#43191 closed enhancement (fixed)

Add aria-current to output of Walker_Nav_Menu for front-end navs

Reported by: williampatton Owned by: chetan200891
Milestone: 5.0 Priority: normal
Severity: normal Version:
Component: Themes Keywords: good-first-bug aria-current has-patch
Focuses: accessibility Cc:

Description (last modified by SergeyBiryukov)

With recent passes on navigations to add aria-current the idea was brought up about placing it on frontend menus too.

See #40833 and other related tickets here https://core.trac.wordpress.org/query?keywords=~aria-current

Modifications would be required inside the Walker_Nav_Menu class. I will look closer at the required modifications but something as simple as this could be all that is needed:

if ( in_array( 'current-menu-item', $classes, true ) ) {
	$atts['aria-current'] = 'page';
}

Attachments (3)

43191.diff (602 bytes) - added by chetan200891 4 months ago.
Created patch to add aria-current to aria-current to output of Walker_Nav_Menu for front-end navs
43191.2.diff (1.9 KB) - added by chetan200891 4 months ago.
Updated patch.
43191.3.diff (1.8 KB) - added by sami.keijonen 4 months ago.

Download all attachments as: .zip

Change History (15)

This ticket was mentioned in Slack in #accessibility by williampatton. View the logs.


4 months ago

#2 @SergeyBiryukov
4 months ago

  • Description modified (diff)
  • Keywords good-first-bug added

#3 @afercia
4 months ago

  • Keywords aria-current added

@chetan200891
4 months ago

Created patch to add aria-current to aria-current to output of Walker_Nav_Menu for front-end navs

#4 @chetan200891
4 months ago

  • Keywords needs-patch removed

I have attached patch 43191.diff to add aria-current to aria-current to output of Walker_Nav_Menu for front-end navs.

#5 @SergeyBiryukov
4 months ago

  • Milestone changed from Awaiting Review to 5.0

#6 @afercia
4 months ago

@chetan200891 thanks! I think the nav items have a $item->current property, maybe it would be better to use that? The new attribute should be documented in the nav_menu_link_attributes filter docblock.

@chetan200891
4 months ago

Updated patch.

#7 @chetan200891
4 months ago

@afercia Thanks for your suggestion. I have updated patch 43191.2.diff based on your suggestion.

This ticket was mentioned in Slack in #accessibility by sami.keijonen. View the logs.


4 months ago

#9 @sami.keijonen
4 months ago

Thanks @chetan200891 ! Somehow I could not test your patch, I got two different files question. Could be that it's just me and SVN.

Just in case I uploaded patch 43191.3.diff.

I tested using default themes and couple of random themes from .org. And all seems to work, also in widget menu.

But aria-current is not outputted if theme uses default wp_page_menu as a fallback in wp_nav_menu. Not sure if this is a problem.

Last edited 4 months ago by sami.keijonen (previous) (diff)

#10 @afercia
4 months ago

But aria-current is not outputted if theme uses default wp_page_menu as a fallback

I believe wp_page_menu() uses a different default walker, which is Walker_Page see walk_page_tree(). I guess that should go in a separate ticket.

#11 @DrewAPicture
4 months ago

  • Keywords has-patch added
  • Owner set to chetan200891
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

#12 @afercia
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 42808:

Accessibility: Themes: use aria-current for the Walker_Nav_Menu current link.

The aria-current attribute is a simple, effective way to help assistive
technologies users orientate themselves within a list of items. Continues the
introduction in core of aria-current after [42440], [41683], [41359], and [41371].

Props williampatton, chetan200891, sami.keijonen.
Fixes #43191.

Note: See TracTickets for help on using tickets.