Skip to content

Commit 0443492

Browse files
committed
refactor(material/table): simplify structural styles
Simplifies the table's structural styles to make them smaller and easier to maintain. Also fixes an error in the table demo.
1 parent 3b96730 commit 0443492

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

src/dev-app/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '@angular/core';
1717
import {bootstrapApplication} from '@angular/platform-browser';
1818
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
19+
import {provideHttpClient} from '@angular/common/http';
1920
import {RouterModule} from '@angular/router';
2021

2122
import {Directionality} from '@angular/cdk/bidi';
@@ -51,6 +52,7 @@ function bootstrap(): void {
5152
RouterModule.forRoot(DEV_APP_ROUTES),
5253
),
5354
provideNativeDateAdapter(),
55+
provideHttpClient(),
5456
{provide: OverlayContainer, useClass: FullscreenOverlayContainer},
5557
{provide: MAT_RIPPLE_GLOBAL_OPTIONS, useExisting: DevAppRippleOptions},
5658
{provide: Directionality, useClass: DevAppDirectionality},

src/material/core/style/_vendor-prefixes.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@
4343
-webkit-clip-path: $value;
4444
clip-path: $value;
4545
}
46+
47+
@mixin smooth-font {
48+
-moz-osx-font-smoothing: grayscale;
49+
-webkit-font-smoothing: antialiased;
50+
}
4651
// stylelint-enable

src/material/table/table.scss

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
@use '@material/data-table/data-table' as mdc-data-table;
2-
@use '@material/data-table/data-table-cell' as mdc-data-table-cell;
3-
@use '@material/data-table/data-table-header-cell' as mdc-data-table-header-cell;
4-
@use '@material/data-table' as mdc-data-table-theme;
5-
@use '@material/typography/typography' as mdc-typography;
61
@use '../core/mdc-helpers/mdc-helpers';
72
@use '../core/tokens/token-utils';
83
@use '../core/tokens/m2/mat/table' as tokens-mat-table;
4+
@use '../core/style/vendor-prefixes';
95
@use './table-flex-styles';
106

117
.mat-mdc-table-sticky {
@@ -21,38 +17,41 @@
2117
border-bottom-style: solid;
2218
}
2319

24-
@include mdc-data-table.static-styles($query: mdc-helpers.$mdc-base-styles-query);
25-
@include mdc-data-table-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
26-
@include mdc-data-table-header-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
27-
@include mdc-data-table-theme.cell-padding(
28-
$leading-padding: mdc-data-table-theme.$cell-leading-padding,
29-
$trailing-padding: mdc-data-table-theme.$cell-trailing-padding,
30-
$query: mdc-helpers.$mdc-base-styles-query
31-
);
3220
@include table-flex-styles.private-table-flex-styles();
3321

3422
.mat-mdc-table {
35-
// MDC Table applies `table-layout: fixed`, but this is a backwards incompatible
36-
// change since the table did not previously apply it.
37-
// TODO: Add a mixin to MDC to set the layout instead of including this override,
38-
// see this issue: https://github.com/material-components/material-components-web/issues/6412
23+
min-width: 100%;
24+
border: 0;
25+
border-spacing: 0;
3926
table-layout: auto;
4027

41-
// The MDC table does not allow text to wrap within the cell. This allows for text to
42-
// wrap when the cell reaches its maximum width.
43-
white-space: normal;
44-
4528
@include token-utils.use-tokens(tokens-mat-table.$prefix, tokens-mat-table.get-token-slots()) {
4629
@include token-utils.create-token-slot(background-color, background-color);
4730
}
4831
}
4932

33+
.mdc-data-table__cell {
34+
box-sizing: border-box;
35+
overflow: hidden;
36+
text-align: left;
37+
text-overflow: ellipsis;
38+
39+
[dir='rtl'] & {
40+
text-align: right;
41+
}
42+
}
43+
44+
.mdc-data-table__cell,
45+
.mdc-data-table__header-cell {
46+
padding: 0 16px;
47+
}
48+
5049
@include mdc-helpers.disable-mdc-fallback-declarations {
5150
@include token-utils.use-tokens(tokens-mat-table.$prefix, tokens-mat-table.get-token-slots()) {
5251
// TODO(crisbeto): these tokens have default values in order to make the initial token
5352
// work easier to land in g3. Eventually we should remove them.
5453
.mat-mdc-header-row {
55-
@include mdc-typography.smooth-font();
54+
@include vendor-prefixes.smooth-font;
5655
@include token-utils.create-token-slot(height, header-container-height, 56px);
5756
@include token-utils.create-token-slot(color, header-headline-color, true);
5857
@include token-utils.create-token-slot(font-family, header-headline-font, true);
@@ -72,15 +71,15 @@
7271
// letter spacing which leads to a lot of internal screenshot diffs.
7372
.mat-mdc-row,
7473
.mdc-data-table__content {
75-
@include mdc-typography.smooth-font();
74+
@include vendor-prefixes.smooth-font;
7675
@include token-utils.create-token-slot(font-family, row-item-label-text-font, true);
7776
@include token-utils.create-token-slot(line-height, row-item-label-text-line-height);
7877
@include token-utils.create-token-slot(font-size, row-item-label-text-size, 14px);
7978
@include token-utils.create-token-slot(font-weight, row-item-label-text-weight);
8079
}
8180

8281
.mat-mdc-footer-row {
83-
@include mdc-typography.smooth-font();
82+
@include vendor-prefixes.smooth-font;
8483
@include token-utils.create-token-slot(height, footer-container-height, 52px);
8584
@include token-utils.create-token-slot(color, row-item-label-text-color, true);
8685
@include token-utils.create-token-slot(font-family, footer-supporting-text-font, true);
@@ -95,6 +94,15 @@
9594
@include token-utils.create-token-slot(letter-spacing, header-headline-tracking);
9695
font-weight: inherit;
9796
line-height: inherit;
97+
box-sizing: border-box;
98+
text-overflow: ellipsis;
99+
overflow: hidden;
100+
outline: none;
101+
text-align: left;
102+
103+
[dir='rtl'] & {
104+
text-align: right;
105+
}
98106
}
99107

100108
.mat-mdc-cell {

0 commit comments

Comments
 (0)