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

Commit 187e431

Browse files
Marcy Suttoncaitp
Marcy Sutton
authored andcommitted
feat(ngAria): announce ngMessages with aria-live
By including the `ngAria` module, `ngMessages` will automatically include the aria-live attribute with an assertive voice, allowing validation messages to be spoken throuhg a screenreader. Closes #9834
1 parent 91834bc commit 187e431

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/ngAria/aria.js

+11
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,16 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
238238
.directive('ngDisabled', ['$aria', function($aria) {
239239
return $aria.$$watchExpr('ngDisabled', 'aria-disabled');
240240
}])
241+
.directive('ngMessages', function() {
242+
return {
243+
restrict: 'A',
244+
require: '?ngMessages',
245+
link: function(scope, elem, attr, ngMessages) {
246+
if (!elem.attr('aria-live')) {
247+
elem.attr('aria-live', 'assertive');
248+
}
249+
}
250+
};
251+
})
241252
.directive('ngClick', ngAriaTabindex)
242253
.directive('ngDblclick', ngAriaTabindex);

test/ngAria/ariaSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ describe('$aria', function() {
400400
});
401401
});
402402

403+
describe('announcing ngMessages', function() {
404+
beforeEach(injectScopeAndCompiler);
405+
406+
it('should attach aria-live', function() {
407+
var element = [
408+
$compile('<div ng-messages="myForm.myName.$error">')(scope)
409+
];
410+
expectAriaAttrOnEachElement(element, 'aria-live', "assertive");
411+
});
412+
});
403413

404414
describe('aria-value when disabled', function() {
405415
beforeEach(configAriaProvider({

0 commit comments

Comments
 (0)