@@ -110,10 +110,10 @@ function $AriaProvider() {
110
110
config = angular . extend ( config , newConfig ) ;
111
111
} ;
112
112
113
- function watchExpr ( attrName , ariaAttr , negate ) {
113
+ function watchExpr ( attrName , ariaAttr , nodeBlackList , negate ) {
114
114
return function ( scope , elem , attr ) {
115
115
var ariaCamelName = attr . $normalize ( ariaAttr ) ;
116
- if ( config [ ariaCamelName ] && ! attr [ ariaCamelName ] ) {
116
+ if ( config [ ariaCamelName ] && ! isNodeOneOf ( elem , nodeBlackList ) && ! attr [ ariaCamelName ] ) {
117
117
scope . $watch ( attr [ attrName ] , function ( boolVal ) {
118
118
if ( negate ) {
119
119
boolVal = ! boolVal ;
@@ -124,6 +124,12 @@ function $AriaProvider() {
124
124
} ;
125
125
}
126
126
127
+ function isNodeOneOf ( elem , nodeTypeArray ) {
128
+ if ( nodeTypeArray . indexOf ( elem [ 0 ] . nodeName ) !== - 1 ) {
129
+ return true ;
130
+ }
131
+ }
132
+
127
133
/**
128
134
* @ngdoc service
129
135
* @name $aria
@@ -175,22 +181,24 @@ function $AriaProvider() {
175
181
config : function ( key ) {
176
182
return config [ key ] ;
177
183
} ,
178
- $$watchExpr : watchExpr
184
+ $$watchExpr : watchExpr ,
185
+ nodeBlackList : [ 'BUTTON' , 'A' , 'INPUT' , 'TEXTAREA' , 'SELECT' ] ,
186
+ isNodeOneOf : isNodeOneOf
179
187
} ;
180
188
} ;
181
189
}
182
190
183
191
184
192
ngAriaModule . directive ( 'ngShow' , [ '$aria' , function ( $aria ) {
185
- return $aria . $$watchExpr ( 'ngShow' , 'aria-hidden' , true ) ;
193
+ return $aria . $$watchExpr ( 'ngShow' , 'aria-hidden' , [ ] , true ) ;
186
194
} ] )
187
195
. directive ( 'ngHide' , [ '$aria' , function ( $aria ) {
188
- return $aria . $$watchExpr ( 'ngHide' , 'aria-hidden' , false ) ;
196
+ return $aria . $$watchExpr ( 'ngHide' , 'aria-hidden' , [ ] , false ) ;
189
197
} ] )
190
198
. directive ( 'ngModel' , [ '$aria' , function ( $aria ) {
191
199
192
- function shouldAttachAttr ( attr , normalizedAttr , elem ) {
193
- return $aria . config ( normalizedAttr ) && ! elem . attr ( attr ) ;
200
+ function shouldAttachAttr ( attr , normalizedAttr , elem , nodeBlacklist ) {
201
+ return ! $aria . isNodeOneOf ( elem , ( nodeBlacklist || [ ] ) ) && $aria . config ( normalizedAttr ) && ! elem . attr ( attr ) ;
194
202
}
195
203
196
204
function shouldAttachRole ( role , elem ) {
@@ -203,6 +211,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
203
211
204
212
return ( ( type || role ) === 'checkbox' || role === 'menuitemcheckbox' ) ? 'checkbox' :
205
213
( ( type || role ) === 'radio' || role === 'menuitemradio' ) ? 'radio' :
214
+ ( type || role ) === 'radiogroup' ? 'radiogroup' :
206
215
( type === 'range' || role === 'progressbar' || role === 'slider' ) ? 'range' :
207
216
( type || role ) === 'textbox' || elem [ 0 ] . nodeName === 'TEXTAREA' ? 'multiline' : '' ;
208
217
}
@@ -216,15 +225,15 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
216
225
217
226
return {
218
227
pre : function ( scope , elem , attr , ngModel ) {
219
- if ( shape === 'checkbox' && attr . type !== 'checkbox' ) {
228
+ if ( shape === 'checkbox' ) {
220
229
//Use the input[checkbox] $isEmpty implementation for elements with checkbox roles
221
230
ngModel . $isEmpty = function ( value ) {
222
231
return value === false ;
223
232
} ;
224
233
}
225
234
} ,
226
235
post : function ( scope , elem , attr , ngModel ) {
227
- var needsTabIndex = shouldAttachAttr ( 'tabindex' , 'tabindex' , elem ) ;
236
+ var needsTabIndex = shouldAttachAttr ( 'tabindex' , 'tabindex' , elem , $aria . nodeBlackList ) ;
228
237
229
238
function ngAriaWatchModelValue ( ) {
230
239
return ngModel . $modelValue ;
@@ -250,21 +259,29 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
250
259
}
251
260
252
261
switch ( shape ) {
262
+ case 'radiogroup' :
263
+ if ( needsTabIndex ) {
264
+ elem . attr ( 'tabindex' , 0 ) ;
265
+ }
266
+ break ;
253
267
case 'radio' :
254
268
case 'checkbox' :
255
269
if ( shouldAttachRole ( shape , elem ) ) {
256
270
elem . attr ( 'role' , shape ) ;
257
271
}
258
- if ( shouldAttachAttr ( 'aria-checked' , 'ariaChecked' , elem ) ) {
272
+ if ( shouldAttachAttr ( 'aria-checked' , 'ariaChecked' , elem , [ 'INPUT' ] ) ) {
259
273
scope . $watch ( ngAriaWatchModelValue , shape === 'radio' ?
260
274
getRadioReaction ( ) : ngAriaCheckboxReaction ) ;
261
275
}
276
+ if ( needsTabIndex ) {
277
+ elem . attr ( 'tabindex' , 0 ) ;
278
+ }
262
279
break ;
263
280
case 'range' :
264
281
if ( shouldAttachRole ( shape , elem ) ) {
265
282
elem . attr ( 'role' , 'slider' ) ;
266
283
}
267
- if ( $aria . config ( 'ariaValue' ) ) {
284
+ if ( ! $aria . isNodeOneOf ( elem , [ 'INPUT' ] ) && $aria . config ( 'ariaValue' ) ) {
268
285
if ( attr . min && ! elem . attr ( 'aria-valuemin' ) ) {
269
286
elem . attr ( 'aria-valuemin' , attr . min ) ;
270
287
}
@@ -277,6 +294,9 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
277
294
} ) ;
278
295
}
279
296
}
297
+ if ( needsTabIndex ) {
298
+ elem . attr ( 'tabindex' , 0 ) ;
299
+ }
280
300
break ;
281
301
case 'multiline' :
282
302
if ( shouldAttachAttr ( 'aria-multiline' , 'ariaMultiline' , elem ) ) {
@@ -285,11 +305,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
285
305
break ;
286
306
}
287
307
288
- if ( needsTabIndex ) {
289
- elem . attr ( 'tabindex' , 0 ) ;
290
- }
291
-
292
- if ( ngModel . $validators . required && shouldAttachAttr ( 'aria-required' , 'ariaRequired' , elem ) ) {
308
+ if ( ngModel . $validators . required && shouldAttachAttr ( 'aria-required' , 'ariaRequired' , elem , $aria . nodeBlackList ) ) {
293
309
scope . $watch ( function ngAriaRequiredWatch ( ) {
294
310
return ngModel . $error . required ;
295
311
} , function ngAriaRequiredReaction ( newVal ) {
@@ -310,7 +326,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
310
326
} ;
311
327
} ] )
312
328
. directive ( 'ngDisabled' , [ '$aria' , function ( $aria ) {
313
- return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' ) ;
329
+ return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' , $aria . nodeBlackList ) ;
314
330
} ] )
315
331
. directive ( 'ngMessages' , function ( ) {
316
332
return {
@@ -329,33 +345,29 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
329
345
compile : function ( elem , attr ) {
330
346
var fn = $parse ( attr . ngClick , /* interceptorFn */ null , /* expensiveChecks */ true ) ;
331
347
return function ( scope , elem , attr ) {
332
-
333
- var nodeBlackList = [ 'BUTTON' , 'A' , 'INPUT' , 'TEXTAREA' ] ;
334
-
335
- function isNodeOneOf ( elem , nodeTypeArray ) {
336
- if ( nodeTypeArray . indexOf ( elem [ 0 ] . nodeName ) !== - 1 ) {
337
- return true ;
348
+
349
+ if ( ! $aria . isNodeOneOf ( elem , $aria . nodeBlackList ) ) {
350
+
351
+ if ( ! elem . attr ( 'role' ) ) {
352
+ elem . attr ( 'role' , 'button' ) ;
353
+ }
354
+
355
+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
356
+ elem . attr ( 'tabindex' , 0 ) ;
338
357
}
339
- }
340
- if ( ! elem . attr ( 'role' ) && ! isNodeOneOf ( elem , nodeBlackList ) ) {
341
- elem . attr ( 'role' , 'button' ) ;
342
- }
343
-
344
- if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
345
- elem . attr ( 'tabindex' , 0 ) ;
346
- }
347
358
348
- if ( $aria . config ( 'bindKeypress' ) && ! attr . ngKeypress && ! isNodeOneOf ( elem , nodeBlackList ) ) {
349
- elem . on ( 'keypress' , function ( event ) {
350
- var keyCode = event . which || event . keyCode ;
351
- if ( keyCode === 32 || keyCode === 13 ) {
352
- scope . $apply ( callback ) ;
353
- }
359
+ if ( $aria . config ( 'bindKeypress' ) && ! attr . ngKeypress ) {
360
+ elem . on ( 'keypress' , function ( event ) {
361
+ var keyCode = event . which || event . keyCode ;
362
+ if ( keyCode === 32 || keyCode === 13 ) {
363
+ scope . $apply ( callback ) ;
364
+ }
354
365
355
- function callback ( ) {
356
- fn ( scope , { $event : event } ) ;
357
- }
358
- } ) ;
366
+ function callback ( ) {
367
+ fn ( scope , { $event : event } ) ;
368
+ }
369
+ } ) ;
370
+ }
359
371
}
360
372
} ;
361
373
}
0 commit comments