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,6 @@ import { I18n } from "./../../i18n/i18n.module";
1919 #dialog
2020 class="bx--overflow-menu-options bx--overflow-menu-options--open"
2121 role="menu"
22- (focusout)="menuClose($event)"
2322 (click)="doClose()"
2423 [attr.aria-label]="dialogConfig.menuLabel">
2524 <ng-template
@@ -29,7 +28,7 @@ import { I18n } from "./../../i18n/i18n.module";
2928 </ul>
3029 `
3130} )
32- export class OverflowMenuPane extends Dialog {
31+ export class OverflowMenuPane extends Dialog implements AfterViewInit {
3332
3433 constructor ( protected elementRef : ElementRef , protected i18n : I18n ) {
3534 super ( elementRef ) ;
@@ -54,16 +53,6 @@ export class OverflowMenuPane extends Dialog {
5453 if ( ! this . dialogConfig . menuLabel ) {
5554 this . dialogConfig . menuLabel = this . i18n . get ( ) . OVERFLOW_MENU . OVERFLOW ;
5655 }
57-
58- setTimeout ( ( ) => {
59- getFocusElementList ( this . elementRef . nativeElement ) . every ( button => {
60- // Allows user to set tabindex to 0.
61- if ( button . getAttribute ( "tabindex" ) === null ) {
62- button . tabIndex = - 1 ;
63- }
64- } ) ;
65- this . listItems ( ) [ 0 ] . focus ( ) ;
66- } , 0 ) ;
6756 }
6857
6958 @HostListener ( "keydown" , [ "$event" ] )
@@ -105,16 +94,25 @@ export class OverflowMenuPane extends Dialog {
10594
10695 case "Esc" : // IE specific value
10796 case "Escape" :
97+ case "Tab" :
10898 event . stopImmediatePropagation ( ) ;
10999 this . doClose ( ) ;
110100 break ;
101+ default : break ;
111102 }
112103 }
113104
114- menuClose ( event ) {
115- if ( this . listItems ( ) . some ( button => button === document . activeElement ) ) {
116- this . doClose ( ) ;
117- }
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 ( ) ;
118116 }
119117
120118 protected listItems ( ) {
0 commit comments