Skip to content

Commit 989d017

Browse files
committed
fixup! fix(cdk/table): set default role of table to 'table'
1 parent 5113b56 commit 989d017

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/cdk/table/cell.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
ContentChild,
1212
Directive,
1313
ElementRef,
14-
Input,
15-
TemplateRef,
1614
Inject,
15+
Input,
1716
Optional,
17+
TemplateRef,
1818
} from '@angular/core';
1919
import {CanStick, CanStickCtor, mixinHasStickyInput} from './can-stick';
2020
import {CDK_TABLE} from './tokens';
@@ -178,12 +178,14 @@ export class CdkHeaderCell extends BaseCdkCell {
178178
selector: 'cdk-footer-cell, td[cdk-footer-cell]',
179179
host: {
180180
'class': 'cdk-footer-cell',
181-
'role': 'cell',
182181
},
183182
})
184183
export class CdkFooterCell extends BaseCdkCell {
185184
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
186185
super(columnDef, elementRef);
186+
const role = columnDef._table._elementRef.nativeElement
187+
.getAttribute('role') === 'table' ? 'cell' : 'gridcell';
188+
elementRef.nativeElement.setAttribute('role', role);
187189
}
188190
}
189191

@@ -192,11 +194,13 @@ export class CdkFooterCell extends BaseCdkCell {
192194
selector: 'cdk-cell, td[cdk-cell]',
193195
host: {
194196
'class': 'cdk-cell',
195-
'role': 'cell',
196197
},
197198
})
198199
export class CdkCell extends BaseCdkCell {
199200
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
200201
super(columnDef, elementRef);
202+
const role = columnDef._table._elementRef.nativeElement
203+
.getAttribute('role') === 'table' ? 'cell' : 'gridcell';
204+
elementRef.nativeElement.setAttribute('role', role);
201205
}
202206
}

src/cdk/table/table.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('CdkTable', () => {
107107
});
108108

109109
it('with the right accessibility roles', () => {
110-
expect(tableElement.getAttribute('role')).toBe('grid');
110+
expect(tableElement.getAttribute('role')).toBe('table');
111111

112112
expect(getHeaderRows(tableElement)[0].getAttribute('role')).toBe('row');
113113
const header = getHeaderRows(tableElement)[0];
@@ -118,7 +118,7 @@ describe('CdkTable', () => {
118118
getRows(tableElement).forEach(row => {
119119
expect(row.getAttribute('role')).toBe('row');
120120
getCells(row).forEach(cell => {
121-
expect(cell.getAttribute('role')).toBe('gridcell');
121+
expect(cell.getAttribute('role')).toBe('cell');
122122
});
123123
});
124124
});

0 commit comments

Comments
 (0)