From 691c30a37f51bed2e22d22b443735c45b1ad9e75 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 15 Jun 2022 14:53:37 -0400 Subject: [PATCH 1/2] Ensure default alpha is 1.0 when using new `` format with the theme function --- src/lib/evaluateTailwindFunctions.js | 12 +++++++--- tests/evaluateTailwindFunctions.test.js | 30 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/lib/evaluateTailwindFunctions.js b/src/lib/evaluateTailwindFunctions.js index c6c86c62276e..4fcfa83d9f47 100644 --- a/src/lib/evaluateTailwindFunctions.js +++ b/src/lib/evaluateTailwindFunctions.js @@ -183,9 +183,15 @@ export default function ({ tailwindConfig: config }) { throw node.error(error) } - if (alpha !== undefined) { - value = parseColorFormat(value) - value = withAlphaValue(value, alpha, value) + let maybeColor = parseColorFormat(value) + let isColorFunction = maybeColor !== undefined && typeof maybeColor === 'function' + + if (alpha !== undefined || isColorFunction) { + if (alpha === undefined) { + alpha = 1.0 + } + + value = withAlphaValue(maybeColor, alpha, maybeColor) } return value diff --git a/tests/evaluateTailwindFunctions.test.js b/tests/evaluateTailwindFunctions.test.js index 30976e3ad222..b5e97a396a72 100644 --- a/tests/evaluateTailwindFunctions.test.js +++ b/tests/evaluateTailwindFunctions.test.js @@ -1025,6 +1025,36 @@ test('Theme function can extract alpha values for colors (8)', () => { }) }) +test('Theme functions replace the alpha value placeholder even with no alpha provided', () => { + let input = css` + .foo { + background: theme(colors.blue.400); + color: theme(colors.blue.500); + } + ` + + let output = css` + .foo { + background: rgb(0 0 255 / 1); + color: rgb(var(--foo) / 1); + } + ` + + return runFull(input, { + theme: { + colors: { + blue: { + 400: 'rgb(0 0 255 / )', + 500: 'rgb(var(--foo) / )', + }, + }, + }, + }).then((result) => { + expect(result.css).toMatchCss(output) + expect(result.warnings().length).toBe(0) + }) +}) + test('Theme functions can reference values with slashes in brackets', () => { let input = css` .foo1 { From ebce1619ae79941747bffda1a2c97e2d844eb99c Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 15 Jun 2022 14:57:24 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40f5812d63f2..ab7803c3ee99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix "Maximum call stack size exceeded" bug ([#8636](https://github.com/tailwindlabs/tailwindcss/pull/8636)) - Allow functions returning parallel variants to mutate the container ([#8622](https://github.com/tailwindlabs/tailwindcss/pull/8622)) - Remove text opacity CSS variables from `::marker` ([#8622](https://github.com/tailwindlabs/tailwindcss/pull/8622)) +- Provide default to `` when using `theme()` ([#8622](https://github.com/tailwindlabs/tailwindcss/pull/8622)) ## [3.1.2] - 2022-06-10