Skip to content

Commit ad1aaaf

Browse files
committed
fixup! fix(cdk/table): set default role of table to 'table'
1 parent 4afb18d commit ad1aaaf

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/cdk/table/cell.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ export class CdkFooterCell extends BaseCdkCell {
184184
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
185185
super(columnDef, elementRef);
186186
if (columnDef._table?._elementRef.nativeElement.nodeType === 1) {
187-
const role = columnDef._table._elementRef.nativeElement
188-
.getAttribute('role') === 'table' ? 'cell' : 'gridcell';
187+
const tableRole = columnDef._table._elementRef.nativeElement
188+
.getAttribute('role');
189+
const role = (tableRole === 'grid' || tableRole === 'treegrid') ? 'gridcell' : 'cell';
189190
elementRef.nativeElement.setAttribute('role', role);
190191
}
191192
}
@@ -202,8 +203,9 @@ export class CdkCell extends BaseCdkCell {
202203
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
203204
super(columnDef, elementRef);
204205
if (columnDef._table?._elementRef.nativeElement.nodeType === 1) {
205-
const role = columnDef._table._elementRef.nativeElement
206-
.getAttribute('role') === 'table' ? 'cell' : 'gridcell';
206+
const tableRole = columnDef._table._elementRef.nativeElement
207+
.getAttribute('role');
208+
const role = (tableRole === 'grid' || tableRole === 'treegrid') ? 'gridcell' : 'cell';
207209
elementRef.nativeElement.setAttribute('role', role);
208210
}
209211
}

src/cdk/table/table.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,19 @@ describe('CdkTable', () => {
611611
it('should not clobber an existing table role', () => {
612612
setupTableTestApp(CustomRoleCdkTableApp);
613613
expect(tableElement.getAttribute('role')).toBe('treegrid');
614+
615+
expect(getHeaderRows(tableElement)[0].getAttribute('role')).toBe('row');
616+
const header = getHeaderRows(tableElement)[0];
617+
getHeaderCells(header).forEach(cell => {
618+
expect(cell.getAttribute('role')).toBe('columnheader');
619+
});
620+
621+
getRows(tableElement).forEach(row => {
622+
expect(row.getAttribute('role')).toBe('row');
623+
getCells(row).forEach(cell => {
624+
expect(cell.getAttribute('role')).toBe('gridcell');
625+
});
626+
});
614627
});
615628

616629
it('should throw an error if two column definitions have the same name', () => {

0 commit comments

Comments
 (0)