Skip to content

Commit eb3bb44

Browse files
authored
Add shadow-initial and inset-shadow-initial utilities (#14468)
This PR complements #14458 by adding new `shadow-initial` and `inset-shadow-initial` utilities that make it possible to "undo" a custom shadow color and revert to the default shadow color for the current shadow size. For example, in this example the shadow will be red on hover even though the default color for the `shadow` utility is `rgb(0 0 0 / 5%)`: ```html <div class="shadow-sm shadow-red-500 hover:shadow"> <!-- … --> </div> ``` This is usually what you want, but if you actually want `hover:shadow` to apply its default color, you need to know what the color is and add it yourself: ```html <div class="shadow-sm shadow-red-500 hover:shadow hover:shadow-black/5"> <!-- … --> </div> ``` Using `shadow-initial`, you can achieve the same thing without having to know what the original color was: ```html <div class="shadow-sm shadow-red-500 hover:shadow hover:shadow-initial"> <!-- … --> </div> ``` The `inset-shadow-initial` utility does the same thing for the `inset-shadow-*` utilities. --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent bf115bf commit eb3bb44

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Add CSS codemods for migrating `@tailwind` directives ([#14411](https://github.com/tailwindlabs/tailwindcss/pull/14411))
1515
- Support `screens` in JS config files ([#14415](https://github.com/tailwindlabs/tailwindcss/pull/14415))
1616
- Add `bg-radial-*` and `bg-conic-*` utilities for radial and conic gradients ([#14467](https://github.com/tailwindlabs/tailwindcss/pull/14467))
17+
- Add new `shadow-initial` and `inset-shadow-initial` utilities for resetting shadow colors ([#14468](https://github.com/tailwindlabs/tailwindcss/pull/14468))
1718

1819
### Fixed
1920

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,6 +2324,7 @@ exports[`getClassList 1`] = `
23242324
"inset-shadow-inherit/90",
23252325
"inset-shadow-inherit/95",
23262326
"inset-shadow-inherit/100",
2327+
"inset-shadow-initial",
23272328
"inset-shadow-transparent",
23282329
"inset-shadow-transparent/0",
23292330
"inset-shadow-transparent/5",
@@ -3302,6 +3303,7 @@ exports[`getClassList 1`] = `
33023303
"shadow-inherit/90",
33033304
"shadow-inherit/95",
33043305
"shadow-inherit/100",
3306+
"shadow-initial",
33053307
"shadow-transparent",
33063308
"shadow-transparent/0",
33073309
"shadow-transparent/5",

packages/tailwindcss/src/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4270,6 +4270,8 @@ export function createUtilities(theme: Theme) {
42704270
])
42714271
}
42724272

4273+
staticUtility('shadow-initial', [boxShadowProperties, ['--tw-shadow-color', 'initial']])
4274+
42734275
utilities.functional('shadow', (candidate) => {
42744276
if (candidate.negative) return
42754277

@@ -4359,6 +4361,11 @@ export function createUtilities(theme: Theme) {
43594361
},
43604362
])
43614363

4364+
staticUtility('inset-shadow-initial', [
4365+
boxShadowProperties,
4366+
['--tw-inset-shadow-color', 'initial'],
4367+
])
4368+
43624369
utilities.functional('inset-shadow', (candidate) => {
43634370
if (candidate.negative) return
43644371

packages/tailwindcss/tests/ui.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ test('shadow colors', async ({ page }) => {
224224
<div id="b" class="shadow-xl shadow-red-500"></div>
225225
<div id="c" class="shadow-[0px_2px_4px] shadow-red-500"></div>
226226
<div id="d" class="shadow shadow-red-500 hover:shadow-xl">Hello world</div>
227+
<div id="e" class="shadow shadow-red-500 hover:shadow-xl hover:shadow-initial">
228+
Hello world
229+
</div>
227230
`,
228231
)
229232

@@ -276,6 +279,28 @@ test('shadow colors', async ({ page }) => {
276279
'rgb(239, 68, 68) 0px 20px 25px -5px, rgb(239, 68, 68) 0px 8px 10px -6px',
277280
].join(', '),
278281
)
282+
283+
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
284+
[
285+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
286+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
287+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
288+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
289+
'rgb(239, 68, 68) 0px 1px 3px 0px, rgb(239, 68, 68) 0px 1px 2px -1px',
290+
].join(', '),
291+
)
292+
293+
await page.locator('#e').hover()
294+
295+
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
296+
[
297+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
298+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
299+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
300+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
301+
'rgba(0, 0, 0, 0.1) 0px 20px 25px -5px, rgba(0, 0, 0, 0.1) 0px 8px 10px -6px',
302+
].join(', '),
303+
)
279304
})
280305

281306
test('inset shadow colors', async ({ page }) => {
@@ -286,6 +311,12 @@ test('inset shadow colors', async ({ page }) => {
286311
<div id="b" class="inset-shadow inset-shadow-red-500"></div>
287312
<div id="c" class="inset-shadow-[0px_3px_6px] inset-shadow-red-500"></div>
288313
<div id="d" class="inset-shadow-sm inset-shadow-red-500 hover:inset-shadow">Hello world</div>
314+
<div
315+
id="e"
316+
class="inset-shadow-sm inset-shadow-red-500 hover:inset-shadow hover:inset-shadow-initial"
317+
>
318+
Hello world
319+
</div>
289320
`,
290321
)
291322

@@ -338,6 +369,28 @@ test('inset shadow colors', async ({ page }) => {
338369
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
339370
].join(', '),
340371
)
372+
373+
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
374+
[
375+
'rgb(239, 68, 68) 0px 1px 1px 0px inset',
376+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
377+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
378+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
379+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
380+
].join(', '),
381+
)
382+
383+
await page.locator('#e').hover()
384+
385+
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
386+
[
387+
'rgba(0, 0, 0, 0.05) 0px 2px 4px 0px inset',
388+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
389+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
390+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
391+
'rgba(0, 0, 0, 0) 0px 0px 0px 0px',
392+
].join(', '),
393+
)
341394
})
342395

343396
test('outline style is optional', async ({ page }) => {

0 commit comments

Comments
 (0)