Skip to content

Commit 2a5bb04

Browse files
committed
fix(material/datepicker): adds aria-describedby value for comparison date range
Updates Angular Components Datepicker component calendar-body to check for a comparison start and comparison end date value and implement aria-describedby id values to correspond with hidden spans that describe a sub range start and a sub range end date if it does exist so that it is read by the screenreader and improves accessibility. Fixes b/195600299
1 parent ea0d1ba commit 2a5bb04

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/material/datepicker/calendar-body.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@
9090
<span [id]="_endDateLabelId" class="mat-calendar-body-hidden-label">
9191
{{endDateAccessibleName}}
9292
</span>
93+
<span [id]="_comparisonStartLabelId" class="mat-calendar-body-hidden-label">
94+
Sub range {{startDateAccessibleName}}
95+
</span>
96+
<span [id]="_comparisonEndLabelId" class="mat-calendar-body-hidden-label">
97+
Sub range {{endDateAccessibleName}}
98+
</span>

src/material/datepicker/calendar-body.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,22 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
451451
}
452452

453453
if (this.startValue === value && this.endValue === value) {
454-
return `${this._startDateLabelId} ${this._endDateLabelId}`;
454+
return `${this._startDateLabelId}-${this._endDateLabelId}`;
455455
} else if (this.startValue === value) {
456456
return this._startDateLabelId;
457457
} else if (this.endValue === value) {
458458
return this._endDateLabelId;
459459
}
460+
461+
if (this.comparisonStart !== null && this.comparisonEnd !== null) {
462+
if (value === this.comparisonStart && value === this.comparisonEnd) {
463+
return `${this._comparisonStartLabelId}-${this._comparisonEndLabelId}`;
464+
} else if (value === this.comparisonStart) {
465+
return this._comparisonStartLabelId;
466+
} else if (value === this.comparisonEnd) {
467+
return this._comparisonEndLabelId;
468+
}
469+
}
460470
return null;
461471
}
462472

@@ -603,6 +613,10 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
603613
_startDateLabelId = `${this._id}-start-date`;
604614

605615
_endDateLabelId = `${this._id}-end-date`;
616+
617+
_comparisonStartLabelId = `${this._id}-comparison-start-date`;
618+
619+
_comparisonEndLabelId = `${this._id}-comparison-end-date`;
606620
}
607621

608622
/** Checks whether a node is a table cell element. */

0 commit comments

Comments
 (0)