Skip to content

Commit cf244ff

Browse files
crisbetoandrewseguin
authored andcommitted
fix(datepicker): add scope to calendar headers (#17163)
Sets a `scope` to the relevant `th` elements in the calendar header for improved accessibility. Fixes #17038. (cherry picked from commit b0c69dd)
1 parent 357d1c3 commit cf244ff

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/material/datepicker/month-view.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<table class="mat-calendar-table" role="presentation">
22
<thead class="mat-calendar-table-header">
3-
<tr><th *ngFor="let day of _weekdays" [attr.aria-label]="day.long">{{day.narrow}}</th></tr>
3+
<tr>
4+
<th scope="col" *ngFor="let day of _weekdays" [attr.aria-label]="day.long">{{day.narrow}}</th>
5+
</tr>
46
<tr><th class="mat-calendar-table-header-divider" colspan="7" aria-hidden="true"></th></tr>
57
</thead>
68
<tbody mat-calendar-body

src/material/datepicker/month-view.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ describe('MatMonthView', () => {
103103
expect(table.getAttribute('role')).toBe('presentation');
104104
});
105105

106+
it('should set the correct scope on the table headers', () => {
107+
const nonDividerHeaders = monthViewNativeElement.querySelectorAll(
108+
'.mat-calendar-table-header th:not(.mat-calendar-table-header-divider)');
109+
const dividerHeader =
110+
monthViewNativeElement.querySelector('.mat-calendar-table-header-divider')!;
111+
112+
expect(Array.from(nonDividerHeaders).every(header => {
113+
return header.getAttribute('scope') === 'col';
114+
})).toBe(true);
115+
expect(dividerHeader.hasAttribute('scope')).toBe(false);
116+
});
117+
106118
describe('calendar body', () => {
107119
let calendarBodyEl: HTMLElement;
108120
let calendarInstance: StandardMonthView;

0 commit comments

Comments
 (0)