@@ -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 ) {
@@ -216,15 +224,15 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
216
224
217
225
return {
218
226
pre : function ( scope , elem , attr , ngModel ) {
219
- if ( shape === 'checkbox' && attr . type !== 'checkbox' ) {
227
+ if ( shape === 'checkbox' ) {
220
228
//Use the input[checkbox] $isEmpty implementation for elements with checkbox roles
221
229
ngModel . $isEmpty = function ( value ) {
222
230
return value === false ;
223
231
} ;
224
232
}
225
233
} ,
226
234
post : function ( scope , elem , attr , ngModel ) {
227
- var needsTabIndex = shouldAttachAttr ( 'tabindex' , 'tabindex' , elem ) ;
235
+ var needsTabIndex = shouldAttachAttr ( 'tabindex' , 'tabindex' , elem , $aria . nodeBlackList ) ;
228
236
229
237
function ngAriaWatchModelValue ( ) {
230
238
return ngModel . $modelValue ;
@@ -255,7 +263,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
255
263
if ( shouldAttachRole ( shape , elem ) ) {
256
264
elem . attr ( 'role' , shape ) ;
257
265
}
258
- if ( shouldAttachAttr ( 'aria-checked' , 'ariaChecked' , elem ) ) {
266
+ if ( shouldAttachAttr ( 'aria-checked' , 'ariaChecked' , elem , [ 'INPUT' ] ) ) {
259
267
scope . $watch ( ngAriaWatchModelValue , shape === 'radio' ?
260
268
getRadioReaction ( ) : ngAriaCheckboxReaction ) ;
261
269
}
@@ -264,7 +272,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
264
272
if ( shouldAttachRole ( shape , elem ) ) {
265
273
elem . attr ( 'role' , 'slider' ) ;
266
274
}
267
- if ( $aria . config ( 'ariaValue' ) ) {
275
+ if ( ! $aria . isNodeOneOf ( elem , [ 'INPUT' ] ) && $aria . config ( 'ariaValue' ) ) {
268
276
if ( attr . min && ! elem . attr ( 'aria-valuemin' ) ) {
269
277
elem . attr ( 'aria-valuemin' , attr . min ) ;
270
278
}
@@ -289,7 +297,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
289
297
elem . attr ( 'tabindex' , 0 ) ;
290
298
}
291
299
292
- if ( ngModel . $validators . required && shouldAttachAttr ( 'aria-required' , 'ariaRequired' , elem ) ) {
300
+ if ( ngModel . $validators . required && shouldAttachAttr ( 'aria-required' , 'ariaRequired' , elem , $aria . nodeBlackList ) ) {
293
301
scope . $watch ( function ngAriaRequiredWatch ( ) {
294
302
return ngModel . $error . required ;
295
303
} , function ngAriaRequiredReaction ( newVal ) {
@@ -310,7 +318,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
310
318
} ;
311
319
} ] )
312
320
. directive ( 'ngDisabled' , [ '$aria' , function ( $aria ) {
313
- return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' ) ;
321
+ return $aria . $$watchExpr ( 'ngDisabled' , 'aria-disabled' , $aria . nodeBlackList ) ;
314
322
} ] )
315
323
. directive ( 'ngMessages' , function ( ) {
316
324
return {
@@ -329,33 +337,29 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
329
337
compile : function ( elem , attr ) {
330
338
var fn = $parse ( attr . ngClick , /* interceptorFn */ null , /* expensiveChecks */ true ) ;
331
339
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 ;
340
+
341
+ if ( ! $aria . isNodeOneOf ( elem , $aria . nodeBlackList ) ) {
342
+
343
+ if ( ! elem . attr ( 'role' ) ) {
344
+ elem . attr ( 'role' , 'button' ) ;
345
+ }
346
+
347
+ if ( $aria . config ( 'tabindex' ) && ! elem . attr ( 'tabindex' ) ) {
348
+ elem . attr ( 'tabindex' , 0 ) ;
338
349
}
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
350
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
- }
351
+ if ( $aria . config ( 'bindKeypress' ) && ! attr . ngKeypress ) {
352
+ elem . on ( 'keypress' , function ( event ) {
353
+ var keyCode = event . which || event . keyCode ;
354
+ if ( keyCode === 32 || keyCode === 13 ) {
355
+ scope . $apply ( callback ) ;
356
+ }
354
357
355
- function callback ( ) {
356
- fn ( scope , { $event : event } ) ;
357
- }
358
- } ) ;
358
+ function callback ( ) {
359
+ fn ( scope , { $event : event } ) ;
360
+ }
361
+ } ) ;
362
+ }
359
363
}
360
364
} ;
361
365
}
0 commit comments