Skip to content

Commit c76a09e

Browse files
authored
fix(material/table): switch back to class-based styling for flex tables (#22350)
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 e1d775d commit c76a09e

File tree

5 files changed

+40
-35
lines changed

5 files changed

+40
-35
lines changed

src/components-examples/material/table/table-expandable-rows/table-expandable-rows-example.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ table {
44

55
tr.example-detail-row {
66
height: 0;
7+
min-height: 0;
78
}
89

910
tr.example-element-row:not(.example-expanded-row):hover {

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

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

6+
@include table-flex-styles.private-table-flex-styles('mat-mdc');
67
@include mdc-data-table.core-styles($query: mdc-helpers.$mat-base-styles-without-animation-query);
7-
@include table-flex-styles.private-table-flex-styles();
88

99
.mat-mdc-table-sticky {
1010
// Note that the table can either set this class or an inline style to make something sticky.
@@ -24,7 +24,7 @@
2424
// MDC table rows are styled with a top border, whereas our legacy flex table styles rows with
2525
// a bottom border. Remove the bottom border style from the rows and let MDC display its top
2626
// border.
27-
mat-row.mat-mdc-row, mat-header-row.mat-mdc-header-row, mat-footer-row.mat-mdc-footer-row {
27+
.mat-mdc-row, .mat-mdc-header-row, .mdc-mdc-footer-row {
2828
border-bottom: none;
2929
}
3030

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,54 @@ $header-row-height: 56px;
33
$row-height: 48px;
44
$row-horizontal-padding: 24px;
55

6-
// 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 {
6+
@mixin private-table-flex-styles($prefix) {
7+
// These styles are nested under a `:not(table)`, because
8+
// they can break the non-flex table if they leak out.
9+
.#{$prefix}-table:not(table) {
910
display: block;
11+
12+
.#{$prefix}-cell, .#{$prefix}-header-cell, .#{$prefix}-footer-cell {
13+
display: flex;
14+
}
15+
16+
.#{$prefix}-row, .#{$prefix}-header-row, .#{$prefix}-footer-row {
17+
display: flex;
18+
19+
// Workaround for https://goo.gl/pFmjJD in IE 11. Adds a pseudo
20+
// element that will stretch the row the correct height. See:
21+
// https://connect.microsoft.com/IE/feedback/details/802625
22+
&::after {
23+
display: inline-block;
24+
min-height: inherit;
25+
content: '';
26+
}
27+
}
1028
}
1129

12-
mat-header-row {
30+
// The remaining styles can leak to the native table without affecting it.
31+
// We keep them outside to lower the specificity.
32+
.#{$prefix}-header-row {
1333
min-height: $header-row-height;
1434
}
1535

16-
mat-row, mat-footer-row {
36+
.#{$prefix}-row, .#{$prefix}-footer-row {
1737
min-height: $row-height;
1838
}
1939

20-
mat-row, mat-header-row, mat-footer-row {
21-
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;
40+
.#{$prefix}-row, .#{$prefix}-header-row, .#{$prefix}-footer-row {
2541
border-bottom-width: 1px;
26-
border-style: solid;
42+
border-bottom-style: solid;
2743
align-items: center;
2844
box-sizing: border-box;
29-
30-
// Workaround for https://goo.gl/pFmjJD in IE 11. Adds a pseudo
31-
// element that will stretch the row the correct height. See:
32-
// https://connect.microsoft.com/IE/feedback/details/802625
33-
&::after {
34-
display: inline-block;
35-
min-height: inherit;
36-
content: '';
37-
}
3845
}
3946

40-
mat-cell, mat-header-cell, mat-footer-cell {
47+
.#{$prefix}-cell, .#{$prefix}-header-cell, .#{$prefix}-footer-cell {
48+
flex: 1;
49+
overflow: hidden;
50+
word-wrap: break-word;
51+
min-height: inherit;
52+
align-items: center;
53+
4154
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
4255
// elements like ripples or badges from throwing off the layout (see #11165).
4356
&:first-of-type {
@@ -58,13 +71,4 @@ $row-horizontal-padding: 24px;
5871
}
5972
}
6073
}
61-
62-
mat-cell, mat-header-cell, mat-footer-cell {
63-
flex: 1;
64-
display: flex;
65-
align-items: center;
66-
overflow: hidden;
67-
word-wrap: break-word;
68-
min-height: inherit;
69-
}
7074
}

src/material/table/_table-theme.scss

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

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

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

src/material/table/table.scss

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

4-
@include table-flex-styles.private-table-flex-styles();
4+
@include table-flex-styles.private-table-flex-styles('mat');
55

66
// Native HTML table structure
77
table.mat-table {

0 commit comments

Comments
 (0)