Skip to content

Commit 3df4d72

Browse files
crisbetotinayuangao
authored andcommitted
fix(input): set proper role on md-error (#6259)
Sets the `alert` role on `md-error` instances, causing the messages to be read out properly by screen readers. For reference: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_alert_role
1 parent 9d3c405 commit 3df4d72

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/lib/input/input-container.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ describe('MdInputContainer with forms', () => {
814814
});
815815
}));
816816

817+
it('should set the proper role on the error messages', () => {
818+
testComponent.formControl.markAsTouched();
819+
fixture.detectChanges();
820+
821+
expect(containerEl.querySelector('md-error')!.getAttribute('role')).toBe('alert');
822+
});
823+
817824
it('sets the aria-describedby to reference errors when in error state', () => {
818825
let hintId = fixture.debugElement.query(By.css('.mat-hint')).nativeElement.getAttribute('id');
819826
let describedBy = inputEl.getAttribute('aria-describedby');

src/lib/input/input-container.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export class MdHint {
102102
selector: 'md-error, mat-error',
103103
host: {
104104
'class': 'mat-input-error',
105+
'role': 'alert',
105106
'[attr.id]': 'id',
106107
}
107108
})

0 commit comments

Comments
 (0)