1- import { Component , HostListener , ElementRef } from "@angular/core" ;
1+ import { Component , HostListener , ElementRef , AfterViewInit } from "@angular/core" ;
22import { Dialog } from "../dialog.component" ;
33import { position } from "../../utils/position" ;
4- import { getFocusElementList , isFocusInLastItem , isFocusInFirstItem } from "./../../common/tab.service" ;
4+ import { isFocusInLastItem , isFocusInFirstItem } from "./../../common/tab.service" ;
55import { I18n } from "./../../i18n/i18n.module" ;
66
77/**
@@ -19,7 +19,7 @@ import { I18n } from "./../../i18n/i18n.module";
1919 #dialog
2020 class="bx--overflow-menu-options bx--overflow-menu-options--open"
2121 role="menu"
22- (focusout )="clickClose($event )"
22+ (click )="doClose( )"
2323 [attr.aria-label]="dialogConfig.menuLabel">
2424 <ng-template
2525 [ngTemplateOutlet]="dialogConfig.content"
@@ -28,7 +28,7 @@ import { I18n } from "./../../i18n/i18n.module";
2828 </ul>
2929 `
3030} )
31- export class OverflowMenuPane extends Dialog {
31+ export class OverflowMenuPane extends Dialog implements AfterViewInit {
3232
3333 constructor ( protected elementRef : ElementRef , protected i18n : I18n ) {
3434 super ( elementRef ) ;
@@ -53,16 +53,6 @@ export class OverflowMenuPane extends Dialog {
5353 if ( ! this . dialogConfig . menuLabel ) {
5454 this . dialogConfig . menuLabel = this . i18n . get ( ) . OVERFLOW_MENU . OVERFLOW ;
5555 }
56-
57- setTimeout ( ( ) => {
58- getFocusElementList ( this . elementRef . nativeElement ) . every ( button => {
59- // Allows user to set tabindex to 0.
60- if ( button . getAttribute ( "tabindex" ) === null ) {
61- button . tabIndex = - 1 ;
62- }
63- } ) ;
64- this . listItems ( ) [ 0 ] . focus ( ) ;
65- } , 0 ) ;
6656 }
6757
6858 @HostListener ( "keydown" , [ "$event" ] )
@@ -104,20 +94,25 @@ export class OverflowMenuPane extends Dialog {
10494
10595 case "Esc" : // IE specific value
10696 case "Escape" :
97+ case "Tab" :
10798 event . stopImmediatePropagation ( ) ;
10899 this . doClose ( ) ;
109100 break ;
101+ default : break ;
110102 }
111103 }
112104
113- clickClose ( event ) {
114- // Opens menu when clicking on the menu button and stays open while navigating through the options
115- if ( this . dialogConfig . parentRef . nativeElement . firstChild . contains ( event . target ) ||
116- this . listItems ( ) . some ( button => button === event . relatedTarget ) ||
117- event . type === "focusout" && event . relatedTarget === this . dialogConfig . parentRef . nativeElement ) {
118- return ;
119- }
120- this . doClose ( ) ;
105+ ngAfterViewInit ( ) {
106+ const focusElementList = this . listItems ( ) ;
107+ focusElementList . forEach ( button => {
108+ // Allows user to set tabindex to 0.
109+ if ( button . getAttribute ( "tabindex" ) === null ) {
110+ button . tabIndex = - 1 ;
111+ }
112+ } ) ;
113+ focusElementList [ 0 ] . tabIndex = 0 ;
114+ focusElementList [ 0 ] . focus ( ) ;
115+ super . ngAfterViewInit ( ) ;
121116 }
122117
123118 protected listItems ( ) {
0 commit comments