@@ -112,14 +112,10 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
112112
113113 // Turn off an existing document click handler
114114 angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
115- $elm . off ( 'keyup' , checkKeyUp ) ;
116- $elm . off ( 'keydown' , checkKeyDown ) ;
117115
118116 // Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
119117 $timeout ( function ( ) {
120118 angular . element ( document ) . on ( docEventType , applyHideMenu ) ;
121- $elm . on ( 'keyup' , checkKeyUp ) ;
122- $elm . on ( 'keydown' , checkKeyDown ) ;
123119 } ) ;
124120 } ;
125121
@@ -144,8 +140,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
144140 }
145141
146142 angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
147- $elm . off ( 'keyup' , checkKeyUp ) ;
148- $elm . off ( 'keydown' , checkKeyDown ) ;
149143 } ;
150144
151145 $scope . $on ( 'hide-menu' , function ( event , args ) {
@@ -173,28 +167,22 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
173167 }
174168 } ;
175169
176- // close menu on ESC and keep tab cyclical
177- var checkKeyUp = function ( event ) {
178- if ( event . keyCode === 27 ) {
179- $scope . hideMenu ( ) ;
180- }
181- } ;
182-
183- var checkKeyDown = function ( event ) {
170+ $scope . checkKeyDown = function ( event ) {
184171 var setFocus = function ( elm ) {
185172 elm . focus ( ) ;
186173 event . preventDefault ( ) ;
187- return false ;
188174 } ;
189- if ( event . keyCode === 9 ) {
175+ if ( event . keyCode === uiGridConstants . keymap . ESC ) {
176+ $scope . hideMenu ( ) ;
177+ } else if ( event . keyCode === uiGridConstants . keymap . TAB ) {
190178 var firstMenuItem , lastMenuItem ;
191179 var menuItemButtons = $elm [ 0 ] . querySelectorAll ( 'button:not(.ng-hide)' ) ;
192180 if ( menuItemButtons . length > 0 ) {
193181 firstMenuItem = menuItemButtons [ 0 ] ;
194182 lastMenuItem = menuItemButtons [ menuItemButtons . length - 1 ] ;
195- if ( event . target === lastMenuItem && ! event . shiftKey ) {
183+ if ( event . target . parentElement . id === lastMenuItem . parentElement . id && ! event . shiftKey ) {
196184 setFocus ( firstMenuItem ) ;
197- } else if ( event . target === firstMenuItem && event . shiftKey ) {
185+ } else if ( event . target . parentElement . id === firstMenuItem . parentElement . id && event . shiftKey ) {
198186 setFocus ( lastMenuItem ) ;
199187 }
200188 }
@@ -212,8 +200,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
212200 $scope . $on ( '$destroy' , function unbindEvents ( ) {
213201 angular . element ( $window ) . off ( 'resize' , applyHideMenu ) ;
214202 angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
215- $elm . off ( 'keyup' , checkKeyUp ) ;
216- $elm . off ( 'keydown' , checkKeyDown ) ;
217203 } ) ;
218204
219205 if ( uiGridCtrl ) {
0 commit comments