WordPress.org

Make WordPress Core

Opened 3 weeks ago

Last modified 2 weeks ago

#43191 assigned enhancement

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 3 weeks 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 3 weeks ago.
Updated patch.
43191.3.diff (1.8 KB) - added by sami.keijonen 3 weeks ago.

Download all attachments as: .zip

Change History (14)

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


3 weeks ago

#2 @SergeyBiryukov
3 weeks ago

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

#3 @afercia
3 weeks ago

  • Keywords aria-current added

@chetan200891
3 weeks ago

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

#4 @chetan200891
3 weeks 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
3 weeks ago

  • Milestone changed from Awaiting Review to 5.0

#6 @afercia
3 weeks 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
3 weeks ago

Updated patch.

#7 @chetan200891
3 weeks 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.


3 weeks ago

#9 @sami.keijonen
2 weeks 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 2 weeks ago by sami.keijonen (previous) (diff)

#10 @afercia
2 weeks 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
2 weeks ago

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

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

Note: See TracTickets for help on using tickets.