Skip to content

Commit cc6094e

Browse files
authored
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 <[email protected]>
1 parent 34fea0e commit cc6094e

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- Enable Vite's `waitForRequestsIdle()` for client requests only ([#13394](https://github.com/tailwindlabs/tailwindcss/pull/13394))
1717
- Make sure `::first-letter` respectes `::selection` styles ([#13408](https://github.com/tailwindlabs/tailwindcss/pull/13408))
18+
- Always inline values for `shadow-*` utilities to ensure shadow colors work correctly ([#13449](https://github.com/tailwindlabs/tailwindcss/pull/13449))
1819

1920
## [4.0.0-alpha.11] - 2024-03-27
2021

packages/tailwindcss/src/theme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class Theme {
4242
return keys
4343
}
4444

45-
get(themeKeys: ThemeKey[]): string | null {
45+
get(themeKeys: (ThemeKey | `${ThemeKey}-${string}`)[]): string | null {
4646
for (let key of themeKeys) {
4747
let value = this.values.get(key)
4848
if (value) {

packages/tailwindcss/src/utilities.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11492,8 +11492,8 @@ test('shadow', () => {
1149211492
}
1149311493
1149411494
.shadow-xl {
11495-
--tw-shadow: var(--shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a);
11496-
--tw-shadow-colored: var(--shadow-xl, 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a);
11495+
--tw-shadow: 0 20px 25px -5px #0000001a, 0 8px 10px -6px #0000001a;
11496+
--tw-shadow-colored: 0 20px 25px -5px var(--tw-shadow-color), 0 8px 10px -6px var(--tw-shadow-color);
1149711497
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
1149811498
}
1149911499
@@ -11725,8 +11725,8 @@ test('inset-shadow', () => {
1172511725
}
1172611726
1172711727
.inset-shadow-sm {
11728-
--tw-inset-shadow: var(--inset-shadow-sm, inset 0 1px 1px #0000000d);
11729-
--tw-inset-shadow-colored: var(--inset-shadow-sm, inset 0 1px 1px #0000000d);
11728+
--tw-inset-shadow: inset 0 1px 1px #0000000d;
11729+
--tw-inset-shadow-colored: inset 0 1px 1px var(--tw-inset-shadow-color);
1173011730
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
1173111731
}
1173211732

packages/tailwindcss/src/utilities.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4171,7 +4171,7 @@ export function createUtilities(theme: Theme) {
41714171

41724172
// Shadow size
41734173
{
4174-
let value = theme.resolve(candidate.value.value, ['--shadow'])
4174+
let value = theme.get([`--shadow-${candidate.value.value}`])
41754175
if (value) {
41764176
return [
41774177
boxShadowProperties(),
@@ -4268,7 +4268,8 @@ export function createUtilities(theme: Theme) {
42684268

42694269
// Shadow size
42704270
{
4271-
let value = theme.resolve(candidate.value.value, ['--inset-shadow'])
4271+
let value = theme.get([`--inset-shadow-${candidate.value.value}`])
4272+
42724273
if (value) {
42734274
return [
42744275
boxShadowProperties(),

packages/tailwindcss/tests/ui.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,35 @@ test('composing shadow, inset shadow, ring, and inset ring', async ({ page }) =>
160160
)
161161
})
162162

163+
test('shadow colors', async ({ page }) => {
164+
let { getPropertyValue } = await render(
165+
page,
166+
html`
167+
<div id="x" class="shadow shadow-red-500"></div>
168+
<div id="y" class="shadow-xl shadow-red-500"></div>
169+
`,
170+
)
171+
172+
expect(await getPropertyValue('#x', 'box-shadow')).toEqual(
173+
[
174+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
175+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
176+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
177+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
178+
'rgb(239, 68, 68) 0px 1px 3px 0px, rgb(239, 68, 68) 0px 1px 2px -1px',
179+
].join(', '),
180+
)
181+
expect(await getPropertyValue('#y', 'box-shadow')).toEqual(
182+
[
183+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
184+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
185+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
186+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
187+
'rgb(239, 68, 68) 0px 20px 25px -5px, rgb(239, 68, 68) 0px 8px 10px -6px',
188+
].join(', '),
189+
)
190+
})
191+
163192
test('outline style is optional', async ({ page }) => {
164193
let { getPropertyValue } = await render(
165194
page,

0 commit comments

Comments
 (0)