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

fix(ngAria): do not set aria attributes on input[type="hidden"] #16367

Merged
merged 1 commit into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ngAria/aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
.directive('ngModel', ['$aria', function($aria) {

function shouldAttachAttr(attr, normalizedAttr, elem, allowBlacklistEls) {
return $aria.config(normalizedAttr) && !elem.attr(attr) && (allowBlacklistEls || !isNodeOneOf(elem, nodeBlackList));
return $aria.config(normalizedAttr) &&
!elem.attr(attr) &&
(allowBlacklistEls || !isNodeOneOf(elem, nodeBlackList)) &&
(elem.attr('type') !== 'hidden' || elem[0].nodeName !== 'INPUT');
}

function shouldAttachRole(role, elem) {
Expand Down
15 changes: 15 additions & 0 deletions test/ngAria/ariaSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,21 @@ describe('$aria', function() {
scope.$apply('txtInput=\'LTten\'');
expect(element.attr('aria-invalid')).toBe('userSetValue');
});

it('should not attach if input is type="hidden"', function() {
compileElement('<input type="hidden" ng-model="txtInput">');
expect(element.attr('aria-invalid')).toBeUndefined();
});


it('should attach aria-invalid to custom control that is type="hidden"', function() {
compileElement('<div ng-model="txtInput" type="hidden" role="textbox" ng-minlength="10"></div>');
scope.$apply('txtInput=\'LTten\'');
expect(element.attr('aria-invalid')).toBe('true');

scope.$apply('txtInput=\'morethantencharacters\'');
expect(element.attr('aria-invalid')).toBe('false');
});
});

describe('aria-invalid when disabled', function() {
Expand Down