Skip to content

Commit

Permalink
fix(material/datepicker): Add aria-current="date" to current date (#2…
Browse files Browse the repository at this point in the history
…3714)

(cherry picked from commit 6f1a1b7)
  • Loading branch information
ByzantineFailure authored and mmalerba committed Nov 15, 2021
1 parent 39480f8 commit ba5d36a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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

0 comments on commit ba5d36a

Please sign in to comment.