Skip to content

Commit 6771ca4

Browse files
authored
Revert "fix(material-experimental/mdc-table): error when flexbox-based table is initialized (#21428)" (#21568)
* Revert "fix(material-experimental/mdc-table): error when flexbox-based table is initialized (#21428)" This reverts commit aade5d1. * fixup! Revert "fix(material-experimental/mdc-table): error when flexbox-based table is initialized (#21428)"
1 parent 1724031 commit 6771ca4

File tree

6 files changed

+125
-183
lines changed

6 files changed

+125
-183
lines changed

src/cdk/table/table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class CdkTable<T> implements AfterContentChecked, CollectionViewer, OnDes
325325
private _cachedRenderRowsMap = new Map<T, WeakMap<CdkRowDef<T>, RenderRow<T>[]>>();
326326

327327
/** Whether the table is applied to a native `<table>`. */
328-
protected _isNativeHtmlTable: boolean;
328+
private _isNativeHtmlTable: boolean;
329329

330330
/**
331331
* Utility class that is responsible for applying the appropriate sticky positioning styles to

src/material-experimental/mdc-table/BUILD.bazel

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,17 @@ ng_test_library(
6262
deps = [
6363
":mdc-table",
6464
"//src/cdk/table",
65-
"//src/material-experimental/mdc-paginator",
65+
"//src/material/paginator",
6666
"//src/material/sort",
67+
"//src/material/table",
6768
"@npm//@angular/platform-browser",
6869
"@npm//rxjs",
6970
],
7071
)
7172

7273
ng_web_test_suite(
7374
name = "unit_tests",
74-
static_files = [
75-
"@npm//:node_modules/@material/textfield/dist/mdc.textfield.js",
76-
"@npm//:node_modules/@material/line-ripple/dist/mdc.lineRipple.js",
77-
"@npm//:node_modules/@material/notched-outline/dist/mdc.notchedOutline.js",
78-
"@npm//:node_modules/@material/ripple/dist/mdc.ripple.js",
79-
"@npm//:node_modules/@material/dom/dist/mdc.dom.js",
80-
"@npm//:node_modules/@material/data-table/dist/mdc.dataTable.js",
81-
],
75+
static_files = ["@npm//:node_modules/@material/data-table/dist/mdc.dataTable.js"],
8276
deps = [
8377
":table_tests_lib",
8478
"//src/material-experimental:mdc_require_config.js",

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

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import {
77
TestBed,
88
tick
99
} from '@angular/core/testing';
10-
import {MatTable, MatTableDataSource, MatTableModule} from './index';
10+
import {MatTable, MatTableModule} from './index';
1111
import {DataSource} from '@angular/cdk/table';
1212
import {BehaviorSubject, Observable} from 'rxjs';
1313
import {MatSort, MatSortHeader, MatSortModule} from '@angular/material/sort';
14-
import {MatPaginator, MatPaginatorModule} from '@angular/material-experimental/mdc-paginator';
14+
import {MatPaginator, MatPaginatorModule} from '@angular/material/paginator';
15+
import {MatTableDataSource} from '@angular/material/table';
1516
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
1617

1718
describe('MDC-based MatTable', () => {
@@ -28,7 +29,6 @@ describe('MDC-based MatTable', () => {
2829
StickyTableApp,
2930
TableWithNgContainerRow,
3031
NestedTableApp,
31-
MatFlexTableApp,
3232
],
3333
}).compileComponents();
3434
}));
@@ -164,14 +164,6 @@ describe('MDC-based MatTable', () => {
164164
expect(tbody.textContent.trim()).toContain('No data');
165165
});
166166

167-
it('should set the content styling class on the tbody', () => {
168-
let fixture = TestBed.createComponent(NativeHtmlTableApp);
169-
fixture.detectChanges();
170-
171-
const tbodyElement = fixture.nativeElement.querySelector('tbody');
172-
expect(tbodyElement.classList).toContain('mdc-data-table__content');
173-
});
174-
175167
});
176168

177169
it('should render with MatTableDataSource and sort', () => {
@@ -221,13 +213,6 @@ describe('MDC-based MatTable', () => {
221213
}).not.toThrow();
222214
}));
223215

224-
it('should be able to render a flexbox-based table', () => {
225-
expect(() => {
226-
const fixture = TestBed.createComponent(MatFlexTableApp);
227-
fixture.detectChanges();
228-
}).not.toThrow();
229-
});
230-
231216
describe('with MatTableDataSource and sort/pagination/filter', () => {
232217
let tableElement: HTMLElement;
233218
let fixture: ComponentFixture<ArrayDataSourceMatTableApp>;
@@ -976,45 +961,6 @@ class TableWithNgContainerRow {
976961
}
977962

978963

979-
@Component({
980-
template: `
981-
<mat-table [dataSource]="dataSource">
982-
<ng-container matColumnDef="column_a">
983-
<mat-header-cell *matHeaderCellDef> Column A</mat-header-cell>
984-
<mat-cell *matCellDef="let row"> {{row.a}}</mat-cell>
985-
<mat-footer-cell *matFooterCellDef> Footer A</mat-footer-cell>
986-
</ng-container>
987-
988-
<ng-container matColumnDef="column_b">
989-
<mat-header-cell *matHeaderCellDef> Column B</mat-header-cell>
990-
<mat-cell *matCellDef="let row"> {{row.b}}</mat-cell>
991-
<mat-footer-cell *matFooterCellDef> Footer B</mat-footer-cell>
992-
</ng-container>
993-
994-
<ng-container matColumnDef="column_c">
995-
<mat-header-cell *matHeaderCellDef> Column C</mat-header-cell>
996-
<mat-cell *matCellDef="let row"> {{row.c}}</mat-cell>
997-
<mat-footer-cell *matFooterCellDef> Footer C</mat-footer-cell>
998-
</ng-container>
999-
1000-
<ng-container matColumnDef="special_column">
1001-
<mat-cell *matCellDef="let row"> fourth_row </mat-cell>
1002-
</ng-container>
1003-
1004-
<mat-header-row *matHeaderRowDef="columnsToRender"></mat-header-row>
1005-
<mat-row *matRowDef="let row; columns: columnsToRender"></mat-row>
1006-
<div *matNoDataRow>No data</div>
1007-
<mat-footer-row *matFooterRowDef="columnsToRender"></mat-footer-row>
1008-
</mat-table>
1009-
`
1010-
})
1011-
class MatFlexTableApp {
1012-
dataSource: FakeDataSource | null = new FakeDataSource();
1013-
columnsToRender = ['column_a', 'column_b', 'column_c'];
1014-
@ViewChild(MatTable) table: MatTable<TestData>;
1015-
}
1016-
1017-
1018964
function getElements(element: Element, query: string): Element[] {
1019965
return [].slice.call(element.querySelectorAll(query));
1020966
}

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ export class MatTable<T> extends CdkTable<T> implements OnInit {
4343
/** Overrides the need to add position: sticky on every sticky cell element in `CdkTable`. */
4444
protected needsPositionStickyOnElement = false;
4545

46+
// After ngOnInit, the `CdkTable` has created and inserted the table sections (thead, tbody,
47+
// tfoot). MDC requires the `mdc-data-table__content` class to be added to the body.
4648
ngOnInit() {
4749
super.ngOnInit();
48-
49-
// After ngOnInit, the `CdkTable` has created and inserted the table sections (thead, tbody,
50-
// tfoot). MDC requires the `mdc-data-table__content` class to be added to the body. Note that
51-
// this only applies to native tables, because we don't wrap the content of flexbox-based ones.
52-
if (this._isNativeHtmlTable) {
53-
const tbody = this._elementRef.nativeElement.querySelector('tbody');
54-
tbody.classList.add('mdc-data-table__content');
55-
}
50+
this._elementRef.nativeElement.querySelector('tbody').classList.add('mdc-data-table__content');
5651
}
5752
}

tools/public_api_guard/cdk/table.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export declare class CdkTable<T> implements AfterContentChecked, CollectionViewe
199199
protected readonly _elementRef: ElementRef;
200200
_footerRowOutlet: FooterRowOutlet;
201201
_headerRowOutlet: HeaderRowOutlet;
202-
protected _isNativeHtmlTable: boolean;
203202
_multiTemplateDataRows: boolean;
204203
_noDataRow: CdkNoDataRow;
205204
_noDataRowOutlet: NoDataRowOutlet;

0 commit comments

Comments
 (0)