Skip to content

Commit 1a54bc4

Browse files
committed
fix(material/datepicker): internationalize comparison date label
Updates previous fix by creating a comparisonDateLabel value in MatDatePickerIntl to allow for further accessibility in allowing the text to be converted and translated. Fixes b/195600299
1 parent 5643f12 commit 1a54bc4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/material/datepicker/calendar-body.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@
9191
{{endDateAccessibleName}}
9292
</span>
9393
<span [id]="_comparisonStartLabelId" class="mat-calendar-body-hidden-label">
94-
Sub range {{startDateAccessibleName}}
94+
{{comparisonDateAccessibleName}} {{startDateAccessibleName}}
9595
</span>
9696
<span [id]="_comparisonEndLabelId" class="mat-calendar-body-hidden-label">
97-
Sub range {{endDateAccessibleName}}
97+
{{comparisonDateAccessibleName}} {{endDateAccessibleName}}
9898
</span>

src/material/datepicker/calendar-body.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {_IdGenerator} from '@angular/cdk/a11y';
2828
import {NgClass} from '@angular/common';
2929
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
3030
import {_StructuralStylesLoader} from '@angular/material/core';
31+
import {MatDatepickerIntl} from './datepicker-intl';
3132

3233
/** Extra CSS classes that can be associated with a calendar cell. */
3334
export type MatCalendarCellCssClasses = string | string[] | Set<string> | {[key: string]: any};
@@ -99,6 +100,7 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
99100
private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
100101
private _ngZone = inject(NgZone);
101102
private _platform = inject(Platform);
103+
private _intl = inject(MatDatepickerIntl);
102104

103105
/**
104106
* Used to skip the next focus event when rendering the preview range.
@@ -204,6 +206,8 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
204206

205207
private _injector = inject(Injector);
206208

209+
comparisonDateAccessibleName = this._intl.comparisonDateLabel;
210+
207211
/**
208212
* Tracking function for rows based on their identity. Ideally we would use some sort of
209213
* key on the row, but that would require a breaking change for the `rows` input. We don't

src/material/datepicker/datepicker-intl.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export class MatDatepickerIntl {
6565
*/
6666
endDateLabel = 'End date';
6767

68+
/**
69+
* A label used to indicate that the date is part of a selected comparison
70+
* sub range of dates (used by screen readers).
71+
*/
72+
comparisonDateLabel = 'Sub range';
73+
6874
/** Formats a range of years (used for visuals). */
6975
formatYearRange(start: string, end: string): string {
7076
return `${start} \u2013 ${end}`;

0 commit comments

Comments
 (0)