Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f9320d8

Browse files
author
Subra
committed
don't replace the value if an aria tag already exists
1 parent 250632c commit f9320d8

File tree

2 files changed

+93
-9
lines changed

2 files changed

+93
-9
lines changed

src/ngAria/aria.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function $AriaProvider(){
8282

8383
var watchAttr = function(attrName, ariaName){
8484
return function(scope, elem, attr){
85-
if(config[ariaName]){
85+
if(config[ariaName] && !elem.attr(convertCase(ariaName))){
8686
if(attr[attrName]){
8787
elem.attr(convertCase(ariaName), true);
8888
}
@@ -98,7 +98,7 @@ function $AriaProvider(){
9898

9999
var watchClass = function(className, ariaName){
100100
return function(scope, elem, attr){
101-
if(config[ariaName]){
101+
if(config[ariaName] && !elem.attr(convertCase(ariaName))){
102102
var destroyWatcher = scope.$watch(function(){
103103
return elem.attr('class');
104104
}, function(){
@@ -113,7 +113,7 @@ function $AriaProvider(){
113113

114114
var watchExpr = function(expr, ariaName){
115115
return function(scope, elem, attr){
116-
if(config[ariaName]){
116+
if(config[ariaName] && !elem.attr(convertCase(ariaName))){
117117
var destroyWatch;
118118
var destroyObserve = attr.$observe(expr, function(value){
119119
if(angular.isFunction(destroyWatch)){
@@ -140,13 +140,13 @@ function $AriaProvider(){
140140
ariaInvalid: watchClass('ng-invalid', 'ariaInvalid'),
141141
ariaValue: function(scope, elem, attr, ngModel){
142142
if(config.ariaValue){
143-
if(attr.min){
143+
if(attr.min && !elem.attr('aria-valuemin')){
144144
elem.attr('aria-valuemin', attr.min);
145145
}
146-
if(attr.max){
146+
if(attr.max && !elem.attr('aria-valuemax')){
147147
elem.attr('aria-valuemax', attr.max);
148148
}
149-
if(ngModel){
149+
if(ngModel && !elem.attr('aria-valuenow')){
150150
var destroyWatcher = scope.$watch(function(){
151151
return ngModel.$modelValue;
152152
}, function(newVal){
@@ -159,7 +159,7 @@ function $AriaProvider(){
159159
}
160160
},
161161
radio: function(scope, elem, attr, ngModel){
162-
if(config.ariaChecked && ngModel){
162+
if(config.ariaChecked && ngModel && !elem.attr('aria-checked')){
163163
var destroyWatcher = scope.$watch(function(){
164164
return ngModel.$modelValue;
165165
}, function(newVal){
@@ -175,12 +175,12 @@ function $AriaProvider(){
175175
}
176176
},
177177
multiline: function(scope, elem, attr){
178-
if(config.ariaMultiline){
178+
if(config.ariaMultiline && !elem.attr('aria-multiline')){
179179
elem.attr('aria-multiline', true);
180180
}
181181
},
182182
roleChecked: function(scope, elem, attr){
183-
if(config.ariaChecked && attr.checked){
183+
if(config.ariaChecked && attr.checked && !elem.attr('aria-checked')){
184184
elem.attr('aria-checked', true);
185185
}
186186
}

test/ngAria/ariaSpec.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ describe('$aria', function(){
2929
expectAriaAttr(element, 'aria-hidden', 'true');
3030
}));
3131

32+
it('should not attach if an aria-hidden is already present', inject(function($compile, $rootScope){
33+
var element = [
34+
$compile('<div ng-show="val" aria-hidden="userSetValue"></div>')($rootScope),
35+
$compile('<div ng-hide="val" aria-hidden="userSetValue"></div>')($rootScope)
36+
];
37+
$rootScope.val = true;
38+
$rootScope.$digest();
39+
40+
expectAriaAttr(element, 'aria-hidden', 'userSetValue');
41+
}));
42+
3243
describe('disabled', function(){
3344
beforeEach(function(){
3445
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -92,6 +103,23 @@ describe('$aria', function(){
92103
expectAriaAttr(element, 'aria-checked', 'true');
93104
}));
94105

106+
it('should not attach itself if an aria-checked value is already present', inject(function($compile, $rootScope){
107+
var element = [
108+
$compile("<input type='checkbox' ng-model='val1' aria-checked='userSetValue'>")($rootScope),
109+
$compile("<input type='radio' ng-model='val2' value='one' aria-checked='userSetValue'><input type='radio' ng-model='val2' value='two'>")($rootScope),
110+
$compile("<div role='radio' ng-model='val' value='{{val3}}' aria-checked='userSetValue'></div>")($rootScope),
111+
$compile("<div role='menuitemradio' ng-model='val' value='{{val3}}' aria-checked='userSetValue'></div>")($rootScope),
112+
$compile("<div role='checkbox' checked='checked' aria-checked='userSetValue'></div>")($rootScope),
113+
$compile("<div role='menuitemcheckbox' checked='checked' aria-checked='userSetValue'></div>")($rootScope)
114+
];
115+
$rootScope.val1 = true;
116+
$rootScope.val2 = 'one';
117+
$rootScope.val3 = '1';
118+
$rootScope.$digest();
119+
120+
expectAriaAttr(element, 'aria-checked', 'userSetValue');
121+
}));
122+
95123
describe('disabled', function(){
96124
beforeEach(function(){
97125
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -136,6 +164,19 @@ describe('$aria', function(){
136164
expectAriaAttr(element, 'aria-disabled', 'true');
137165
}));
138166

167+
it('should not attach itself if an aria tag is already present', inject(function($compile, $rootScope){
168+
var element = [
169+
$compile("<input aria-disabled='userSetValue' ng-disabled='val'>")($rootScope),
170+
$compile("<textarea aria-disabled='userSetValue' ng-disabled='val'></textarea>")($rootScope),
171+
$compile("<button aria-disabled='userSetValue' ng-disabled='val'></button>")($rootScope),
172+
$compile("<select aria-disabled='userSetValue' ng-disabled='val'></select>")($rootScope)
173+
];
174+
175+
$rootScope.val = true;
176+
$rootScope.$digest();
177+
expectAriaAttr(element, 'aria-disabled', 'userSetValue');
178+
}));
179+
139180
describe('disabled', function(){
140181
beforeEach(function(){
141182
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -176,6 +217,13 @@ describe('$aria', function(){
176217
expectAriaAttr(element, 'aria-invalid', 'false');
177218
}));
178219

220+
it('should not attach itself if aria-invalid is already present', inject(function($compile, $rootScope){
221+
var element = $compile("<input ng-model='txtInput' ng-minlength='10' aria-invalid='userSetValue'>")($rootScope);
222+
$rootScope.txtInput = "LTten";
223+
$rootScope.$digest();
224+
expectAriaAttr(element, 'aria-invalid', 'userSetValue');
225+
}));
226+
179227
describe('disabled', function(){
180228
beforeEach(function(){
181229
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -222,6 +270,18 @@ describe('$aria', function(){
222270
expectAriaAttr(element, 'aria-required', 'false');
223271
}));
224272

273+
it('should not attach itself if aria-required is already present', inject(function($compile, $rootScope){
274+
var element = [
275+
$compile("<input ng-model='val' required aria-required='userSetValue'>")($rootScope),
276+
$compile("<textarea ng-model='val' required aria-required='userSetValue'></textarea>")($rootScope),
277+
$compile("<select ng-model='val' required aria-required='userSetValue'></select>")($rootScope),
278+
$compile("<input ng-model='val' ng-required='true' aria-required='userSetValue'>")($rootScope)
279+
];
280+
281+
$rootScope.$digest();
282+
expectAriaAttr(element, 'aria-required', 'userSetValue');
283+
}));
284+
225285
describe('disabled', function(){
226286
beforeEach(function(){
227287
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -259,6 +319,16 @@ describe('$aria', function(){
259319
expectAriaAttr(element, 'aria-multiline', 'true');
260320
}));
261321

322+
it('should not attach if aria-multiline is already present', inject(function($compile, $rootScope){
323+
var element = [
324+
$compile("<textarea aria-multiline='userSetValue'></textarea>")($rootScope),
325+
$compile("<div role='textbox' aria-multiline='userSetValue'></div>")($rootScope)
326+
];
327+
328+
$rootScope.$digest();
329+
expectAriaAttr(element, 'aria-multiline', 'userSetValue');
330+
}));
331+
262332
describe('disabled', function(){
263333
beforeEach(function(){
264334
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){
@@ -303,6 +373,20 @@ describe('$aria', function(){
303373
expectAriaAttr(element, 'aria-valuenow', "90");
304374
}));
305375

376+
it('should not attach if aria-value* is already present', inject(function($compile, $rootScope){
377+
var element = [
378+
$compile('<input type="range" ng-model="val" min="0" max="100" aria-valuenow="userSetValue1" aria-valuemin="userSetValue2" aria-valuemax="userSetValue3">')($rootScope),
379+
$compile('<div role="progressbar" min="0" max="100" ng-model="val" aria-valuenow="userSetValue1" aria-valuemin="userSetValue2" aria-valuemax="userSetValue3">')($rootScope),
380+
$compile('<div role="slider" min="0" max="100" ng-model="val" aria-valuenow="userSetValue1" aria-valuemin="userSetValue2" aria-valuemax="userSetValue3">')($rootScope)
381+
];
382+
$rootScope.val = 50;
383+
$rootScope.$digest();
384+
385+
expectAriaAttr(element, 'aria-valuenow', "userSetValue1");
386+
expectAriaAttr(element, 'aria-valuemin', "userSetValue2");
387+
expectAriaAttr(element, 'aria-valuemax', "userSetValue3");
388+
}));
389+
306390
describe('disabled', function(){
307391
beforeEach(function(){
308392
angular.module('ariaTest', ['ngAria']).config(function($ariaProvider){

0 commit comments

Comments
 (0)