Skip to content

Commit 9f01912

Browse files
committed
fix(datepicker): range input label pointing to non-existent id (#19031)
This is something that I put the code in for in the beginning, but forgot to wire up. The `aria-owns` of the `label` in the `mat-form-field` needs to point to the id of the start input, but it didn't have an id.
1 parent ef54582 commit 9f01912

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/material/datepicker/date-range-input-parts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ const _MatDateRangeInputBase:
174174
'(input)': '_onInput($event.target.value)',
175175
'(change)': '_onChange()',
176176
'(keydown)': '_onKeydown($event)',
177+
'[attr.id]': '_rangeInput.id',
177178
'[attr.aria-labelledby]': '_rangeInput._ariaLabelledBy',
178179
'[attr.aria-describedby]': '_rangeInput._ariaDescribedBy',
179180
'[attr.aria-haspopup]': '_rangeInput.rangePicker ? "dialog" : null',

src/material/datepicker/date-range-input.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ describe('MatDatepicker', () => {
140140
expect(rangeInput.classList).toContain(hideClass);
141141
});
142142

143+
it('should point the label aria-owns to the id of the start input', () => {
144+
const fixture = createComponent(StandardRangePicker);
145+
fixture.detectChanges();
146+
const label = fixture.nativeElement.querySelector('label');
147+
const start = fixture.componentInstance.start.nativeElement;
148+
149+
expect(start.id).toBeTruthy();
150+
expect(label.getAttribute('aria-owns')).toBe(start.id);
151+
});
152+
143153
it('should point the input aria-labelledby to the form field label', () => {
144154
const fixture = createComponent(StandardRangePicker);
145155
fixture.detectChanges();

src/material/datepicker/datepicker-input.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import {
1313
Inject,
1414
Input,
1515
Optional,
16-
Output,
17-
AfterViewInit,
1816
} from '@angular/core';
1917
import {
2018
NG_VALIDATORS,

0 commit comments

Comments
 (0)