Skip to content

Commit cfe37d1

Browse files
authored
fix(datepicker): add role to date range input (#19717)
Adds a `group` role to the date range input since it groups two inputs.
1 parent 8934feb commit cfe37d1

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ export interface MatDateRangeInputParent<D> {
5555
_startInput: MatDateRangeInputPartBase<D>;
5656
_endInput: MatDateRangeInputPartBase<D>;
5757
_groupDisabled: boolean;
58-
_ariaDescribedBy: string | null;
59-
_ariaLabelledBy: string | null;
6058
_handleChildValueChange: () => void;
6159
_openDatepicker: () => void;
6260
}
@@ -187,8 +185,6 @@ const _MatDateRangeInputBase:
187185
'(change)': '_onChange()',
188186
'(keydown)': '_onKeydown($event)',
189187
'[attr.id]': '_rangeInput.id',
190-
'[attr.aria-labelledby]': '_rangeInput._ariaLabelledBy',
191-
'[attr.aria-describedby]': '_rangeInput._ariaDescribedBy',
192188
'[attr.aria-haspopup]': '_rangeInput.rangePicker ? "dialog" : null',
193189
'[attr.aria-owns]': '(_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null',
194190
'[attr.min]': '_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null',
@@ -269,8 +265,6 @@ export class MatStartDate<D> extends _MatDateRangeInputBase<D> implements CanUpd
269265
'(input)': '_onInput($event.target.value)',
270266
'(change)': '_onChange()',
271267
'(keydown)': '_onKeydown($event)',
272-
'[attr.aria-labelledby]': '_rangeInput._ariaLabelledBy',
273-
'[attr.aria-describedby]': '_rangeInput._ariaDescribedBy',
274268
'[attr.aria-haspopup]': '_rangeInput.rangePicker ? "dialog" : null',
275269
'[attr.aria-owns]': '(_rangeInput.rangePicker?.opened && _rangeInput.rangePicker.id) || null',
276270
'[attr.min]': '_getMinDate() ? _dateAdapter.toIso8601(_getMinDate()) : null',

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ describe('MatDateRangeInput', () => {
8989
expect(fixture.componentInstance.end.nativeElement.getAttribute('type')).toBe('text');
9090
});
9191

92+
it('should set the correct role on the range input', () => {
93+
const fixture = createComponent(StandardRangePicker);
94+
fixture.detectChanges();
95+
const rangeInput = fixture.nativeElement.querySelector('.mat-date-range-input');
96+
expect(rangeInput.getAttribute('role')).toBe('group');
97+
});
98+
9299
it('should mark the entire range input as disabled if both inputs are disabled', () => {
93100
const fixture = createComponent(StandardRangePicker);
94101
fixture.detectChanges();
@@ -151,26 +158,24 @@ describe('MatDateRangeInput', () => {
151158
expect(label.getAttribute('aria-owns')).toBe(start.id);
152159
});
153160

154-
it('should point the input aria-labelledby to the form field label', () => {
161+
it('should point the range input aria-labelledby to the form field label', () => {
155162
const fixture = createComponent(StandardRangePicker);
156163
fixture.detectChanges();
157164
const labelId = fixture.nativeElement.querySelector('label').id;
158-
const {start, end} = fixture.componentInstance;
165+
const rangeInput = fixture.nativeElement.querySelector('.mat-date-range-input');
159166

160167
expect(labelId).toBeTruthy();
161-
expect(start.nativeElement.getAttribute('aria-labelledby')).toBe(labelId);
162-
expect(end.nativeElement.getAttribute('aria-labelledby')).toBe(labelId);
168+
expect(rangeInput.getAttribute('aria-labelledby')).toBe(labelId);
163169
});
164170

165-
it('should point the input aria-labelledby to the form field hint element', () => {
171+
it('should point the range input aria-labelledby to the form field hint element', () => {
166172
const fixture = createComponent(StandardRangePicker);
167173
fixture.detectChanges();
168174
const labelId = fixture.nativeElement.querySelector('.mat-hint').id;
169-
const {start, end} = fixture.componentInstance;
175+
const rangeInput = fixture.nativeElement.querySelector('.mat-date-range-input');
170176

171177
expect(labelId).toBeTruthy();
172-
expect(start.nativeElement.getAttribute('aria-describedby')).toBe(labelId);
173-
expect(end.nativeElement.getAttribute('aria-describedby')).toBe(labelId);
178+
expect(rangeInput.getAttribute('aria-describedby')).toBe(labelId);
174179
});
175180

176181
it('should float the form field label when either input is focused', () => {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ let nextUniqueId = 0;
4848
'class': 'mat-date-range-input',
4949
'[class.mat-date-range-input-hide-placeholders]': '_shouldHidePlaceholders()',
5050
'[attr.id]': 'null',
51+
'role': 'group',
52+
'[attr.aria-labelledby]': '_ariaLabelledBy',
53+
'[attr.aria-describedby]': '_ariaDescribedBy',
5154
},
5255
changeDetection: ChangeDetectionStrategy.OnPush,
5356
encapsulation: ViewEncapsulation.None,

0 commit comments

Comments
 (0)