Skip to content

Commit 178c58c

Browse files
committed
fix(typography): unable to override tag selectors inside .mat-typography
Currently we've got two sets of typography selectors: some that target tags under `.mat-typography` (e.g. `.mat-typography h1`) and others that target a specific class (e.g. `.mat-title`). The intention with the class selectors was also to allow for the styles of a tag to be replaced (e.g. having an `h3` look like an `h2` if necessary), however that wasn't possible while inside `.mat-typography`, because the tag selectors were more specific. These changes update the class selectors to make it possible to override the tag selectors. Fixes #14597.
1 parent 03a9a39 commit 178c58c

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/material/core/typography/_typography.scss

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,30 +71,51 @@
7171

7272
// Adds the base typography styles, based on a config.
7373
@mixin mat-base-typography($config, $selector: '.mat-typography') {
74-
.mat-h1, .mat-headline, #{$selector} h1 {
74+
// Note that it seems redundant to prefix the class rules with the `$selector`, however it's
75+
// necessary if we want to allow people to overwrite the tag selectors. This is due to
76+
// selectors like `#{$selector} h1` being more specific than ones like `.mat-title`.
77+
.mat-h1,
78+
.mat-headline,
79+
#{$selector} .mat-h1,
80+
#{$selector} .mat-headline,
81+
#{$selector} h1 {
7582
@include mat-typography-level-to-styles($config, headline);
7683
margin: 0 0 16px;
7784
}
7885

79-
.mat-h2, .mat-title, #{$selector} h2 {
86+
.mat-h2,
87+
.mat-title,
88+
#{$selector} .mat-h2,
89+
#{$selector} .mat-title,
90+
#{$selector} h2 {
8091
@include mat-typography-level-to-styles($config, title);
8192
margin: 0 0 16px;
8293
}
8394

84-
.mat-h3, .mat-subheading-2, #{$selector} h3 {
95+
.mat-h3,
96+
.mat-subheading-2,
97+
#{$selector} .mat-h3,
98+
#{$selector} .mat-subheading-2,
99+
#{$selector} h3 {
85100
@include mat-typography-level-to-styles($config, subheading-2);
86101
margin: 0 0 16px;
87102
}
88103

89-
.mat-h4, .mat-subheading-1, #{$selector} h4 {
104+
.mat-h4,
105+
.mat-subheading-1,
106+
#{$selector} .mat-h4,
107+
#{$selector} .mat-subheading-1,
108+
#{$selector} h4 {
90109
@include mat-typography-level-to-styles($config, subheading-1);
91110
margin: 0 0 16px;
92111
}
93112

94113
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
95114
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
96115
// and h6 at 0.67em.
97-
.mat-h5, #{$selector} h5 {
116+
.mat-h5,
117+
#{$selector} .mat-h5,
118+
#{$selector} h5 {
98119
@include mat-typography-font-shorthand(
99120
mat-font-size($config, body-1) * 0.83,
100121
mat-font-weight($config, body-1),
@@ -105,7 +126,9 @@
105126
margin: 0 0 12px;
106127
}
107128

108-
.mat-h6, #{$selector} h6 {
129+
.mat-h6,
130+
#{$selector} .mat-h6,
131+
#{$selector} h6 {
109132
@include mat-typography-font-shorthand(
110133
mat-font-size($config, body-1) * 0.67,
111134
mat-font-weight($config, body-1),
@@ -116,38 +139,52 @@
116139
margin: 0 0 12px;
117140
}
118141

119-
.mat-body-strong, .mat-body-2 {
142+
.mat-body-strong,
143+
.mat-body-2,
144+
#{$selector} .mat-body-strong,
145+
#{$selector} .mat-body-2 {
120146
@include mat-typography-level-to-styles($config, body-2);
121147
}
122148

123-
.mat-body, .mat-body-1, #{$selector} {
149+
.mat-body,
150+
.mat-body-1,
151+
#{$selector} .mat-body,
152+
#{$selector} .mat-body-1,
153+
#{$selector} {
124154
@include mat-typography-level-to-styles($config, body-1);
125155

126156
p {
127157
margin: 0 0 12px;
128158
}
129159
}
130160

131-
.mat-small, .mat-caption {
161+
.mat-small,
162+
.mat-caption,
163+
#{$selector} .mat-small,
164+
#{$selector} .mat-caption {
132165
@include mat-typography-level-to-styles($config, caption);
133166
}
134167

135-
.mat-display-4, #{$selector} .mat-display-4 {
168+
.mat-display-4,
169+
#{$selector} .mat-display-4 {
136170
@include mat-typography-level-to-styles($config, display-4);
137171
margin: 0 0 56px;
138172
}
139173

140-
.mat-display-3, #{$selector} .mat-display-3 {
174+
.mat-display-3,
175+
#{$selector} .mat-display-3 {
141176
@include mat-typography-level-to-styles($config, display-3);
142177
margin: 0 0 64px;
143178
}
144179

145-
.mat-display-2, #{$selector} .mat-display-2 {
180+
.mat-display-2,
181+
#{$selector} .mat-display-2 {
146182
@include mat-typography-level-to-styles($config, display-2);
147183
margin: 0 0 64px;
148184
}
149185

150-
.mat-display-1, #{$selector} .mat-display-1 {
186+
.mat-display-1,
187+
#{$selector} .mat-display-1 {
151188
@include mat-typography-level-to-styles($config, display-1);
152189
margin: 0 0 64px;
153190
}

0 commit comments

Comments
 (0)