Skip to content

feat(material/datepicker): Add aria-current="date" to current date #23714

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

Merged
merged 1 commit into from
Nov 15, 2021
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
1 change: 1 addition & 0 deletions src/material/datepicker/calendar-body.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
[attr.aria-label]="item.ariaLabel"
[attr.aria-disabled]="!item.enabled || null"
[attr.aria-selected]="_isSelected(item.compareValue)"
[attr.aria-current]="todayValue === item.compareValue ? 'date' : null"
(click)="_cellClicked(item, $event)"
[style.width]="_cellWidth"
[style.paddingTop]="_cellPadding"
Expand Down
38 changes: 36 additions & 2 deletions src/material/datepicker/calendar-body.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,43 @@ describe('MatCalendarBody', () => {
});

it('highlights today', () => {
const todayCell = calendarBodyNativeElement.querySelector('.mat-calendar-body-today')!;
const todayCells = calendarBodyNativeElement.querySelectorAll('.mat-calendar-body-today')!;
expect(todayCells.length).toBe(1);

const todayCell = todayCells[0];

expect(todayCell).not.toBeNull();
expect(todayCell.innerHTML.trim()).toBe('3');
expect(todayCell.textContent!.trim()).toBe('3');
});

it('sets aria-current="date" on today', () => {
const todayCells = calendarBodyNativeElement.querySelectorAll(
'[aria-current="date"] .mat-calendar-body-today',
)!;
expect(todayCells.length).toBe(1);

const todayCell = todayCells[0];

expect(todayCell).not.toBeNull();
expect(todayCell.textContent!.trim()).toBe('3');
});

it('does not highlight today if today is not within the scope', () => {
testComponent.todayValue = 100000;
fixture.detectChanges();

const todayCell = calendarBodyNativeElement.querySelector('.mat-calendar-body-today')!;
expect(todayCell).toBeNull();
});

it('does not set aria-current="date" on any cell if today is not ' + 'the scope', () => {
testComponent.todayValue = 100000;
fixture.detectChanges();

const todayCell = calendarBodyNativeElement.querySelector(
'[aria-current="date"] .mat-calendar-body-today',
)!;
expect(todayCell).toBeNull();
});

it('highlights selected', () => {
Expand Down