Skip to content

Commit ea10bb9

Browse files
authored
Add line-height modifier for font-size utilities (#9875)
* Add line-height modifier for font-size utilities * Add test for arbitrary values * Add failing test for non-configured modifier values * Add more tests (including failing case) * Remove unused code * Add note + failing test * Remove unused code * Fix test * Fix test * Update changelog Co-authored-by: Adam Wathan <[email protected]>
1 parent 0d9e190 commit ea10bb9

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `line-height` modifier support to `font-size` utilities ([#9875](https://github.com/tailwindlabs/tailwindcss/pull/9875))
13+
1014
### Fixed
1115

1216
- Cleanup unused `variantOrder` ([#9829](https://github.com/tailwindlabs/tailwindcss/pull/9829))

src/corePlugins.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,16 @@ export let corePlugins = {
18341834
fontSize: ({ matchUtilities, theme }) => {
18351835
matchUtilities(
18361836
{
1837-
text: (value) => {
1837+
text: (value, { modifier }) => {
18381838
let [fontSize, options] = Array.isArray(value) ? value : [value]
1839+
1840+
if (modifier) {
1841+
return {
1842+
'font-size': fontSize,
1843+
'line-height': modifier,
1844+
}
1845+
}
1846+
18391847
let { lineHeight, letterSpacing, fontWeight } = isPlainObject(options)
18401848
? options
18411849
: { lineHeight: options }
@@ -1850,6 +1858,7 @@ export let corePlugins = {
18501858
},
18511859
{
18521860
values: theme('fontSize'),
1861+
modifiers: theme('lineHeight'),
18531862
type: ['absolute-size', 'relative-size', 'length', 'percentage'],
18541863
}
18551864
)

tests/match-utilities.test.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ test('match utilities with modifiers', async () => {
44
let config = {
55
content: [
66
{
7-
raw: html`<div class="test test/foo test-1/foo test-2/foo test/[foo] test-1/[foo]"></div> `,
7+
raw: html`<div
8+
class="test test/foo test-1/foo test-2/foo test/[foo] test-1/[foo] test-[8]/[9]"
9+
></div> `,
810
},
911
],
1012
corePlugins: { preflight: false },
@@ -24,6 +26,7 @@ test('match utilities with modifiers', async () => {
2426
'1': 'one',
2527
'2': 'two',
2628
'1/foo': 'onefoo',
29+
'[8]/[9]': 'eightnine',
2730
},
2831
modifiers: 'any',
2932
}
@@ -57,6 +60,9 @@ test('match utilities with modifiers', async () => {
5760
.test-1\/\[foo\] {
5861
color: one_[foo];
5962
}
63+
.test-\[8\]\/\[9\] {
64+
color: eightnine_null;
65+
}
6066
`)
6167
})
6268

tests/plugins/fontSize.test.js

+74
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,77 @@ test('font-size utilities can include a font-weight', () => {
119119
`)
120120
})
121121
})
122+
123+
test('font-size utilities can include a line-height modifier', () => {
124+
let config = {
125+
content: [
126+
{
127+
raw: html`<div class="text-sm md:text-base">
128+
<div class="text-sm/6 md:text-base/7"></div>
129+
<div class="text-sm/[21px] md:text-base/[33px]"></div>
130+
<div class="text-[13px]/6 md:text-[19px]/8"></div>
131+
<div class="text-[17px]/[23px] md:text-[21px]/[29px]"></div>
132+
<div class="text-sm/999 md:text-base/000"></div>
133+
</div>`,
134+
},
135+
],
136+
theme: {
137+
fontSize: {
138+
sm: ['12px', '20px'],
139+
base: ['16px', '24px'],
140+
},
141+
lineHeight: {
142+
6: '24px',
143+
7: '28px',
144+
8: '32px',
145+
},
146+
},
147+
}
148+
149+
return run('@tailwind utilities', config).then((result) => {
150+
expect(result.css).toMatchCss(css`
151+
.text-sm {
152+
font-size: 12px;
153+
line-height: 20px;
154+
}
155+
.text-sm\/6 {
156+
font-size: 12px;
157+
line-height: 24px;
158+
}
159+
.text-sm\/\[21px\] {
160+
font-size: 12px;
161+
line-height: 21px;
162+
}
163+
.text-\[13px\]\/6 {
164+
font-size: 13px;
165+
line-height: 24px;
166+
}
167+
.text-\[17px\]\/\[23px\] {
168+
font-size: 17px;
169+
line-height: 23px;
170+
}
171+
@media (min-width: 768px) {
172+
.md\:text-base {
173+
font-size: 16px;
174+
line-height: 24px;
175+
}
176+
.md\:text-base\/7 {
177+
font-size: 16px;
178+
line-height: 28px;
179+
}
180+
.md\:text-base\/\[33px\] {
181+
font-size: 16px;
182+
line-height: 33px;
183+
}
184+
.md\:text-\[19px\]\/8 {
185+
font-size: 19px;
186+
line-height: 32px;
187+
}
188+
.md\:text-\[21px\]\/\[29px\] {
189+
font-size: 21px;
190+
line-height: 29px;
191+
}
192+
}
193+
`)
194+
})
195+
})

0 commit comments

Comments
 (0)