Skip to content

Commit 3dc3283

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 4778f49 commit 3dc3283

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
// calc is used here to support css variables
100121
calc(#{mat-font-size($config, body-1)} * 0.83),
@@ -106,7 +127,9 @@
106127
margin: 0 0 12px;
107128
}
108129

109-
.mat-h6, #{$selector} h6 {
130+
.mat-h6,
131+
#{$selector} .mat-h6,
132+
#{$selector} h6 {
110133
@include mat-typography-font-shorthand(
111134
// calc is used here to support css variables
112135
calc(#{mat-font-size($config, body-1)} * 0.67),
@@ -118,38 +141,52 @@
118141
margin: 0 0 12px;
119142
}
120143

121-
.mat-body-strong, .mat-body-2 {
144+
.mat-body-strong,
145+
.mat-body-2,
146+
#{$selector} .mat-body-strong,
147+
#{$selector} .mat-body-2 {
122148
@include mat-typography-level-to-styles($config, body-2);
123149
}
124150

125-
.mat-body, .mat-body-1, #{$selector} {
151+
.mat-body,
152+
.mat-body-1,
153+
#{$selector} .mat-body,
154+
#{$selector} .mat-body-1,
155+
#{$selector} {
126156
@include mat-typography-level-to-styles($config, body-1);
127157

128158
p {
129159
margin: 0 0 12px;
130160
}
131161
}
132162

133-
.mat-small, .mat-caption {
163+
.mat-small,
164+
.mat-caption,
165+
#{$selector} .mat-small,
166+
#{$selector} .mat-caption {
134167
@include mat-typography-level-to-styles($config, caption);
135168
}
136169

137-
.mat-display-4, #{$selector} .mat-display-4 {
170+
.mat-display-4,
171+
#{$selector} .mat-display-4 {
138172
@include mat-typography-level-to-styles($config, display-4);
139173
margin: 0 0 56px;
140174
}
141175

142-
.mat-display-3, #{$selector} .mat-display-3 {
176+
.mat-display-3,
177+
#{$selector} .mat-display-3 {
143178
@include mat-typography-level-to-styles($config, display-3);
144179
margin: 0 0 64px;
145180
}
146181

147-
.mat-display-2, #{$selector} .mat-display-2 {
182+
.mat-display-2,
183+
#{$selector} .mat-display-2 {
148184
@include mat-typography-level-to-styles($config, display-2);
149185
margin: 0 0 64px;
150186
}
151187

152-
.mat-display-1, #{$selector} .mat-display-1 {
188+
.mat-display-1,
189+
#{$selector} .mat-display-1 {
153190
@include mat-typography-level-to-styles($config, display-1);
154191
margin: 0 0 64px;
155192
}

0 commit comments

Comments
 (0)