Skip to content

Commit 1f6b90c

Browse files
authored
fix(table): incorrect padding for single-cell rows in rtl (#20266)
The styles that reset the padding in RTL shouldn't apply to single-cell rows. Also moves a bit of code around so we don't have to repeat top-level selectors as much. Fixes #20265.
1 parent 2683b3d commit 1f6b90c

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/material/table/table.scss

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,25 @@ mat-row, mat-header-row, mat-footer-row {
3939
}
4040
}
4141

42-
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
43-
// elements like ripples or badges from throwing off the layout (see #11165).
44-
mat-cell:first-of-type, mat-header-cell:first-of-type, mat-footer-cell:first-of-type {
45-
padding-left: $mat-row-horizontal-padding;
42+
mat-cell, mat-header-cell, mat-footer-cell {
43+
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
44+
// elements like ripples or badges from throwing off the layout (see #11165).
45+
&:first-of-type {
46+
padding-left: $mat-row-horizontal-padding;
4647

47-
[dir='rtl'] & {
48-
padding-left: 0;
49-
padding-right: $mat-row-horizontal-padding;
48+
[dir='rtl'] &:not(:only-of-type) {
49+
padding-left: 0;
50+
padding-right: $mat-row-horizontal-padding;
51+
}
5052
}
51-
}
5253

53-
mat-cell:last-of-type, mat-header-cell:last-of-type, mat-footer-cell:last-of-type {
54-
padding-right: $mat-row-horizontal-padding;
54+
&:last-of-type {
55+
padding-right: $mat-row-horizontal-padding;
5556

56-
[dir='rtl'] & {
57-
padding-right: 0;
58-
padding-left: $mat-row-horizontal-padding;
57+
[dir='rtl'] &:not(:only-of-type) {
58+
padding-right: 0;
59+
padding-left: $mat-row-horizontal-padding;
60+
}
5961
}
6062
}
6163

@@ -95,25 +97,25 @@ th.mat-header-cell, td.mat-cell, td.mat-footer-cell {
9597
padding: 0;
9698
border-bottom-width: 1px;
9799
border-bottom-style: solid;
98-
}
99100

100-
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
101-
// elements like ripples or badges from throwing off the layout (see #11165).
102-
th.mat-header-cell:first-of-type, td.mat-cell:first-of-type, td.mat-footer-cell:first-of-type {
103-
padding-left: $mat-row-horizontal-padding;
101+
// Note: we use `first-of-type`/`last-of-type` here in order to prevent extra
102+
// elements like ripples or badges from throwing off the layout (see #11165).
103+
&:first-of-type {
104+
padding-left: $mat-row-horizontal-padding;
104105

105-
[dir='rtl'] & {
106-
padding-left: 0;
107-
padding-right: $mat-row-horizontal-padding;
106+
[dir='rtl'] &:not(:only-of-type) {
107+
padding-left: 0;
108+
padding-right: $mat-row-horizontal-padding;
109+
}
108110
}
109-
}
110111

111-
th.mat-header-cell:last-of-type, td.mat-cell:last-of-type, td.mat-footer-cell:last-of-type {
112-
padding-right: $mat-row-horizontal-padding;
112+
&:last-of-type {
113+
padding-right: $mat-row-horizontal-padding;
113114

114-
[dir='rtl'] & {
115-
padding-right: 0;
116-
padding-left: $mat-row-horizontal-padding;
115+
[dir='rtl'] &:not(:only-of-type) {
116+
padding-right: 0;
117+
padding-left: $mat-row-horizontal-padding;
118+
}
117119
}
118120
}
119121

0 commit comments

Comments
 (0)