Skip to content

Commit 299d086

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 d22f48c commit 299d086

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/lib/core/typography/_typography.scss

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

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

77-
.mat-h2, .mat-title, #{$selector} h2 {
84+
.mat-h2,
85+
.mat-title,
86+
#{$selector} .mat-h2,
87+
#{$selector} .mat-title,
88+
#{$selector} h2 {
7889
@include mat-typography-level-to-styles($config, title);
7990
margin: 0 0 16px;
8091
}
8192

82-
.mat-h3, .mat-subheading-2, #{$selector} h3 {
93+
.mat-h3,
94+
.mat-subheading-2,
95+
#{$selector} .mat-h3,
96+
#{$selector} .mat-subheading-2,
97+
#{$selector} h3 {
8398
@include mat-typography-level-to-styles($config, subheading-2);
8499
margin: 0 0 16px;
85100
}
86101

87-
.mat-h4, .mat-subheading-1, #{$selector} h4 {
102+
.mat-h4,
103+
.mat-subheading-1,
104+
#{$selector} .mat-h4,
105+
#{$selector} .mat-subheading-1,
106+
#{$selector} h4 {
88107
@include mat-typography-level-to-styles($config, subheading-1);
89108
margin: 0 0 16px;
90109
}
91110

92111
// Note: the spec doesn't have anything that would correspond to h5 and h6, but we add these for
93112
// consistency. The font sizes come from the Chrome user agent styles which have h5 at 0.83em
94113
// and h6 at 0.67em.
95-
.mat-h5, #{$selector} h5 {
114+
.mat-h5,
115+
#{$selector} .mat-h5,
116+
#{$selector} h5 {
96117
@include mat-typography-font-shorthand(
97118
mat-font-size($config, body-1) * 0.83,
98119
mat-font-weight($config, body-1),
@@ -103,7 +124,9 @@
103124
margin: 0 0 12px;
104125
}
105126

106-
.mat-h6, #{$selector} h6 {
127+
.mat-h6,
128+
#{$selector} .mat-h6,
129+
#{$selector} h6 {
107130
@include mat-typography-font-shorthand(
108131
mat-font-size($config, body-1) * 0.67,
109132
mat-font-weight($config, body-1),
@@ -114,43 +137,57 @@
114137
margin: 0 0 12px;
115138
}
116139

117-
.mat-body-strong, .mat-body-2 {
140+
.mat-body-strong,
141+
.mat-body-2,
142+
#{$selector} .mat-body-strong,
143+
#{$selector} .mat-body-2 {
118144
@include mat-typography-level-to-styles($config, body-2);
119145
}
120146

121-
.mat-body, .mat-body-1, #{$selector} {
147+
.mat-body,
148+
.mat-body-1,
149+
#{$selector} .mat-body,
150+
#{$selector} .mat-body-1,
151+
#{$selector} {
122152
@include mat-typography-level-to-styles($config, body-1);
123153

124154
p {
125155
margin: 0 0 12px;
126156
}
127157
}
128158

129-
.mat-small, .mat-caption {
159+
.mat-small,
160+
.mat-caption,
161+
#{$selector} .mat-small,
162+
#{$selector} .mat-caption {
130163
@include mat-typography-level-to-styles($config, caption);
131164
}
132165

133166
// Note: The spec doesn't mention letter spacing. The value comes from
134167
// eyeballing it until it looked exactly like the spec examples.
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
letter-spacing: -0.05em;
139173
}
140174

141-
.mat-display-3, #{$selector} .mat-display-3 {
175+
.mat-display-3,
176+
#{$selector} .mat-display-3 {
142177
@include mat-typography-level-to-styles($config, display-3);
143178
margin: 0 0 64px;
144179
letter-spacing: -0.02em;
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
letter-spacing: -0.005em;
151187
}
152188

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

0 commit comments

Comments
 (0)