@@ -43,8 +43,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
43
43
templateUrl : 'ui-grid/uiGridMenu' ,
44
44
replace : false ,
45
45
link : function ( $scope , $elm , $attrs , uiGridCtrl ) {
46
- var menuMid ;
47
- var $animate ;
48
46
var gridMenuMaxHeight ;
49
47
50
48
$scope . dynamicStyles = '' ;
@@ -99,17 +97,22 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
99
97
100
98
// Turn off an existing document click handler
101
99
angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
100
+ $elm . off ( 'keyup' , checkKeyUp ) ;
101
+ $elm . off ( 'keydown' , checkKeyDown ) ;
102
102
103
103
// Turn on the document click handler, but in a timeout so it doesn't apply to THIS click if there is one
104
104
$timeout ( function ( ) {
105
105
angular . element ( document ) . on ( docEventType , applyHideMenu ) ;
106
+ $elm . on ( 'keyup' , checkKeyUp ) ;
107
+ $elm . on ( 'keydown' , checkKeyDown ) ;
108
+
106
109
} ) ;
107
110
//automatically set the focus to the first button element in the now open menu.
108
111
gridUtil . focus . bySelector ( $elm , 'button[type=button]' , true ) ;
109
112
} ;
110
113
111
114
112
- $scope . hideMenu = function ( event , args ) {
115
+ $scope . hideMenu = function ( event ) {
113
116
if ( $scope . shown ) {
114
117
/*
115
118
* In order to animate cleanly we animate the addition of ng-hide, then use a $timeout to
@@ -129,6 +132,8 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
129
132
}
130
133
131
134
angular . element ( document ) . off ( 'click touchstart' , applyHideMenu ) ;
135
+ $elm . off ( 'keyup' , checkKeyUp ) ;
136
+ $elm . off ( 'keydown' , checkKeyDown ) ;
132
137
} ;
133
138
134
139
$scope . $on ( 'hide-menu' , function ( event , args ) {
@@ -149,6 +154,34 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
149
154
}
150
155
} ;
151
156
157
+ // close menu on ESC and keep tab cyclical
158
+ var checkKeyUp = function ( event ) {
159
+ if ( event . keyCode === 27 ) {
160
+ $scope . hideMenu ( ) ;
161
+ }
162
+ } ;
163
+
164
+ var checkKeyDown = function ( event ) {
165
+ var setFocus = function ( elm ) {
166
+ elm . focus ( ) ;
167
+ event . preventDefault ( ) ;
168
+ return false ;
169
+ } ;
170
+ if ( event . keyCode === 9 ) {
171
+ var firstMenuItem , lastMenuItem ;
172
+ var menuItemButtons = $elm [ 0 ] . querySelectorAll ( 'button:not(.ng-hide)' ) ;
173
+ if ( menuItemButtons . length > 0 ) {
174
+ firstMenuItem = menuItemButtons [ 0 ] ;
175
+ lastMenuItem = menuItemButtons [ menuItemButtons . length - 1 ] ;
176
+ if ( event . target === lastMenuItem && ! event . shiftKey ) {
177
+ setFocus ( firstMenuItem ) ;
178
+ } else if ( event . target === firstMenuItem && event . shiftKey ) {
179
+ setFocus ( lastMenuItem ) ;
180
+ }
181
+ }
182
+ }
183
+ } ;
184
+
152
185
if ( typeof ( $scope . autoHide ) === 'undefined' || $scope . autoHide === undefined ) {
153
186
$scope . autoHide = true ;
154
187
}
@@ -171,12 +204,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
171
204
}
172
205
173
206
$scope . $on ( '$destroy' , $scope . $on ( uiGridConstants . events . ITEM_DRAGGING , applyHideMenu ) ) ;
174
- } ,
175
-
176
-
177
- controller : [ '$scope' , '$element' , '$attrs' , function ( $scope , $element , $attrs ) {
178
- var self = this ;
179
- } ]
207
+ }
180
208
} ;
181
209
182
210
return uiGridMenu ;
@@ -196,15 +224,12 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
196
224
leaveOpen : '=' ,
197
225
screenReaderOnly : '='
198
226
} ,
199
- require : [ '?^uiGrid' , '^uiGridMenu' ] ,
227
+ require : [ '?^uiGrid' ] ,
200
228
templateUrl : 'ui-grid/uiGridMenuItem' ,
201
229
replace : false ,
202
- compile : function ( $elm , $attrs ) {
230
+ compile : function ( ) {
203
231
return {
204
- pre : function ( $scope , $elm , $attrs , controllers ) {
205
- var uiGridCtrl = controllers [ 0 ] ,
206
- uiGridMenuCtrl = controllers [ 1 ] ;
207
-
232
+ pre : function ( $scope , $elm ) {
208
233
if ( $scope . templateUrl ) {
209
234
gridUtil . getTemplate ( $scope . templateUrl )
210
235
. then ( function ( contents ) {
@@ -216,8 +241,7 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
216
241
}
217
242
} ,
218
243
post : function ( $scope , $elm , $attrs , controllers ) {
219
- var uiGridCtrl = controllers [ 0 ] ,
220
- uiGridMenuCtrl = controllers [ 1 ] ;
244
+ var uiGridCtrl = controllers [ 0 ] ;
221
245
222
246
// TODO(c0bra): validate that shown and active are functions if they're defined. An exception is already thrown above this though
223
247
// if (typeof($scope.shown) !== 'undefined' && $scope.shown && typeof($scope.shown) !== 'function') {
0 commit comments