Menu links should have id attribute

Created on 26 July 2025, 17 days ago

Problem/Motivation

The core issue πŸ“Œ Use ARIA disclosure pattern for submenu buttons in vertical toolbar orientation Needs work adds an aria-labelledby attribute to the expand/collapse buttons in the admin menu. The value is based on the id attribute of the adjacent <a> element.

When using the admin_toolbar module, that <a> element has no id attribute, so the resulting markup is aria-labelledby=undefined. That makes #3093378 ineffective.

Steps to reproduce

  1. Install Drupal core using the branch from the issue fork for πŸ“Œ Use ARIA disclosure pattern for submenu buttons in vertical toolbar orientation Needs work (or apply the patch from that issue's MR).
  2. Install the admin_toolbar module and enable it.
  3. Look at the markup for the <button> element with class="toolbar-icon toolbar-handle".

Proposed resolution

Add a few lines from toolbar_menu_navigation_links() in the core toolbar module to toolbar_tools_menu_navigation_links().

Remaining tasks

User interface changes

There are no visible changes.

The links in the admin menu will have id attributes.

In conjunction with πŸ“Œ Use ARIA disclosure pattern for submenu buttons in vertical toolbar orientation Needs work , the expand/collapse buttons in the admin menu will have aria-labelledby attributes.

API changes

None

Data model changes

None

✨ Feature request
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

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

Merge Requests

Comments & Activities

  • Issue created by @benjifisher
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    The toolbar_tools_menu_navigation_links() function in this module is clearly based on toolbar_menu_navigation_links() in the core toolbar module. I am not sure why the current version (in this module) does not set the id attribute. Perhaps it is intentional, for performance reasons.

    I checked the Git history for core:

    % git hist -S "['attributes']['id']" -- core/modules/toolbar/toolbar.module 
    ...
    * 70bed3385fe 2014-07-30 | Issue #2301317 by pwolanin, dawehner, Wim Leers, effulgentsia, YesCT, xjm, alexpott: MenuLinkNG part4: Conversion. [Alex Pott]
    * 44f76c6bcff 2014-07-30 | Revert "Issue #2301317 by pwolanin, effulgentsia, Wim Leers, dawehner, alexpott: MenuLinkNG part4: Conversion." [Alex Pott]
    * fd2db9cd352 2014-07-30 | Issue #2301317 by pwolanin, effulgentsia, Wim Leers, dawehner, alexpott: MenuLinkNG part4: Conversion. [Nathaniel Catchpole]
    ...
    * ab07a33aba4 2013-02-01 | Issue #1847198 by benjifisher, jessebeach, effulgentsia: Update the structure returned by hook_toolbar(). [webchick]
    ...
    * 7bbf113d4ed 2012-11-21 | Issue #1137920 by jessebeach, lewisnyman, tkoleary, Bojhan, webchick, benjifisher, nod_, sjbassett, kathryn531, effulgentsia, Everett Zufelt: fixed toolbar on small screen sizes and redesign toolbar for desktop. [Dries]
    

    So the id attribute is set in the core module at least since 2014. (The commits from 2012 and 2013 are some of my earliest contributions to Drupal.)

    A similar search in this module showed no results, so it seems the id attribute has never been set:

    % git hist -S "['attributes']['id']" -- admin_toolbar.module && echo done
    done
    
  • Merge request !166Set the id attribute for the admin menu β†’ (Open) created by benjifisher
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area
  • Pipeline finished with Failed
    17 days ago
    Total: 1543s
    #557314
  • Pipeline finished with Success
    16 days ago
    Total: 227s
    #557550
  • Pipeline finished with Success
    16 days ago
    Total: 383s
    #557551
  • Pipeline finished with Success
    16 days ago
    Total: 222s
    #557552
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    The tests are now passing, so MR !166 is really ready for review. (Well, eslint complains. But I did not touch any JavaScript files, and that test also has warnings on the 3.x branch.)

  • πŸ‡«πŸ‡·France dydave

    Thanks a lot @benjifisher for raising this issue and getting the work started on this!

    Just added a quick comment to the merge request, could you please take a quick look when you have some time and let us know what you think?

    Thanks in advance!

  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    Today's comments on πŸ“Œ Use ARIA disclosure pattern for submenu buttons in vertical toolbar orientation Needs work suggest using something other than the id attribute (and using text inside the button instead of an aria-lebelledby attribute). So maybe wait on this issue until we get a decision there.

  • πŸ‡«πŸ‡·France dydave

    Thanks Benjin (@benjifisher) for letting us know.

    We'll wait to see what happens in the related issue before moving forward with the suggested changes.

    Thanks again!

Production build 0.71.5 2024