66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { AfterContentInit , Directive } from '@angular/core' ;
9+ import { inject , AfterContentInit , Directive , ElementRef } from '@angular/core' ;
1010import {
1111 DOWN_ARROW ,
1212 ESCAPE ,
@@ -16,6 +16,7 @@ import {
1616 TAB ,
1717 UP_ARROW ,
1818} from '../keycodes' ;
19+ import { _getEventTarget } from '../platform' ;
1920import { takeUntil } from 'rxjs/operators' ;
2021import { CdkMenuGroup } from './menu-group' ;
2122import { CDK_MENU } from './menu-interface' ;
@@ -43,6 +44,8 @@ import {CdkMenuBase} from './menu-base';
4344 ] ,
4445} )
4546export class CdkMenuBar extends CdkMenuBase implements AfterContentInit {
47+ private readonly _elementRef : ElementRef < HTMLElement > = inject ( ElementRef ) ;
48+
4649 /** The direction items in the menu flow. */
4750 override readonly orientation = 'horizontal' ;
4851
@@ -65,7 +68,9 @@ export class CdkMenuBar extends CdkMenuBase implements AfterContentInit {
6568 case DOWN_ARROW :
6669 case LEFT_ARROW :
6770 case RIGHT_ARROW :
68- if ( ! hasModifierKey ( event ) ) {
71+ const target = _getEventTarget ( event ) as HTMLElement ;
72+
73+ if ( ! hasModifierKey ( event ) && target . parentElement === this . _elementRef . nativeElement ) {
6974 const horizontalArrows = event . keyCode === LEFT_ARROW || event . keyCode === RIGHT_ARROW ;
7075 // For a horizontal menu if the left/right keys were clicked, or a vertical menu if the
7176 // up/down keys were clicked: if the current menu is open, close it then focus and open the
0 commit comments