bug(cdk/menu): Trigger does not update ARIA values correctly in OnPush
components
#27725
Closed
1 task
Labels
Accessibility
This issue is related to accessibility (a11y)
area: cdk/menu
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Is this a regression?
The previous version in which this bug was not present was
No response
Description
I recently noticed that the menu trigger (
CdkMenuTrigger
) misbehaves when insideOnPush
components because theOnPush
change detection strategy will cascade into child directives implicitly. Specifically, thearia-expanded
property will not correctly follow the open sub-menu. After some investigation this seems to simply be caused by theCdkMenuTrigger
not usingdetectChanges()
ormarkForCheck()
from theChangeDetectorRef
after opening and closing the menu overlay. The attachment state of the menu overlay is used to populatearia-expanded
directly.This can be worked around by having the
OnPush
parent listen to(opened)
and(closed)
events emitted by the trigger, but that is not very scalable since each menu item would then require two additional handlers inside everyOnPush
component.I will be sending a pull request that will make the
CdkMenuTrigger
call relevant methods from theChangeDetectorRef
at appropriate times to support being placed inOnPush
components.Reproduction
StackBlitz link: https://stackblitz.com/edit/components-issue-uc7xxl
Note: In the StackBlitz the style of menu items is changed based on the
aria-expanded
property of the element. If the element hasaria-expanded
set totrue
the item will appear with a black background and white text. This is supposed to make it easy to see howaria-expanded
updates.Steps to reproduce:
CdkMenu
or aCdkMenuBar
in a component usingChangeDetectionStrategy.OnPush
Expected Behavior
When hovering over another item with a sub-menu, the
aria-expanded
property of the newly hovered item should be set totrue
and that of the previous item should be set tofalse
. Thearia-expanded
property should betrue
for the item that has an open sub-menu at all times. When clicking outside the menu all sub-menus should close andaria-expanded
should befalse
for all items in the menu.Actual Behavior
The
aria-expanded
property continues to betrue
on the initially clicked element regardless of the item hovered and where the open sub-menu is. It also continues to betrue
for an item even when all sub-menus are closed.Environment
The text was updated successfully, but these errors were encountered: