Skip to content
Merged
Prev Previous commit
Next Next commit
Fixes
  • Loading branch information
philipp-spiess committed Mar 18, 2025
commit feb93a9f191ebb7cedc58cb174c547c51a42cdab
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ exports[`compiling CSS > prefix all CSS variables inside preflight 1`] = `

::placeholder {
opacity: 1;
color: color-mix(in oklab, currentColor 50%, transparent);
color: oklab(from currentColor l a b / 50%);
}

textarea {
Expand Down
14 changes: 7 additions & 7 deletions packages/tailwindcss/src/css-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('--theme(…)', () => {
`)
})

test('--theme(…) injects the fallback when the value it refers is set to a `--theme(…)` function containing `initial`', async () => {
test('--theme(…) injects the fallback when the value it refers is set to a `--theme(…)` function with the fallback `initial`', async () => {
expect(
await compileCss(css`
@theme prefix(tw) {
Expand All @@ -235,7 +235,7 @@ describe('--theme(…)', () => {
`)
})

test('--theme(…) injects the fallback when the value it refers is set to a `--theme(…)` function containing `initial` in @reference mode', async () => {
test('--theme(…) injects the fallback when the value it refers is set to a `--theme(…)` function with the fallback `initial` in @reference mode', async () => {
expect(
await compileCss(css`
@theme reference prefix(tw) {
Expand All @@ -252,7 +252,7 @@ describe('--theme(…)', () => {
`)
})

test('--theme(…) returns the fallback when the value it refers is set to a `--theme(…)` function that returns `initial` as inline value', async () => {
test('--theme(…) resolves with the fallback when the value it refers is set to a `--theme(… inline)` function with the fallback `initial`', async () => {
expect(
await compileCss(css`
@theme prefix(tw) {
Expand All @@ -269,19 +269,19 @@ describe('--theme(…)', () => {
`)
})

test('--theme(…) returns the fallback when the value it refers is set to a `--theme(…)` function that returns `initial` as inline value in @reference mode', async () => {
test('--theme(…) resolves with the fallback when the value it refers is set to a `--theme(… inline)` function with the fallback `initial` in @reference mode', async () => {
expect(
await compileCss(css`
@theme reference prefix(tw) {
--default-font-family: --theme(--font-family, initial);
--default-font-family: --theme(--font-family inline, initial);
}
.red {
font-family: --theme(--default-font-family, Potato Sans, sans-serif);
font-family: --theme(--default-font-family inline, Potato Sans, sans-serif);
}
`),
).toMatchInlineSnapshot(`
".red {
font-family: var(--tw-default-font-family, Potato Sans, sans-serif);
font-family: Potato Sans, sans-serif;
}"
`)
})
Expand Down
13 changes: 8 additions & 5 deletions packages/tailwindcss/src/css-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,17 @@ function theme(
return resolvedValue
}

// Inject the fallback…
//
// - …as the value if the value returned is `initial`
// - …expect any `initial` fallbacks on `var(…)`, `theme(…)`, or `--theme(…)`
// - …as the fallback if a `var(…)` with no fallback is returned
let joinedFallback = fallback.join(', ')
if (joinedFallback === 'initial') return resolvedValue

// When the resolved value returns `initial`, resolve with the the fallback value
if (resolvedValue === 'initial') return joinedFallback

// Inject the fallback of a `--theme(…)` function into the fallback of a referenced `--theme(…)`
// function or `var(…)` declaration. If the referenced function already defines a fallback, we use
// a potential fallback value of `initial` in the referenced function to determine if we should
// inject the fallback value of the caller. If that's not the case, we keep the fallback as-is
// (this is needed for theme variables in reference-mode).
if (
resolvedValue.startsWith('var(') ||
resolvedValue.startsWith('theme(') ||
Expand Down