Skip to content

Commit 5cb3860

Browse files
committed
fix(material/table): switch back to class-based styling for flex tables
In an earlier PR we switched the flex-based table styles to target the tag names, rather than classes in order to support flex tables in MDC. The problem with targeting tag names is that it doesn't allow our styles to be applied to other elements within the table. E.g. in #22349 the user isn't able to target the "no data" row. These changes switch back to targeting classes and add some styles to prevent the flex-specific styles from bleeding into the table-based ones. Fixes #22349.
1 parent b8d83cb commit 5cb3860

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
@use '../mdc-helpers/mdc-helpers';
44
@use '../../material/table/table-flex-styles';
55

6+
.mat-mdc-table:not(table) {
7+
@include table-flex-styles.private-table-flex-styles('mat-mdc');
8+
}
9+
610
@include mdc-data-table.core-styles($query: mdc-helpers.$mat-base-styles-without-animation-query);
7-
@include table-flex-styles.private-table-flex-styles();
811

912
.mat-mdc-table-sticky {
1013
// Note that the table can either set this class or an inline style to make something sticky.
@@ -24,6 +27,11 @@
2427
// MDC table rows are styled with a top border, whereas our legacy flex table styles rows with
2528
// a bottom border. Remove the bottom border style from the rows and let MDC display its top
2629
// border.
27-
mat-row.mat-mdc-row, mat-header-row.mat-mdc-header-row, mat-footer-row.mat-mdc-footer-row {
30+
mat-row.mat-mdc-row,
31+
mat-header-row.mat-mdc-header-row,
32+
mat-footer-row.mat-mdc-footer-row,
33+
.mat-mdc-table:not(table) .mat-mdc-row,
34+
.mat-mdc-table:not(table) .mat-mdc-header-row,
35+
.mat-mdc-table:not(table) .mdc-mdc-footer-row {
2836
border-bottom: none;
2937
}

src/material/table/_table-flex-styles.scss

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,21 @@ $row-height: 48px;
44
$row-horizontal-padding: 24px;
55

66
// Only use tag name selectors here since the styles are shared between MDC and non-MDC
7-
@mixin private-table-flex-styles {
8-
mat-table {
9-
display: block;
10-
}
7+
@mixin private-table-flex-styles($prefix) {
8+
display: block;
119

12-
mat-header-row {
10+
.#{$prefix}-header-row {
1311
min-height: $header-row-height;
1412
}
1513

16-
mat-row, mat-footer-row {
14+
.#{$prefix}-row, .#{$prefix}-footer-row {
1715
min-height: $row-height;
1816
}
1917

20-
mat-row, mat-header-row, mat-footer-row {
18+
.#{$prefix}-row, .#{$prefix}-header-row, .#{$prefix}-footer-row {
2119
display: flex;
22-
// Define a border style, but then widths default to 3px. Reset them to 0px except the bottom
23-
// which should be 1px;
24-
border-width: 0;
2520
border-bottom-width: 1px;
26-
border-style: solid;
21+
border-bottom-style: solid;
2722
align-items: center;
2823
box-sizing: border-box;
2924

@@ -37,7 +32,7 @@ $row-horizontal-padding: 24px;
3732
}
3833
}
3934

40-
mat-cell, mat-header-cell, mat-footer-cell {
35+
.#{$prefix}-cell, .#{$prefix}-header-cell, .#{$prefix}-footer-cell {
4136
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
4237
// elements like ripples or badges from throwing off the layout (see #11165).
4338
&:first-of-type {
@@ -59,7 +54,7 @@ $row-horizontal-padding: 24px;
5954
}
6055
}
6156

62-
mat-cell, mat-header-cell, mat-footer-cell {
57+
.#{$prefix}-cell, .#{$prefix}-header-cell, .#{$prefix}-footer-cell {
6358
flex: 1;
6459
display: flex;
6560
align-items: center;

src/material/table/_table-theme.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
}
1515

1616
.mat-table thead, .mat-table tbody, .mat-table tfoot,
17-
mat-header-row, mat-row, mat-footer-row,
17+
.mat-header-row, .mat-row, .mat-footer-row,
1818
[mat-header-row], [mat-row], [mat-footer-row],
1919
.mat-table-sticky {
2020
background: inherit;
2121
}
2222

23-
mat-row, mat-header-row, mat-footer-row,
23+
.mat-row, .mat-header-row, .mat-footer-row,
2424
th.mat-header-cell, td.mat-cell, td.mat-footer-cell {
2525
border-bottom-color: theming.get-color-from-palette($foreground, divider);
2626
}

src/material/table/table.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@use '../core/style/vendor-prefixes';
22
@use './table-flex-styles';
33

4-
@include table-flex-styles.private-table-flex-styles();
4+
.mat-table:not(table) {
5+
@include table-flex-styles.private-table-flex-styles('mat');
6+
}
57

68
// Native HTML table structure
79
table.mat-table {

0 commit comments

Comments
 (0)