Skip to content

Commit 1ec1445

Browse files
authored
Support spacing scale as line-height modifiers (#14966)
This PR fixes an issue where utilities like `text-sm/6` failed to include a line-height because `--leading-6` is no longer an explicitly defined theme value by default. I don't really love seeing `calc(var(--spacing) * 9)` in the output here admittedly and it's making me consider again if we should register this variable as `inline` so we see the final computed value in the CSS, but if we do that it's something we should change in a separate PR. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent d2c2749 commit 1ec1445

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

CHANGELOG.md

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

1212
- Don't reset horizontal padding on date/time pseudo-elements ([#14959](https://github.com/tailwindlabs/tailwindcss/pull/14959))
1313
- Don't emit `calc()` with invalid values for bare values that aren't integers in spacing utilities ([#14962](https://github.com/tailwindlabs/tailwindcss/pull/14962))
14+
- Ensure spacing scale values work as line-height modifiers ([#14966](https://github.com/tailwindlabs/tailwindcss/pull/14966))
1415

1516
## [4.0.0-alpha.32] - 2024-11-11
1617

packages/tailwindcss/src/utilities.test.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -14811,11 +14811,10 @@ test('text', async () => {
1481114811
await compileCss(
1481214812
css`
1481314813
@theme {
14814+
--spacing: 0.25rem;
1481414815
--color-red-500: #ef4444;
14815-
--leading-6: 1.5rem;
1481614816
--text-sm: 0.875rem;
1481714817
--text-sm--line-height: 1.25rem;
14818-
--leading-9: 2.25rem;
1481914818
}
1482014819
@tailwind utilities;
1482114820
`,
@@ -14868,11 +14867,10 @@ test('text', async () => {
1486814867
),
1486914868
).toMatchInlineSnapshot(`
1487014869
":root {
14870+
--spacing: .25rem;
1487114871
--color-red-500: #ef4444;
14872-
--leading-6: 1.5rem;
1487314872
--text-sm: .875rem;
1487414873
--text-sm--line-height: 1.25rem;
14875-
--leading-9: 2.25rem;
1487614874
}
1487714875
1487814876
.text-sm {
@@ -14882,32 +14880,32 @@ test('text', async () => {
1488214880
1488314881
.text-\\[12px\\]\\/6 {
1488414882
font-size: 12px;
14885-
line-height: var(--leading-6);
14883+
line-height: calc(var(--spacing) * 6);
1488614884
}
1488714885
1488814886
.text-\\[50\\%\\]\\/6 {
1488914887
font-size: 50%;
14890-
line-height: var(--leading-6);
14888+
line-height: calc(var(--spacing) * 6);
1489114889
}
1489214890
1489314891
.text-\\[clamp\\(1rem\\,var\\(--size\\)\\,3rem\\)\\]\\/9 {
1489414892
font-size: clamp(1rem, var(--size), 3rem);
14895-
line-height: var(--leading-9);
14893+
line-height: calc(var(--spacing) * 9);
1489614894
}
1489714895
1489814896
.text-\\[larger\\]\\/6 {
1489914897
font-size: larger;
14900-
line-height: var(--leading-6);
14898+
line-height: calc(var(--spacing) * 6);
1490114899
}
1490214900
1490314901
.text-\\[xx-large\\]\\/6 {
1490414902
font-size: xx-large;
14905-
line-height: var(--leading-6);
14903+
line-height: calc(var(--spacing) * 6);
1490614904
}
1490714905
1490814906
.text-sm\\/6 {
1490914907
font-size: var(--text-sm);
14910-
line-height: var(--leading-6);
14908+
line-height: calc(var(--spacing) * 6);
1491114909
}
1491214910
1491314911
.text-sm\\/\\[4px\\] {

packages/tailwindcss/src/utilities.ts

+12
Original file line numberDiff line numberDiff line change
@@ -3902,6 +3902,12 @@ export function createUtilities(theme: Theme) {
39023902
? candidate.modifier.value
39033903
: theme.resolve(candidate.modifier.value, ['--leading'])
39043904

3905+
if (!modifier && isValidSpacingMultiplier(candidate.modifier.value)) {
3906+
let multiplier = theme.resolve(null, ['--spacing'])
3907+
if (!multiplier) return null
3908+
modifier = `calc(${multiplier} * ${candidate.modifier.value})`
3909+
}
3910+
39053911
if (modifier) {
39063912
return [decl('font-size', value), decl('line-height', modifier)]
39073913
}
@@ -3942,6 +3948,12 @@ export function createUtilities(theme: Theme) {
39423948
? candidate.modifier.value
39433949
: theme.resolve(candidate.modifier.value, ['--leading'])
39443950

3951+
if (!modifier && isValidSpacingMultiplier(candidate.modifier.value)) {
3952+
let multiplier = theme.resolve(null, ['--spacing'])
3953+
if (!multiplier) return null
3954+
modifier = `calc(${multiplier} * ${candidate.modifier.value})`
3955+
}
3956+
39453957
let declarations = [decl('font-size', fontSize)]
39463958
modifier && declarations.push(decl('line-height', modifier))
39473959
return declarations

0 commit comments

Comments
 (0)