@@ -68,9 +68,11 @@ export function isClickInsideMenuOverlay(target: Element): boolean {
68
68
host : {
69
69
'class' : 'cdk-menu-trigger' ,
70
70
'aria-haspopup' : 'menu' ,
71
+ '[attr.aria-expanded]' : 'isOpen()' ,
72
+ '(focusin)' : '_setHasFocus(true)' ,
73
+ '(focusout)' : '_setHasFocus(false)' ,
71
74
'(keydown)' : '_toggleOnKeydown($event)' ,
72
75
'(click)' : 'toggle()' ,
73
- '[attr.aria-expanded]' : 'isOpen()' ,
74
76
} ,
75
77
inputs : [ '_menuTemplateRef: cdkMenuTriggerFor' , 'menuPosition: cdkMenuPosition' ] ,
76
78
outputs : [ 'opened: cdkMenuOpened' , 'closed: cdkMenuClosed' ] ,
@@ -94,6 +96,7 @@ export class CdkMenuItemTrigger extends MenuTrigger implements OnDestroy {
94
96
super ( injector , menuStack ) ;
95
97
this . _registerCloseHandler ( ) ;
96
98
this . _subscribeToMouseEnter ( ) ;
99
+ this . _subscribeToHasFocus ( ) ;
97
100
}
98
101
99
102
/** Open/close the attached menu if the trigger has been configured with one */
@@ -302,4 +305,20 @@ export class CdkMenuItemTrigger extends MenuTrigger implements OnDestroy {
302
305
} ) ;
303
306
}
304
307
}
308
+
309
+ private _subscribeToHasFocus ( ) {
310
+ if ( ! this . _parentMenu ) {
311
+ this . menuStack . hasFocus . pipe ( takeUntil ( this . _destroyed ) ) . subscribe ( hasFocus => {
312
+ if ( ! hasFocus ) {
313
+ this . menuStack . closeAll ( ) ;
314
+ }
315
+ } ) ;
316
+ }
317
+ }
318
+
319
+ _setHasFocus ( hasFocus : boolean ) {
320
+ if ( ! this . _parentMenu ) {
321
+ this . menuStack . setHasFocus ( hasFocus ) ;
322
+ }
323
+ }
305
324
}
0 commit comments