From cc6094e84fb128df914a16d3bb387fde32e426f0 Mon Sep 17 00:00:00 2001 From: Adam Wathan Date: Thu, 4 Apr 2024 18:01:37 -0400 Subject: [PATCH] Don't read variables for shadow sizes (#13449) * Don't read variables for shadow sizes * Add UI test * Handle key suffix in get function instead of ThemeKey * Remove duplicate theme keys * Format test in a less insane way * Revert playground changes * Update changelog --------- Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com> --- CHANGELOG.md | 1 + packages/tailwindcss/src/theme.ts | 2 +- packages/tailwindcss/src/utilities.test.ts | 8 +++--- packages/tailwindcss/src/utilities.ts | 5 ++-- packages/tailwindcss/tests/ui.spec.ts | 29 ++++++++++++++++++++++ 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 725a101d5..ca78cdf42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Enable Vite's `waitForRequestsIdle()` for client requests only ([#13394](https://github.com/tailwindlabs/tailwindcss/pull/13394)) - Make sure `::first-letter` respectes `::selection` styles ([#13408](https://github.com/tailwindlabs/tailwindcss/pull/13408)) +- Always inline values for `shadow-*` utilities to ensure shadow colors work correctly ([#13449](https://github.com/tailwindlabs/tailwindcss/pull/13449)) ## [4.0.0-alpha.11] - 2024-03-27 diff --git a/packages/tailwindcss/src/theme.ts b/packages/tailwindcss/src/theme.ts index e6af0ecde..8b5b5091c 100644 --- a/packages/tailwindcss/src/theme.ts +++ b/packages/tailwindcss/src/theme.ts @@ -42,7 +42,7 @@ export class Theme { return keys } - get(themeKeys: ThemeKey[]): string | null { + get(themeKeys: (ThemeKey | `${ThemeKey}-${string}`)[]): string | null { for (let key of themeKeys) { let value = this.values.get(key) if (value) { diff --git a/packages/tailwindcss/src/utilities.test.ts b/packages/tailwindcss/src/utilities.test.ts index 8427e7330..7ea5213ed 100644 --- a/packages/tailwindcss/src/utilities.test.ts +++ b/packages/tailwindcss/src/utilities.test.ts @@ -11492,8 +11492,8 @@ test('shadow', () => { } .shadow-xl { - --tw-shadow: var(--shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a); - --tw-shadow-colored: var(--shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a); + --tw-shadow: 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a; + --tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color); box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); } @@ -11725,8 +11725,8 @@ test('inset-shadow', () => { } .inset-shadow-sm { - --tw-inset-shadow: var(--inset-shadow-sm, inset 0 1px 1px #0000000d); - --tw-inset-shadow-colored: var(--inset-shadow-sm, inset 0 1px 1px #0000000d); + --tw-inset-shadow: inset 0 1px 1px #0000000d; + --tw-inset-shadow-colored: inset 0 1px 1px var(--tw-inset-shadow-color); box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow); } diff --git a/packages/tailwindcss/src/utilities.ts b/packages/tailwindcss/src/utilities.ts index 481e6712b..30647eb99 100644 --- a/packages/tailwindcss/src/utilities.ts +++ b/packages/tailwindcss/src/utilities.ts @@ -4171,7 +4171,7 @@ export function createUtilities(theme: Theme) { // Shadow size { - let value = theme.resolve(candidate.value.value, ['--shadow']) + let value = theme.get([`--shadow-${candidate.value.value}`]) if (value) { return [ boxShadowProperties(), @@ -4268,7 +4268,8 @@ export function createUtilities(theme: Theme) { // Shadow size { - let value = theme.resolve(candidate.value.value, ['--inset-shadow']) + let value = theme.get([`--inset-shadow-${candidate.value.value}`]) + if (value) { return [ boxShadowProperties(), diff --git a/packages/tailwindcss/tests/ui.spec.ts b/packages/tailwindcss/tests/ui.spec.ts index 9db3b880f..66fb34fa3 100644 --- a/packages/tailwindcss/tests/ui.spec.ts +++ b/packages/tailwindcss/tests/ui.spec.ts @@ -160,6 +160,35 @@ test('composing shadow, inset shadow, ring, and inset ring', async ({ page }) => ) }) +test('shadow colors', async ({ page }) => { + let { getPropertyValue } = await render( + page, + html` +
+
+ `, + ) + + expect(await getPropertyValue('#x', 'box-shadow')).toEqual( + [ + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgb(239, 68, 68) 0px 1px 3px 0px, rgb(239, 68, 68) 0px 1px 2px -1px', + ].join(', '), + ) + expect(await getPropertyValue('#y', 'box-shadow')).toEqual( + [ + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgba(0, 0, 0, 0) 0px 0px 0px 0px', + 'rgb(239, 68, 68) 0px 20px 25px -5px, rgb(239, 68, 68) 0px 8px 10px -6px', + ].join(', '), + ) +}) + test('outline style is optional', async ({ page }) => { let { getPropertyValue } = await render( page,