Skip to content

Commit d6fd163

Browse files
committed
fix some tests with check on menubar parent
1 parent c17ef68 commit d6fd163

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/cdk/menu/menu-bar.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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';
1010
import {
1111
DOWN_ARROW,
1212
ESCAPE,
@@ -16,6 +16,7 @@ import {
1616
TAB,
1717
UP_ARROW,
1818
} from '../keycodes';
19+
import {_getEventTarget} from '../platform';
1920
import {takeUntil} from 'rxjs/operators';
2021
import {CdkMenuGroup} from './menu-group';
2122
import {CDK_MENU} from './menu-interface';
@@ -43,6 +44,8 @@ import {CdkMenuBase} from './menu-base';
4344
],
4445
})
4546
export 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

Comments
 (0)