Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/datepicker): adds aria-describedby value for comparison date range #29910

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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]="_comparisonStartLabelId" class="mat-calendar-body-hidden-label">
{{comparisonDateAccessibleName}} {{startDateAccessibleName}}
</span>
<span [id]="_comparisonEndLabelId" class="mat-calendar-body-hidden-label">
{{comparisonDateAccessibleName}} {{endDateAccessibleName}}
</span>
24 changes: 24 additions & 0 deletions 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 @@ -204,6 +206,8 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView

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 Down Expand Up @@ -467,6 +471,16 @@ 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._comparisonStartLabelId}-${this._comparisonEndLabelId}`;
essjay05 marked this conversation as resolved.
Show resolved Hide resolved
} else if (value === this.comparisonStart) {
return this._comparisonStartLabelId;
} else if (value === this.comparisonEnd) {
return this._comparisonEndLabelId;
}
}
return null;
}

Expand Down Expand Up @@ -607,6 +621,16 @@ export class MatCalendarBody<D = any> implements OnChanges, OnDestroy, AfterView

return null;
}

private _id = `mat-calendar-body-${calendarBodyId++}`;

_startDateLabelId = `${this._id}-start-date`;

_endDateLabelId = `${this._id}-end-date`;

_comparisonStartLabelId = `${this._id}-comparison-start-date`;

_comparisonEndLabelId = `${this._id}-comparison-end-date`;
}

/** Checks whether a node is a table cell element. */
Expand Down
6 changes: 6 additions & 0 deletions src/material/datepicker/datepicker-intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export class MatDatepickerIntl {
*/
endDateLabel = 'End date';

/**
* A label used to indicate that the date is part of a selected comparison
* sub range of dates (used by screen readers).
*/
comparisonDateLabel = 'Sub range';
essjay05 marked this conversation as resolved.
Show resolved Hide resolved

/** Formats a range of years (used for visuals). */
formatYearRange(start: string, end: string): string {
return `${start} \u2013 ${end}`;
Expand Down
Loading