Skip to content

Commit 0496cfe

Browse files
authored
Revert "fix(cdk/table): set default role of table to 'table' (#22491)" (#23150)
This reverts commit 71d75f4.
1 parent ae968ab commit 0496cfe

File tree

4 files changed

+9
-30
lines changed

4 files changed

+9
-30
lines changed

src/cdk/table/cell.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {
1111
ContentChild,
1212
Directive,
1313
ElementRef,
14-
Inject,
1514
Input,
16-
Optional,
1715
TemplateRef,
16+
Inject,
17+
Optional,
1818
} from '@angular/core';
1919
import {CanStick, CanStickCtor, mixinHasStickyInput} from './can-stick';
2020
import {CDK_TABLE} from './tokens';
@@ -178,17 +178,12 @@ export class CdkHeaderCell extends BaseCdkCell {
178178
selector: 'cdk-footer-cell, td[cdk-footer-cell]',
179179
host: {
180180
'class': 'cdk-footer-cell',
181+
'role': 'gridcell',
181182
},
182183
})
183184
export class CdkFooterCell extends BaseCdkCell {
184185
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
185186
super(columnDef, elementRef);
186-
if (columnDef._table?._elementRef.nativeElement.nodeType === 1) {
187-
const tableRole = columnDef._table._elementRef.nativeElement
188-
.getAttribute('role');
189-
const role = (tableRole === 'grid' || tableRole === 'treegrid') ? 'gridcell' : 'cell';
190-
elementRef.nativeElement.setAttribute('role', role);
191-
}
192187
}
193188
}
194189

@@ -197,16 +192,11 @@ export class CdkFooterCell extends BaseCdkCell {
197192
selector: 'cdk-cell, td[cdk-cell]',
198193
host: {
199194
'class': 'cdk-cell',
195+
'role': 'gridcell',
200196
},
201197
})
202198
export class CdkCell extends BaseCdkCell {
203199
constructor(columnDef: CdkColumnDef, elementRef: ElementRef) {
204200
super(columnDef, elementRef);
205-
if (columnDef._table?._elementRef.nativeElement.nodeType === 1) {
206-
const tableRole = columnDef._table._elementRef.nativeElement
207-
.getAttribute('role');
208-
const role = (tableRole === 'grid' || tableRole === 'treegrid') ? 'gridcell' : 'cell';
209-
elementRef.nativeElement.setAttribute('role', role);
210-
}
211201
}
212202
}

src/cdk/table/table.spec.ts

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

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

113113
expect(getHeaderRows(tableElement)[0].getAttribute('role')).toBe('row');
114114
const header = getHeaderRows(tableElement)[0];
@@ -119,7 +119,7 @@ describe('CdkTable', () => {
119119
getRows(tableElement).forEach(row => {
120120
expect(row.getAttribute('role')).toBe('row');
121121
getCells(row).forEach(cell => {
122-
expect(cell.getAttribute('role')).toBe('cell');
122+
expect(cell.getAttribute('role')).toBe('gridcell');
123123
});
124124
});
125125
});
@@ -622,19 +622,6 @@ describe('CdkTable', () => {
622622
it('should not clobber an existing table role', () => {
623623
setupTableTestApp(CustomRoleCdkTableApp);
624624
expect(tableElement.getAttribute('role')).toBe('treegrid');
625-
626-
expect(getHeaderRows(tableElement)[0].getAttribute('role')).toBe('row');
627-
const header = getHeaderRows(tableElement)[0];
628-
getHeaderCells(header).forEach(cell => {
629-
expect(cell.getAttribute('role')).toBe('columnheader');
630-
});
631-
632-
getRows(tableElement).forEach(row => {
633-
expect(row.getAttribute('role')).toBe('row');
634-
getCells(row).forEach(cell => {
635-
expect(cell.getAttribute('role')).toBe('gridcell');
636-
});
637-
});
638625
});
639626

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

src/cdk/table/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
521521
@Optional() @SkipSelf() @Inject(STICKY_POSITIONING_LISTENER)
522522
protected readonly _stickyPositioningListener: StickyPositioningListener) {
523523
if (!role) {
524-
this._elementRef.nativeElement.setAttribute('role', 'table');
524+
this._elementRef.nativeElement.setAttribute('role', 'grid');
525525
}
526526

527527
this._document = _document;

src/material-experimental/mdc-table/cell.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export class MatHeaderCell extends CdkHeaderCell {}
9090
selector: 'mat-footer-cell, td[mat-footer-cell]',
9191
host: {
9292
'class': 'mat-mdc-footer-cell mdc-data-table__cell',
93+
'role': 'gridcell',
9394
},
9495
})
9596
export class MatFooterCell extends CdkFooterCell {}
@@ -99,6 +100,7 @@ export class MatFooterCell extends CdkFooterCell {}
99100
selector: 'mat-cell, td[mat-cell]',
100101
host: {
101102
'class': 'mat-mdc-cell mdc-data-table__cell',
103+
'role': 'gridcell',
102104
},
103105
})
104106
export class MatCell extends CdkCell {}

0 commit comments

Comments
 (0)