Skip to content
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
17 changes: 17 additions & 0 deletions src/lib/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ describe('MatInput without forms', function () {
expect(labelElement.getAttribute('aria-owns')).toBe(inputElement.id);
});

it('should add aria-required reflecting the required state', () => {
const fixture = TestBed.createComponent(MatInputWithRequired);
fixture.detectChanges();

const inputElement: HTMLInputElement =
fixture.debugElement.query(By.css('input')).nativeElement;

expect(inputElement.getAttribute('aria-required'))
.toBe('false', 'Expected aria-required to reflect required state of false');

fixture.componentInstance.required = true;
fixture.detectChanges();

expect(inputElement.getAttribute('aria-required'))
.toBe('true', 'Expected aria-required to reflect required state of true');
});

it('should not overwrite existing id', () => {
let fixture = TestBed.createComponent(MatInputWithId);
fixture.detectChanges();
Expand Down
1 change: 1 addition & 0 deletions src/lib/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let nextUniqueId = 0;
'[readonly]': 'readonly',
'[attr.aria-describedby]': '_ariaDescribedby || null',
'[attr.aria-invalid]': 'errorState',
'[attr.aria-required]': 'required.toString()',
'(blur)': '_focusChanged(false)',
'(focus)': '_focusChanged(true)',
'(input)': '_onInput()',
Expand Down