Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(cdkMenu): Accessibility Issue (context-) menu #30666

Closed
1 task
zwif opened this issue Mar 20, 2025 · 0 comments · Fixed by #30680
Closed
1 task

bug(cdkMenu): Accessibility Issue (context-) menu #30666

zwif opened this issue Mar 20, 2025 · 0 comments · Fixed by #30680
Assignees
Labels
area: cdk/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@zwif
Copy link

zwif commented Mar 20, 2025

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When a (context-) menu is opened and then closed, the aria-controls attribute on the host is not cleared.

When opening the menu, following happens:

  • menu is injected in the DOM with an id like cdk-menu-1 (the number increases with each time opening the context menu)
  • Additionally, the trigger element will get an aria-controls="cdk-menu-1" attribute

When the menu closes:

  • menu is removed from the DOM
  • the aria-controls attribute stays ❌

This is an accessibility error, since it references an id which is not present in the DOM. Tools for automated accessibility testing will report this, like accessibilityinsights in the attached screenshot from the angular material cdk menu example page:
Image

Reproduction

StackBlitz link: https://stackblitz.com/edit/bt5mp6y6 (Fork from the stackblitz of the first example of the cdkMenu page https://material.angular.io/cdk/menu/examples)
Steps to reproduce:

  1. open the contextmenu
  2. close the contextmenu
    => When inspecting the DOM you can see the aria-controls attribute, but the referenced id is not present in the DOM.

Expected Behavior

aria-controls attribute is removed when the referenced menu is removed from the DOM.

Actual Behavior

aria-controls attribute is present referencing an id not present in the DOM.

Environment

  • CDK/Material: 19.2.4
@zwif zwif added the needs triage This issue needs to be triaged by the team label Mar 20, 2025
@zwif zwif changed the title bug(cdkMenu): Accessibility Issue Contextmenu bug(cdkMenu): Accessibility Issue (context-) menu Mar 20, 2025
@crisbeto crisbeto self-assigned this Mar 21, 2025
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: cdk/menu and removed needs triage This issue needs to be triaged by the team labels Mar 21, 2025
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 21, 2025
Fixes that we were keeping the current menu ID on the context menu trigger instead of clearing it.

Fixes angular#30666.
crisbeto added a commit that referenced this issue Mar 21, 2025
Fixes that we were keeping the current menu ID on the context menu trigger instead of clearing it.

Fixes #30666.

(cherry picked from commit 985721c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/menu P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants