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
5 changes: 3 additions & 2 deletions src/material/datepicker/calendar-header.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
<div class="mat-calendar-controls">
<button mat-button type="button" class="mat-calendar-period-button"
(click)="currentPeriodClicked()" [attr.aria-label]="periodButtonLabel"
[attr.aria-describedby]="_buttonDescriptionId"
cdkAriaLive="polite">
{{periodButtonText}}
<span [attr.id]="_buttonDescriptionId">{{periodButtonText}}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just [id] should work

<div class="mat-calendar-arrow"
[class.mat-calendar-invert]="calendar.currentView != 'month'"></div>
[class.mat-calendar-invert]="calendar.currentView !== 'month'"></div>
</button>

<div class="mat-calendar-spacer"></div>
Expand Down
8 changes: 8 additions & 0 deletions src/material/datepicker/calendar-header.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ describe('MatCalendarHeader', () => {
expect(calendarInstance.currentView).toBe('multi-year');
expect(periodButton.textContent).toContain('FAKE_YEAR');
});

it('should label and describe period button for assistive technology', () => {
const description = periodButton.querySelector('span[id]');
expect(periodButton.hasAttribute('aria-label')).toBe(true);
expect(periodButton.hasAttribute('aria-describedby')).toBe(true);
expect(periodButton.getAttribute('aria-describedby')).toBe(description?.getAttribute('id')!);
});

});

describe('calendar with minDate only', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/material/datepicker/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import {MAT_SINGLE_DATE_SELECTION_MODEL_PROVIDER, DateRange} from './date-select
*/
export type MatCalendarView = 'month' | 'year' | 'multi-year';

/** Counter used to generate unique IDs. */
let uniqueId = 0;

/** Default header for MatCalendar */
@Component({
selector: 'mat-calendar-header',
Expand All @@ -59,6 +62,8 @@ export type MatCalendarView = 'month' | 'year' | 'multi-year';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class MatCalendarHeader<D> {
_buttonDescriptionId = `mat-calendar-button-${uniqueId++}`;

constructor(private _intl: MatDatepickerIntl,
@Inject(forwardRef(() => MatCalendar)) public calendar: MatCalendar<D>,
@Optional() private _dateAdapter: DateAdapter<D>,
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export declare type MatCalendarCellCssClasses = string | string[] | Set<string>
};

export declare class MatCalendarHeader<D> {
_buttonDescriptionId: string;
calendar: MatCalendar<D>;
get nextButtonLabel(): string;
get periodButtonLabel(): string;
Expand Down