Skip to content

Commit bb68c7b

Browse files
authored
feat(material-experimental/mdc-table): add MDC styles/classes (#18000)
* feat(material-experimental/mdc-table): add MDC styles/classes * fix sass build
1 parent 093d007 commit bb68c7b

File tree

12 files changed

+47
-14
lines changed

12 files changed

+47
-14
lines changed

src/dev-app/mdc-table/mdc-table-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<table mat-table [dataSource]="dataSource">
1+
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
22
<!-- Position Column -->
33
<ng-container matColumnDef="position">
44
<th mat-header-cell *matHeaderCellDef> No. </th>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
table {
2+
width: 800px;
3+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ ng_module(
3131
sass_library(
3232
name = "mdc_table_scss_lib",
3333
srcs = glob(["**/_*.scss"]),
34+
deps = [
35+
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
36+
],
3437
)
3538

3639
sass_binary(
@@ -39,6 +42,10 @@ sass_binary(
3942
include_paths = [
4043
"external/npm/node_modules",
4144
],
45+
deps = [
46+
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
47+
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
48+
],
4249
)
4350

4451
###########
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
@import '../mdc-helpers/mdc-helpers';
2+
@import '@material/data-table/mixins';
3+
14
@mixin mat-table-theme-mdc($theme) {
2-
// TODO: Include theme styles for MDC Table
5+
@include mat-using-mdc-theme($theme) {
6+
@include mdc-data-table-core-styles($query: $mat-theme-styles-query);
7+
}
38
}
49

510
@mixin mat-table-typography-mdc($config) {
6-
// TODO: Include typography styles for MDC Table
11+
@include mat-using-mdc-typography($config) {
12+
@include mdc-data-table-core-styles($query: $mat-typography-styles-query);
13+
}
714
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class MatColumnDef extends CdkColumnDef {
7070
@Directive({
7171
selector: 'th[mat-header-cell]',
7272
host: {
73-
'class': 'mat-mdc-header-cell',
73+
'class': 'mat-mdc-header-cell mdc-data-table__header-cell',
7474
'role': 'columnheader',
7575
},
7676
})
@@ -86,7 +86,7 @@ export class MatHeaderCell extends CdkHeaderCell {
8686
@Directive({
8787
selector: 'td[mat-footer-cell]',
8888
host: {
89-
'class': 'mat-mdc-footer-cell',
89+
'class': 'mat-mdc-footer-cell mdc-data-table__cell',
9090
'role': 'gridcell',
9191
},
9292
})
@@ -102,7 +102,7 @@ export class MatFooterCell extends CdkFooterCell {
102102
@Directive({
103103
selector: 'td[mat-cell]',
104104
host: {
105-
'class': 'mat-mdc-cell',
105+
'class': 'mat-mdc-cell mdc-data-table__cell',
106106
'role': 'gridcell',
107107
},
108108
})

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class MatRowDef<T> extends CdkRowDef<T> {
6262
selector: 'tr[mat-header-row]',
6363
template: CDK_ROW_TEMPLATE,
6464
host: {
65-
'class': 'mat-mdc-header-row',
65+
'class': 'mat-mdc-header-row mdc-data-table__header-row',
6666
'role': 'row',
6767
},
6868
// See note on CdkTable for explanation on why this uses the default change detection strategy.
@@ -80,7 +80,7 @@ export class MatHeaderRow extends CdkHeaderRow {
8080
selector: 'tr[mat-footer-row]',
8181
template: CDK_ROW_TEMPLATE,
8282
host: {
83-
'class': 'mat-mdc-footer-row',
83+
'class': 'mat-mdc-footer-row mdc-data-table__row',
8484
'role': 'row',
8585
},
8686
// See note on CdkTable for explanation on why this uses the default change detection strategy.
@@ -98,7 +98,7 @@ export class MatFooterRow extends CdkFooterRow {
9898
selector: 'tr[mat-row]',
9999
template: CDK_ROW_TEMPLATE,
100100
host: {
101-
'class': 'mat-mdc-row',
101+
'class': 'mat-mdc-row mdc-data-table__row',
102102
'role': 'row',
103103
},
104104
// See note on CdkTable for explanation on why this uses the default change detection strategy.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
// TODO: Include MDC styles for the table
1+
@import '@material/data-table/mixins';
2+
@import '../mdc-helpers/mdc-helpers';
3+
4+
@include mdc-data-table-core-styles($query: $mat-base-styles-without-animation-query);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
9+
import {ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation} from '@angular/core';
1010
import {CDK_TABLE_TEMPLATE, CdkTable} from '@angular/cdk/table';
1111
import {BooleanInput} from '@angular/cdk/coercion';
1212

@@ -16,17 +16,24 @@ import {BooleanInput} from '@angular/cdk/coercion';
1616
template: CDK_TABLE_TEMPLATE,
1717
styleUrls: ['table.css'],
1818
host: {
19-
'class': 'mat-mdc-table',
19+
'class': 'mat-mdc-table mdc-data-table__table',
2020
},
2121
providers: [{provide: CdkTable, useExisting: MatTable}],
2222
encapsulation: ViewEncapsulation.None,
2323
// See note on CdkTable for explanation on why this uses the default change detection strategy.
2424
// tslint:disable-next-line:validate-decorators
2525
changeDetection: ChangeDetectionStrategy.Default,
2626
})
27-
export class MatTable<T> extends CdkTable<T> {
27+
export class MatTable<T> extends CdkTable<T> implements OnInit {
2828
/** Overrides the sticky CSS class set by the `CdkTable`. */
29-
protected stickyCssClass = 'mat-table-sticky';
29+
protected stickyCssClass = 'mat-mdc-table-sticky';
3030

3131
static ngAcceptInputType_multiTemplateDataRows: BooleanInput;
32+
33+
// After ngOnInit, the `CdkTable` has created and inserted the table sections (thead, tbody,
34+
// tfoot). MDC requires the `mdc-data-table__content` class to be added to the body.
35+
ngOnInit() {
36+
super.ngOnInit();
37+
this._elementRef.nativeElement.querySelector('tbody').classList.add('mdc-data-table__content');
38+
}
3239
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sass_library(
1717
"//src/material-experimental/mdc-progress-bar:mdc_progress_bar_scss_lib",
1818
"//src/material-experimental/mdc-radio:mdc_radio_scss_lib",
1919
"//src/material-experimental/mdc-slide-toggle:mdc_slide_toggle_scss_lib",
20+
"//src/material-experimental/mdc-table:mdc_table_scss_lib",
2021
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
2122
],
2223
)

src/material-experimental/mdc-theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@import '../mdc-radio/mdc-radio';
88
@import '../mdc-slide-toggle/mdc-slide-toggle';
99
@import '../mdc-tabs/mdc-tabs';
10+
@import '../mdc-table/mdc-table';
1011
@import '../mdc-progress-bar/mdc-progress-bar';
1112

1213
@mixin angular-material-theme-mdc($theme) {
@@ -21,6 +22,7 @@
2122
@include mat-progress-bar-theme-mdc($theme);
2223
@include mat-radio-theme-mdc($theme);
2324
@include mat-slide-toggle-theme-mdc($theme);
25+
@include mat-table-theme-mdc($theme);
2426
// TODO(andrewjs): Add this back when MDC syncs their slider code into Google-internal code
2527
// @include mat-slider-theme-mdc($theme);
2628
@include mat-tabs-theme-mdc($theme);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sass_library(
1818
"//src/material-experimental/mdc-radio:mdc_radio_scss_lib",
1919
"//src/material-experimental/mdc-slide-toggle:mdc_slide_toggle_scss_lib",
2020
"//src/material-experimental/mdc-slider:mdc_slider_scss_lib",
21+
"//src/material-experimental/mdc-table:mdc_table_scss_lib",
2122
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
2223
],
2324
)

src/material-experimental/mdc-typography/_all-typography.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@import '../mdc-slide-toggle/mdc-slide-toggle';
99
@import '../mdc-slider/mdc-slider';
1010
@import '../mdc-tabs/mdc-tabs';
11+
@import '../mdc-table/mdc-table';
1112
@import '../mdc-progress-bar/mdc-progress-bar';
1213

1314
@mixin angular-material-typography-mdc($config: null) {
@@ -27,5 +28,6 @@
2728
@include mat-slide-toggle-typography-mdc($config);
2829
@include mat-slider-typography-mdc($config);
2930
@include mat-tabs-typography-mdc($config);
31+
@include mat-table-typography-mdc($config);
3032
@include mat-progress-bar-typography-mdc($config);
3133
}

0 commit comments

Comments
 (0)