Skip to content

feat(material-experimental/mdc-table): add MDC styles/classes #18000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dev-app/mdc-table/mdc-table-demo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<table mat-table [dataSource]="dataSource">
<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<!-- Position Column -->
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
Expand Down
3 changes: 3 additions & 0 deletions src/dev-app/mdc-table/mdc-table-demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
table {
width: 800px;
}
7 changes: 7 additions & 0 deletions src/material-experimental/mdc-table/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ng_module(
sass_library(
name = "mdc_table_scss_lib",
srcs = glob(["**/_*.scss"]),
deps = [
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
],
)

sass_binary(
Expand All @@ -39,6 +42,10 @@ sass_binary(
include_paths = [
"external/npm/node_modules",
],
deps = [
"//src/material-experimental/mdc-helpers:mdc_helpers_scss_lib",
"//src/material-experimental/mdc-helpers:mdc_scss_deps_lib",
],
)

###########
Expand Down
11 changes: 9 additions & 2 deletions src/material-experimental/mdc-table/_mdc-table.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
@import '../mdc-helpers/mdc-helpers';
@import '@material/data-table/mixins';

@mixin mat-table-theme-mdc($theme) {
// TODO: Include theme styles for MDC Table
@include mat-using-mdc-theme($theme) {
@include mdc-data-table-core-styles($query: $mat-theme-styles-query);
}
}

@mixin mat-table-typography-mdc($config) {
// TODO: Include typography styles for MDC Table
@include mat-using-mdc-typography($config) {
@include mdc-data-table-core-styles($query: $mat-typography-styles-query);
}
}
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-table/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MatColumnDef extends CdkColumnDef {
@Directive({
selector: 'th[mat-header-cell]',
host: {
'class': 'mat-mdc-header-cell',
'class': 'mat-mdc-header-cell mdc-data-table__header-cell',
'role': 'columnheader',
},
})
Expand All @@ -86,7 +86,7 @@ export class MatHeaderCell extends CdkHeaderCell {
@Directive({
selector: 'td[mat-footer-cell]',
host: {
'class': 'mat-mdc-footer-cell',
'class': 'mat-mdc-footer-cell mdc-data-table__cell',
'role': 'gridcell',
},
})
Expand All @@ -102,7 +102,7 @@ export class MatFooterCell extends CdkFooterCell {
@Directive({
selector: 'td[mat-cell]',
host: {
'class': 'mat-mdc-cell',
'class': 'mat-mdc-cell mdc-data-table__cell',
'role': 'gridcell',
},
})
Expand Down
6 changes: 3 additions & 3 deletions src/material-experimental/mdc-table/row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class MatRowDef<T> extends CdkRowDef<T> {
selector: 'tr[mat-header-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'mat-mdc-header-row',
'class': 'mat-mdc-header-row mdc-data-table__header-row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
Expand All @@ -80,7 +80,7 @@ export class MatHeaderRow extends CdkHeaderRow {
selector: 'tr[mat-footer-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'mat-mdc-footer-row',
'class': 'mat-mdc-footer-row mdc-data-table__row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
Expand All @@ -98,7 +98,7 @@ export class MatFooterRow extends CdkFooterRow {
selector: 'tr[mat-row]',
template: CDK_ROW_TEMPLATE,
host: {
'class': 'mat-mdc-row',
'class': 'mat-mdc-row mdc-data-table__row',
'role': 'row',
},
// See note on CdkTable for explanation on why this uses the default change detection strategy.
Expand Down
5 changes: 4 additions & 1 deletion src/material-experimental/mdc-table/table.scss
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
// TODO: Include MDC styles for the table
@import '@material/data-table/mixins';
@import '../mdc-helpers/mdc-helpers';

@include mdc-data-table-core-styles($query: $mat-base-styles-without-animation-query);
15 changes: 11 additions & 4 deletions src/material-experimental/mdc-table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {ChangeDetectionStrategy, Component, ViewEncapsulation} from '@angular/core';
import {ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation} from '@angular/core';
import {CDK_TABLE_TEMPLATE, CdkTable} from '@angular/cdk/table';
import {BooleanInput} from '@angular/cdk/coercion';

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

static ngAcceptInputType_multiTemplateDataRows: BooleanInput;

// After ngOnInit, the `CdkTable` has created and inserted the table sections (thead, tbody,
// tfoot). MDC requires the `mdc-data-table__content` class to be added to the body.
ngOnInit() {
super.ngOnInit();
this._elementRef.nativeElement.querySelector('tbody').classList.add('mdc-data-table__content');
}
}
1 change: 1 addition & 0 deletions src/material-experimental/mdc-theming/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sass_library(
"//src/material-experimental/mdc-progress-bar:mdc_progress_bar_scss_lib",
"//src/material-experimental/mdc-radio:mdc_radio_scss_lib",
"//src/material-experimental/mdc-slide-toggle:mdc_slide_toggle_scss_lib",
"//src/material-experimental/mdc-table:mdc_table_scss_lib",
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
],
)
Expand Down
2 changes: 2 additions & 0 deletions src/material-experimental/mdc-theming/_all-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import '../mdc-radio/mdc-radio';
@import '../mdc-slide-toggle/mdc-slide-toggle';
@import '../mdc-tabs/mdc-tabs';
@import '../mdc-table/mdc-table';
@import '../mdc-progress-bar/mdc-progress-bar';

@mixin angular-material-theme-mdc($theme) {
Expand All @@ -21,6 +22,7 @@
@include mat-progress-bar-theme-mdc($theme);
@include mat-radio-theme-mdc($theme);
@include mat-slide-toggle-theme-mdc($theme);
@include mat-table-theme-mdc($theme);
// TODO(andrewjs): Add this back when MDC syncs their slider code into Google-internal code
// @include mat-slider-theme-mdc($theme);
@include mat-tabs-theme-mdc($theme);
Expand Down
1 change: 1 addition & 0 deletions src/material-experimental/mdc-typography/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ sass_library(
"//src/material-experimental/mdc-radio:mdc_radio_scss_lib",
"//src/material-experimental/mdc-slide-toggle:mdc_slide_toggle_scss_lib",
"//src/material-experimental/mdc-slider:mdc_slider_scss_lib",
"//src/material-experimental/mdc-table:mdc_table_scss_lib",
"//src/material-experimental/mdc-tabs:mdc_tabs_scss_lib",
],
)
2 changes: 2 additions & 0 deletions src/material-experimental/mdc-typography/_all-typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@import '../mdc-slide-toggle/mdc-slide-toggle';
@import '../mdc-slider/mdc-slider';
@import '../mdc-tabs/mdc-tabs';
@import '../mdc-table/mdc-table';
@import '../mdc-progress-bar/mdc-progress-bar';

@mixin angular-material-typography-mdc($config: null) {
Expand All @@ -27,5 +28,6 @@
@include mat-slide-toggle-typography-mdc($config);
@include mat-slider-typography-mdc($config);
@include mat-tabs-typography-mdc($config);
@include mat-table-typography-mdc($config);
@include mat-progress-bar-typography-mdc($config);
}