@@ -112,14 +112,10 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
112
112
113
113
// Turn off an existing document click handler
114
114
angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
115
- $elm . off ( 'keyup' , checkKeyUp ) ;
116
- $elm . off ( 'keydown' , checkKeyDown ) ;
117
115
118
116
// Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
119
117
$timeout ( function ( ) {
120
118
angular . element ( document ) . on ( docEventType , applyHideMenu ) ;
121
- $elm . on ( 'keyup' , checkKeyUp ) ;
122
- $elm . on ( 'keydown' , checkKeyDown ) ;
123
119
} ) ;
124
120
} ;
125
121
@@ -144,8 +140,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
144
140
}
145
141
146
142
angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
147
- $elm . off ( 'keyup' , checkKeyUp ) ;
148
- $elm . off ( 'keydown' , checkKeyDown ) ;
149
143
} ;
150
144
151
145
$scope . $on ( 'hide-menu' , function ( event , args ) {
@@ -173,28 +167,22 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
173
167
}
174
168
} ;
175
169
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 ) {
184
171
var setFocus = function ( elm ) {
185
172
elm . focus ( ) ;
186
173
event . preventDefault ( ) ;
187
- return false ;
188
174
} ;
189
- if ( event . keyCode === 9 ) {
175
+ if ( event . keyCode === uiGridConstants . keymap . ESC ) {
176
+ $scope . hideMenu ( ) ;
177
+ } else if ( event . keyCode === uiGridConstants . keymap . TAB ) {
190
178
var firstMenuItem , lastMenuItem ;
191
179
var menuItemButtons = $elm [ 0 ] . querySelectorAll ( 'button:not(.ng-hide)' ) ;
192
180
if ( menuItemButtons . length > 0 ) {
193
181
firstMenuItem = menuItemButtons [ 0 ] ;
194
182
lastMenuItem = menuItemButtons [ menuItemButtons . length - 1 ] ;
195
- if ( event . target === lastMenuItem && ! event . shiftKey ) {
183
+ if ( event . target . parentElement . id === lastMenuItem . parentElement . id && ! event . shiftKey ) {
196
184
setFocus ( firstMenuItem ) ;
197
- } else if ( event . target === firstMenuItem && event . shiftKey ) {
185
+ } else if ( event . target . parentElement . id === firstMenuItem . parentElement . id && event . shiftKey ) {
198
186
setFocus ( lastMenuItem ) ;
199
187
}
200
188
}
@@ -212,8 +200,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
212
200
$scope . $on ( '$destroy' , function unbindEvents ( ) {
213
201
angular . element ( $window ) . off ( 'resize' , applyHideMenu ) ;
214
202
angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
215
- $elm . off ( 'keyup' , checkKeyUp ) ;
216
- $elm . off ( 'keydown' , checkKeyDown ) ;
217
203
} ) ;
218
204
219
205
if ( uiGridCtrl ) {
0 commit comments