Skip to content

Commit 4e889e6

Browse files
committed
fix(card): remove extra margin if header doesn't have an avatar
The card header margin was set up assuming that there would always be an avatar element, but that's not always the case. These changes add an extra check to avoid the extra margin. Fixes #19069.
1 parent 695dde6 commit 4e889e6

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/dev-app/card/card-demo.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@
6060
</mat-card-content>
6161
</mat-card>
6262

63+
<!-- Used to test header without an avatar. -->
64+
<mat-card>
65+
<mat-card-header>
66+
<mat-card-title>Header title</mat-card-title>
67+
<mat-card-subtitle>Header subtitle</mat-card-subtitle>
68+
</mat-card-header>
69+
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
70+
<mat-card-content>
71+
<p>Here is some content</p>
72+
</mat-card-content>
73+
</mat-card>
74+
6375
<mat-card class="demo-card-blue mat-card-flat">
6476
<mat-card-title>Easily customizable</mat-card-title>
6577
<mat-card-actions>

src/dev-app/mdc-card/mdc-card-demo.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@
6363
</mat-card-content>
6464
</mat-card>
6565

66+
<!-- Used to test header without an avatar. -->
67+
<mat-card [class.mdc-card--outlined]="outlined">
68+
<mat-card-header>
69+
<mat-card-title>Header title</mat-card-title>
70+
<mat-card-subtitle>Header subtitle</mat-card-subtitle>
71+
</mat-card-header>
72+
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
73+
<mat-card-content>
74+
<p>Here is some content</p>
75+
</mat-card-content>
76+
</mat-card>
77+
6678
<mat-card class="demo-card-blue mat-card-flat" [class.mdc-card--outlined]="outlined">
6779
<mat-card-title>Easily customizable</mat-card-title>
6880
<mat-card-actions>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ $mat-card-default-padding: 16px !default;
2828
// Custom elements default to `display: inline`. Reset to 'block'.
2929
display: block;
3030

31-
// Apply default padding for a text content region. Omit any bottom padding because we assume
32-
// this region will be followed by another region that includes top padding.
33-
padding: $mat-card-default-padding $mat-card-default-padding 0;
31+
.mat-mdc-card-avatar ~ .mat-mdc-card-header-text & {
32+
// Apply default padding for a text content region. Omit any bottom padding because we assume
33+
// this region will be followed by another region that includes top padding.
34+
padding: $mat-card-default-padding $mat-card-default-padding 0;
35+
}
3436
}
3537

3638
// Header section at the top of a card. MDC does not have a pre-made header section for cards.
@@ -133,8 +135,11 @@ $mat-card-default-padding: 16px !default;
133135
// `mat-card-title-group` since the padding is captured by parent container already.
134136
.mat-mdc-card-subtitle ~ .mat-mdc-card-title,
135137
.mat-mdc-card-title ~ .mat-mdc-card-subtitle,
136-
.mat-mdc-card-header .mat-mdc-card-title,
137-
.mat-mdc-card-header .mat-mdc-card-subtitle,
138+
139+
// The `.mat-mdc-card-header-text` here is redundant since the header text
140+
// wrapper is always there in the header, but we need the extra specificity.
141+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-title,
142+
.mat-mdc-card-header .mat-mdc-card-header-text .mat-mdc-card-subtitle,
138143
.mat-mdc-card-title-group .mat-mdc-card-title,
139144
.mat-mdc-card-title-group .mat-mdc-card-subtitle {
140145
padding-top: 0;

src/material/card/card.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,17 @@ $mat-card-header-size: 40px !default;
103103
}
104104

105105
.mat-card-header-text {
106-
margin: 0 $mat-card-padding;
106+
&:not(:first-child) {
107+
margin-left: $mat-card-padding;
108+
}
109+
110+
[dir='rtl'] & {
111+
margin-left: 0;
112+
113+
&:not(:first-child) {
114+
margin-right: $mat-card-padding;
115+
}
116+
}
107117
}
108118

109119
.mat-card-avatar {

0 commit comments

Comments
 (0)