Skip to content

Commit 8178d6f

Browse files
jelbournjosephperrott
authored andcommitted
fix(input): add aria-required to inputs (#8034)
1 parent bc8560e commit 8178d6f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/lib/input/input.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,23 @@ describe('MatInput without forms', function () {
238238
expect(labelElement.getAttribute('aria-owns')).toBe(inputElement.id);
239239
});
240240

241+
it('should add aria-required reflecting the required state', () => {
242+
const fixture = TestBed.createComponent(MatInputWithRequired);
243+
fixture.detectChanges();
244+
245+
const inputElement: HTMLInputElement =
246+
fixture.debugElement.query(By.css('input')).nativeElement;
247+
248+
expect(inputElement.getAttribute('aria-required'))
249+
.toBe('false', 'Expected aria-required to reflect required state of false');
250+
251+
fixture.componentInstance.required = true;
252+
fixture.detectChanges();
253+
254+
expect(inputElement.getAttribute('aria-required'))
255+
.toBe('true', 'Expected aria-required to reflect required state of true');
256+
});
257+
241258
it('should not overwrite existing id', () => {
242259
let fixture = TestBed.createComponent(MatInputWithId);
243260
fixture.detectChanges();

src/lib/input/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ let nextUniqueId = 0;
5959
'[readonly]': 'readonly',
6060
'[attr.aria-describedby]': '_ariaDescribedby || null',
6161
'[attr.aria-invalid]': 'errorState',
62+
'[attr.aria-required]': 'required.toString()',
6263
'(blur)': '_focusChanged(false)',
6364
'(focus)': '_focusChanged(true)',
6465
'(input)': '_onInput()',

0 commit comments

Comments
 (0)