Skip to content
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
6 changes: 6 additions & 0 deletions src/material/datepicker/calendar-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@
<span [id]="_endDateLabelId" class="mat-calendar-body-hidden-label">
{{endDateAccessibleName}}
</span>
<span [id]="_comparisonStartDateLabelId" class="mat-calendar-body-hidden-label">
{{comparisonDateAccessibleName}} {{startDateAccessibleName}}
</span>
<span [id]="_comparisonEndDateLabelId" class="mat-calendar-body-hidden-label">
{{comparisonDateAccessibleName}} {{endDateAccessibleName}}
</span>
25 changes: 24 additions & 1 deletion src/material/datepicker/calendar-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {_IdGenerator} from '@angular/cdk/a11y';
import {NgClass} from '@angular/common';
import {_CdkPrivateStyleLoader} from '@angular/cdk/private';
import {_StructuralStylesLoader} from '@angular/material/core';
import {MatDatepickerIntl} from './datepicker-intl';

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

/**
* Used to skip the next focus event when rendering the preview range.
Expand Down Expand Up @@ -200,10 +202,18 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
/** ID for the end date label. */
_endDateLabelId: string;

/** ID for the comparison start date label. */
_comparisonStartDateLabelId: string;

/** ID for the comparison end date label. */
_comparisonEndDateLabelId: string;

private _didDragSinceMouseDown = false;

private _injector = inject(Injector);

comparisonDateAccessibleName = this._intl.comparisonDateLabel;

/**
* Tracking function for rows based on their identity. Ideally we would use some sort of
* key on the row, but that would require a breaking change for the `rows` input. We don't
Expand All @@ -216,7 +226,9 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
constructor() {
const idGenerator = inject(_IdGenerator);
this._startDateLabelId = idGenerator.getId('mat-calendar-body-start-');
this._endDateLabelId = idGenerator.getId('mat-calendar-body-start-');
this._endDateLabelId = idGenerator.getId('mat-calendar-body-end-');
this._comparisonStartDateLabelId = idGenerator.getId('mat-calendar-body-comparison-start-');
this._comparisonEndDateLabelId = idGenerator.getId('mat-calendar-body-comparison-end-');

inject(_CdkPrivateStyleLoader).load(_StructuralStylesLoader);

Expand Down Expand Up @@ -467,6 +479,17 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
} else if (this.endValue === value) {
return this._endDateLabelId;
}

if (this.comparisonStart !== null && this.comparisonEnd !== null) {
if (value === this.comparisonStart && value === this.comparisonEnd) {
return `${this._comparisonStartDateLabelId} ${this._comparisonEndDateLabelId}`;
} else if (value === this.comparisonStart) {
return this._comparisonStartDateLabelId;
} else if (value === this.comparisonEnd) {
return this._comparisonEndDateLabelId;
}
}

return null;
}

Expand Down
5 changes: 5 additions & 0 deletions src/material/datepicker/datepicker-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export class MatDatepickerIntl {
*/
endDateLabel = 'End date';

/**
* A label for the Comparison date of a range of dates (used by screen readers).
*/
comparisonDateLabel = 'Comparison range';

/** Formats a range of years (used for visuals). */
formatYearRange(start: string, end: string): string {
return `${start} \u2013 ${end}`;
Expand Down
5 changes: 5 additions & 0 deletions tools/public_api_guard/material/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView
_cellClicked(cell: MatCalendarCell, event: MouseEvent): void;
_cellPadding: string;
_cellWidth: string;
// (undocumented)
comparisonDateAccessibleName: string;
comparisonEnd: number | null;
_comparisonEndDateLabelId: string;
comparisonStart: number | null;
_comparisonStartDateLabelId: string;
readonly dragEnded: EventEmitter<MatCalendarUserEvent<D | null>>;
readonly dragStarted: EventEmitter<MatCalendarUserEvent<D>>;
// (undocumented)
Expand Down Expand Up @@ -480,6 +484,7 @@ export class MatDatepickerIntl {
calendarLabel: string;
readonly changes: Subject<void>;
closeCalendarLabel: string;
comparisonDateLabel: string;
// @deprecated
endDateLabel: string;
formatYearRange(start: string, end: string): string;
Expand Down
Loading