Skip to content

Commit 0926e86

Browse files
committed
fix(material/core): 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 26fc03e commit 0926e86

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
@@ -183,30 +183,51 @@
183183
@mixin typography-hierarchy($config-or-theme, $selector: '.mat-typography') {
184184
$config: private-typography-to-2014-config(theming.get-typography-config($config-or-theme));
185185

186-
.mat-h1, .mat-headline, #{$selector} h1 {
186+
// Note that it seems redundant to prefix the class rules with the `$selector`, however it's
187+
// necessary if we want to allow people to overwrite the tag selectors. This is due to
188+
// selectors like `#{$selector} h1` being more specific than ones like `.mat-title`.
189+
.mat-h1,
190+
.mat-headline,
191+
#{$selector} .mat-h1,
192+
#{$selector} .mat-headline,
193+
#{$selector} h1 {
187194
@include typography-utils.typography-level($config, headline);
188195
margin: 0 0 16px;
189196
}
190197

191-
.mat-h2, .mat-title, #{$selector} h2 {
198+
.mat-h2,
199+
.mat-title,
200+
#{$selector} .mat-h2,
201+
#{$selector} .mat-title,
202+
#{$selector} h2 {
192203
@include typography-utils.typography-level($config, title);
193204
margin: 0 0 16px;
194205
}
195206

196-
.mat-h3, .mat-subheading-2, #{$selector} h3 {
207+
.mat-h3,
208+
.mat-subheading-2,
209+
#{$selector} .mat-h3,
210+
#{$selector} .mat-subheading-2,
211+
#{$selector} h3 {
197212
@include typography-utils.typography-level($config, subheading-2);
198213
margin: 0 0 16px;
199214
}
200215

201-
.mat-h4, .mat-subheading-1, #{$selector} h4 {
216+
.mat-h4,
217+
.mat-subheading-1,
218+
#{$selector} .mat-h4,
219+
#{$selector} .mat-subheading-1,
220+
#{$selector} h4 {
202221
@include typography-utils.typography-level($config, subheading-1);
203222
margin: 0 0 16px;
204223
}
205224

206225
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
207226
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
208227
// and h6 at 0.67em.
209-
.mat-h5, #{$selector} h5 {
228+
.mat-h5,
229+
#{$selector} .mat-h5,
230+
#{$selector} h5 {
210231
@include typography-utils.font-shorthand(
211232
// calc is used here to support css variables
212233
calc(#{typography-utils.font-size($config, body-1)} * 0.83),
@@ -218,7 +239,9 @@
218239
margin: 0 0 12px;
219240
}
220241

221-
.mat-h6, #{$selector} h6 {
242+
.mat-h6,
243+
#{$selector} .mat-h6,
244+
#{$selector} h6 {
222245
@include typography-utils.font-shorthand(
223246
// calc is used here to support css variables
224247
calc(#{typography-utils.font-size($config, body-1)} * 0.67),
@@ -230,38 +253,52 @@
230253
margin: 0 0 12px;
231254
}
232255

233-
.mat-body-strong, .mat-body-2 {
256+
.mat-body-strong,
257+
.mat-body-2,
258+
#{$selector} .mat-body-strong,
259+
#{$selector} .mat-body-2 {
234260
@include typography-utils.typography-level($config, body-2);
235261
}
236262

237-
.mat-body, .mat-body-1, #{$selector} {
263+
.mat-body,
264+
.mat-body-1,
265+
#{$selector} .mat-body,
266+
#{$selector} .mat-body-1,
267+
#{$selector} {
238268
@include typography-utils.typography-level($config, body-1);
239269

240270
p {
241271
margin: 0 0 12px;
242272
}
243273
}
244274

245-
.mat-small, .mat-caption {
275+
.mat-small,
276+
.mat-caption,
277+
#{$selector} .mat-small,
278+
#{$selector} .mat-caption {
246279
@include typography-utils.typography-level($config, caption);
247280
}
248281

249-
.mat-display-4, #{$selector} .mat-display-4 {
282+
.mat-display-4,
283+
#{$selector} .mat-display-4 {
250284
@include typography-utils.typography-level($config, display-4);
251285
margin: 0 0 56px;
252286
}
253287

254-
.mat-display-3, #{$selector} .mat-display-3 {
288+
.mat-display-3,
289+
#{$selector} .mat-display-3 {
255290
@include typography-utils.typography-level($config, display-3);
256291
margin: 0 0 64px;
257292
}
258293

259-
.mat-display-2, #{$selector} .mat-display-2 {
294+
.mat-display-2,
295+
#{$selector} .mat-display-2 {
260296
@include typography-utils.typography-level($config, display-2);
261297
margin: 0 0 64px;
262298
}
263299

264-
.mat-display-1, #{$selector} .mat-display-1 {
300+
.mat-display-1,
301+
#{$selector} .mat-display-1 {
265302
@include typography-utils.typography-level($config, display-1);
266303
margin: 0 0 64px;
267304
}

0 commit comments

Comments
 (0)