File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -261,7 +261,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
261
261
readonly onMenuOpen: EventEmitter <void >;
262
262
// (undocumented)
263
263
_openedBy: Exclude <FocusOrigin , ' program' | null > | undefined ;
264
- openMenu(): void ;
264
+ openMenu(disableAutoFocus ? : boolean ): void ;
265
265
restoreFocus: boolean ;
266
266
toggleMenu(): void ;
267
267
triggersSubmenu(): boolean ;
Original file line number Diff line number Diff line change @@ -282,7 +282,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
282
282
}
283
283
284
284
/** Opens the menu. */
285
- openMenu ( ) : void {
285
+ openMenu ( disableAutoFocus ?: boolean ) : void {
286
286
const menu = this . menu ;
287
287
288
288
if ( this . _menuOpen || ! menu ) {
@@ -317,7 +317,7 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
317
317
this . _closingActionsSubscription = this . _menuClosingActions ( ) . subscribe ( ( ) => this . closeMenu ( ) ) ;
318
318
menu . parentMenu = this . triggersSubmenu ( ) ? this . _parentMaterialMenu : undefined ;
319
319
menu . direction = this . dir ;
320
- menu . focusFirstItem ( this . _openedBy || 'program' ) ;
320
+ if ( ! disableAutoFocus ) menu . focusFirstItem ( this . _openedBy || 'program' ) ;
321
321
this . _setIsMenuOpen ( true ) ;
322
322
323
323
if ( menu instanceof MatMenu ) {
@@ -590,7 +590,10 @@ export class MatMenuTrigger implements AfterContentInit, OnDestroy {
590
590
this . _hoverSubscription = this . _parentMaterialMenu . _hovered ( ) . subscribe ( active => {
591
591
if ( active === this . _menuItemInstance && ! active . disabled ) {
592
592
this . _openedBy = 'mouse' ;
593
- this . openMenu ( ) ;
593
+ // Open the menu, but do NOT auto-focus on first item when just hovering.
594
+ // When VoiceOver is enabled, this is particularly confusing as the focus will
595
+ // cause another hover event, and continue opening sub-menus without interaction.
596
+ this . openMenu ( true ) ;
594
597
}
595
598
} ) ;
596
599
}
Original file line number Diff line number Diff line change @@ -2510,7 +2510,7 @@ describe('MatMenu', () => {
2510
2510
} ) ,
2511
2511
) ;
2512
2512
2513
- it ( 'should not re- focus a child menu trigger when hovering another trigger' , fakeAsync ( ( ) => {
2513
+ it ( 'should preserve focus on a child menu trigger when hovering another trigger' , fakeAsync ( ( ) => {
2514
2514
dispatchFakeEvent ( instance . rootTriggerEl . nativeElement , 'mousedown' ) ;
2515
2515
instance . rootTriggerEl . nativeElement . click ( ) ;
2516
2516
fixture . detectChanges ( ) ;
@@ -2529,7 +2529,7 @@ describe('MatMenu', () => {
2529
2529
fixture . detectChanges ( ) ;
2530
2530
tick ( 500 ) ;
2531
2531
2532
- expect ( document . activeElement ) . not . toBe (
2532
+ expect ( document . activeElement ) . toBe (
2533
2533
levelOneTrigger ,
2534
2534
'Expected focus not to be returned to the initial trigger.' ,
2535
2535
) ;
You can’t perform that action at this time.
0 commit comments