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

Commit 961e9ee

Browse files
author
Subra
committed
fix(ngAria): handle non-string model values
Fix for #10212. Compare the string value of the model so that aria-checked will be properly applied to type=radio in the case where the model is a number Closes #10212
1 parent e6a2527 commit 961e9ee

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/ngAria/aria.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
228228
if (needsTabIndex) {
229229
needsTabIndex = false;
230230
return function ngAriaRadioReaction(newVal) {
231-
var boolVal = newVal === attr.value;
231+
var boolVal = (angular.isUndefined(newVal) ? newVal : newVal.toString()) === attr.value;
232232
elem.attr('aria-checked', boolVal);
233233
elem.attr('tabindex', 0 - !boolVal);
234234
};
235235
} else {
236236
return function ngAriaRadioReaction(newVal) {
237-
elem.attr('aria-checked', newVal === attr.value);
237+
elem.attr('aria-checked', (angular.isUndefined(newVal) ? newVal : newVal.toString()) === attr.value);
238238
};
239239
}
240240
}

test/ngAria/ariaSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ describe('$aria', function() {
9898
expect(element.eq(1).attr('aria-checked')).toBe('true');
9999
});
100100

101+
it('should handle non-string model values', function() {
102+
var element = $compile('<input type="radio" ng-model="val" value="0">' +
103+
'<input type="radio" ng-model="val" value="1">')(scope);
104+
105+
scope.$apply("val=0");
106+
expect(element.eq(0).attr('aria-checked')).toBe('true');
107+
expect(element.eq(1).attr('aria-checked')).toBe('false');
108+
109+
scope.$apply("val=1");
110+
expect(element.eq(0).attr('aria-checked')).toBe('false');
111+
expect(element.eq(1).attr('aria-checked')).toBe('true');
112+
});
113+
101114
it('should attach itself to role="radio"', function() {
102115
scope.$apply("val = 'one'");
103116
compileInput('<div role="radio" ng-model="val" value="{{val}}"></div>');

0 commit comments

Comments
 (0)