Make WordPress Core

Opened 7 weeks ago

Closed 10 days ago

#66152 closed defect (bug) (fixed)

Default Navigation fallback menu title is ambiguous and produces a redundant accessible name

Reported by: bacoords Owned by: joedolson
Priority: normal Milestone: 7.2
Component: Editor Version: 6.3
Severity: normal Keywords: needs-copy-review has-patch has-unit-tests commit
Cc: Focuses: accessibility, ui-copy

Description

Description

On a fresh WordPress site using a block theme, when there is no existing Navigation Menu or suitable Classic Menu, WP_Navigation_Fallback::create_default_fallback() creates a published wp_navigation post titled “Navigation”:

'post_title' => _x( 'Navigation', 'Title of a Navigation menu' ),
'post_name'  => 'navigation',

Source: ​class-wp-navigation-fallback.php

This causes two related problems:

  1. In the Site Editor, “Navigation” is both the name of the Navigation screen and the title of the default menu. The generic menu title does not distinguish the menu from the screen or describe the menu's purpose.
  2. The Navigation post title is also used as the frontend navigation landmark's accessible name when the block has no explicit ariaLabel. WP_Navigation_Block_Renderer::get_navigation_name() returns the post title, which is then output as the aria-label on the <nav> element.

Relevant code:

The resulting markup includes:

<nav class="wp-block-navigation …" aria-label="Navigation">

Because the <nav> element already exposes the navigation landmark role, assistive technology may announce this as “Navigation, navigation.” The label is redundant rather than meaningfully distinguishing this landmark from other navigation landmarks.

Steps to reproduce

  1. Start with a fresh WordPress installation using a block theme, with no existing wp_navigation posts or Classic Menus.
  2. Open the Site Editor and access the Navigation screen, causing the default fallback Navigation Menu to be created.
  3. Observe that the menu is titled “Navigation,” the same name used for the screen.
  4. View the site frontend and inspect the Navigation block's <nav> element.
  5. Observe aria-label="Navigation".

Expected result

The generated menu should have a meaningful administrative title that distinguishes it from the Navigation screen, and the frontend navigation landmark should have a meaningful, non-redundant accessible name.

One possible approach would be to name the administrative object “Primary", which would use “Primary” as the accessible label.

Actual result

The generated menu is titled “Navigation,” which is ambiguous in the editor and becomes a redundant accessible name on the frontend.

Related issues

  • #47123 established that navigation landmark labels should not include the word “Navigation,” because screen readers already announce the landmark role.
  • ​Gutenberg #59706 tracks the broader need for meaningful and unique Navigation Menu names and notes that automatically generated names are currently inadequate.
  • ​Gutenberg #52488 tracks broader improvements to Navigation fallback behavior.

Change History (8)

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


7 weeks ago

#2 @joedolson
7 weeks ago

  • Milestone Awaiting Review → 7.2
  • Owner set to joedolson
  • Status new → accepted

Discussing this in the accessibility bug scrub, we think that the most reasonable solution is to change the default title to 'Main'. For practical reasons, the fallback title can never be perfect, since the actual use and intent are unknown; but because the fallback menu contains a list of pages, the most likely case is that it's a primary menu containing all pages. (​https://github.com/WordPress/wordpress-develop/blob/170944a34b6f4d76decffb5c40b5b068dc7779d8/src/wp-includes/class-wp-navigation-fallback.php#L300)

This ticket was mentioned in ​PR #13666 on ​WordPress/wordpress-develop by ​@sainathpoojary.


7 weeks ago
#3

  • Keywords has-patch has-unit-tests added

On a fresh site with a block theme, WordPress creates a default fallback navigation menu titled "Navigation".

This causes two issues:

  1. In the Site Editor, the fallback menu uses the exact same name as the Navigation screen.
  2. On the front end, this title becomes the accessible label for the navigation landmark (aria-label="Navigation" on <nav>). Screen readers announce this redundantly as "Navigation, navigation".

Following the discussion on Trac, this PR changes the default fallback menu title from "Navigation" to "Main" and updates the unit tests.

Trac ticket: https://core.trac.wordpress.org/ticket/66152

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Used for: Edge-case checks and assistance with the PR description, implementation and testing were done and reviewed by me.

#4 @joedolson
6 weeks ago

  • Keywords commit added

#5 @afercia
5 weeks ago

While testing this issue on latest trunk, I couldn't see any aria-label on the nav element. The nav element is unlebeled for me. Tested on Twenty Twenty-Four and Twenty Twenty-Five.
Is this a known issue?

Rather, I see the navigation menu unordered list being a direct child of the navigation block container unordered list so that a <ul> element is a child of another <ul> element. This is not even valid HTML and may disrupt the count and announcements of the items in the navigation.

<ul class="wp-block-navigation__container ...
    <ul class="wp-block-page-list ...

Is this a known issue?
I would appreciate the editor to produce valid and semantic markup.

#6 @joedolson
5 weeks ago

The nested ul is a known issue; see ​https://github.com/WordPress/gutenberg/issues/82207, ​https://github.com/WordPress/gutenberg/issues/60500

It happens specifically when the fallback pulls in the page list. That may also be responsible for the missing aria-label?

There are a lot of issues with how aria labels work in navigation blocks.

​@rejaulalomkhan commented on ​PR #13666:


4 weeks ago
#7

Thanks for working on this, @SainathPoojary! I tested it locally and also looked into the missing aria-label that @afercia reported in comment:5 on the ticket.

Patch Testing Report

Patch tested: ​https://github.com/WordPress/wordpress-develop/pull/13666

Environment

  • WordPress: 7.2-alpha-63166-src
  • PHP: 8.3.35
  • Server: PHP CLI (PHPUnit 9.6.38)
  • Database: MySQL 8.4.11
  • Browser: N/A (unit tests)
  • OS: macOS (wordpress-develop Docker environment)
  • Theme: Twenty Twenty-Five
  • MU Plugins: None activated
  • Plugins: None activated

Steps taken

  1. Applied only the updated tests to current trunk and ran npm run test:php -- --filter WP_Navigation_Fallback_Test → 2 failures (Navigation is not Main), as expected.
  2. Applied the full PR → WP_Navigation_Fallback_Test passes on single site and multisite (11 tests); the editor group (random order), the blocks group (715 tests) and WP_REST_Navigation_Fallback_Controller_Test also pass.
  3. With a throwaway test, deleted all wp_navigation posts, created one page, and rendered the Navigation block with do_blocks() on trunk and with the PR:
    • (no ref, the fallback is rendered): the <nav> has no aria-label on trunk or with the PR.
    • : aria-label="Navigation" on trunk, aria-label="Main" with the PR.
  4. ✅ Patch is solving the problem: the default fallback menu is created as "Main", and that name is used as the landmark label when the block references it.

Expected result

  • The default fallback menu is titled "Main", so it no longer repeats the "Navigation" screen name and gives a less redundant accessible name.

Additional Notes

  • This explains the missing label in comment:5: get_navigation_name() only reads the post title when the block has a ref. A block without ref that renders the fallback (as in a fresh block theme header before it is saved in the Site Editor) gets no aria-label at all, with or without this PR. That seems separate from this change and could be a follow-up.
  • AI assistance: Claude Code was used to run the tests; results reviewed by me.

#8 @joedolson
10 days ago

  • Resolution → fixed
  • Status accepted → closed

In 65211:

Accessibility: Improve fallback aria-label for navigation.

The fallback wp_navigation post has a default title of "Navigation", which provides the default aria-label for the menu. As all nav elements have the function of navigation, this is a strongly dis-recommended pattern for a default menu. This also leads to a duplicate name for the navigation screen and the default menu.

Change fallback name to 'Main', which is a high probability use case if a fallback menu is in use, and eliminates the naming conflict with the navigation screen.

Props bacoords, sainathpoojary, joedolson, afercia, rejaulalomkhan.
Fixes #66152.

Note: See TracTickets for help on using tickets.