Skip to content

fix(material/form-field): fix duplicate announcement of form controls #27102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2023
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
11 changes: 0 additions & 11 deletions src/material/chips/chip-grid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,17 +526,6 @@ describe('MDC-based MatChipGrid', () => {
expect(spy).toHaveBeenCalled();
subscription.unsubscribe();
});

it('should point the label id to the chip input', () => {
const label = fixture.nativeElement.querySelector('label');
const input = fixture.nativeElement.querySelector('input');

fixture.detectChanges();

expect(label.getAttribute('for')).toBeTruthy();
expect(label.getAttribute('for')).toBe(input.getAttribute('id'));
expect(label.getAttribute('aria-owns')).toBe(input.getAttribute('id'));
});
});

describe('with chip remove', () => {
Expand Down
10 changes: 0 additions & 10 deletions src/material/datepicker/date-range-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ describe('MatDateRangeInput', () => {
expect(rangeInput.classList).toContain(hideClass);
});

it('should point the label aria-owns to the <mat-date-range-input/>', () => {
const fixture = createComponent(StandardRangePicker);
fixture.detectChanges();
const label = fixture.nativeElement.querySelector('label');
const rangeInput = fixture.componentInstance.rangeInput;

expect(rangeInput.id).toBeTruthy();
expect(label.getAttribute('aria-owns')).toBe(rangeInput.id);
});

it('should point the range input aria-labelledby to the form field label', () => {
const fixture = createComponent(StandardRangePicker);
fixture.detectChanges();
Expand Down
6 changes: 1 addition & 5 deletions src/material/form-field/form-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@
as part of the label, and we don't want to spend resources on walking through projected content
to set `aria-hidden`. Nor do we want to set `aria-labelledby` on every form control if we could
simply link the label to the control using the label `for` attribute.

*Note*: We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
read if it comes before the control in the DOM.
-->
<label matFormFieldFloatingLabel
[floating]="_shouldLabelFloat()"
[monitorResize]="_hasOutline()"
*ngIf="_hasFloatingLabel()"
[id]="_labelId"
[attr.for]="_control.id"
[attr.aria-owns]="_control.id">
[attr.for]="_control.id">
<ng-content select="mat-label"></ng-content>
<!--
We set the required marker as a separate element, in order to make it easier to target if
Expand Down
14 changes: 0 additions & 14 deletions src/material/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,6 @@ describe('MatMdcInput without forms', () => {
expect(inputElement.id).toEqual(labelElement.getAttribute('for')!);
}));

it('should add aria-owns to the label for the associated control', fakeAsync(() => {
let fixture = createComponent(MatInputTextTestController);
fixture.detectChanges();

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

expect(labelElement.getAttribute('aria-owns')).toBe(inputElement.id);
}));

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