Skip to content

Commit ee0d752

Browse files
Hide default shadow suggestions when missing theme keys (#17743)
Right now if you have a completely empty theme we'll still suggest `shadow`, `inset-shadow`, and `text-shadow` as utilities even tho they won't exist. This fixes this by checking for the theme key when computing the suggestions.
1 parent fc4afc2 commit ee0d752

File tree

3 files changed

+33
-69
lines changed

3 files changed

+33
-69
lines changed

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

-66
Original file line numberDiff line numberDiff line change
@@ -4755,28 +4755,6 @@ exports[`getClassList 1`] = `
47554755
"inset-ring-transparent/90",
47564756
"inset-ring-transparent/95",
47574757
"inset-ring-transparent/100",
4758-
"inset-shadow",
4759-
"inset-shadow/0",
4760-
"inset-shadow/5",
4761-
"inset-shadow/10",
4762-
"inset-shadow/15",
4763-
"inset-shadow/20",
4764-
"inset-shadow/25",
4765-
"inset-shadow/30",
4766-
"inset-shadow/35",
4767-
"inset-shadow/40",
4768-
"inset-shadow/45",
4769-
"inset-shadow/50",
4770-
"inset-shadow/55",
4771-
"inset-shadow/60",
4772-
"inset-shadow/65",
4773-
"inset-shadow/70",
4774-
"inset-shadow/75",
4775-
"inset-shadow/80",
4776-
"inset-shadow/85",
4777-
"inset-shadow/90",
4778-
"inset-shadow/95",
4779-
"inset-shadow/100",
47804758
"inset-shadow-current",
47814759
"inset-shadow-current/0",
47824760
"inset-shadow-current/5",
@@ -9685,28 +9663,6 @@ exports[`getClassList 1`] = `
96859663
"sepia-0",
96869664
"sepia-50",
96879665
"sepia-100",
9688-
"shadow",
9689-
"shadow/0",
9690-
"shadow/5",
9691-
"shadow/10",
9692-
"shadow/15",
9693-
"shadow/20",
9694-
"shadow/25",
9695-
"shadow/30",
9696-
"shadow/35",
9697-
"shadow/40",
9698-
"shadow/45",
9699-
"shadow/50",
9700-
"shadow/55",
9701-
"shadow/60",
9702-
"shadow/65",
9703-
"shadow/70",
9704-
"shadow/75",
9705-
"shadow/80",
9706-
"shadow/85",
9707-
"shadow/90",
9708-
"shadow/95",
9709-
"shadow/100",
97109666
"shadow-current",
97119667
"shadow-current/0",
97129668
"shadow-current/5",
@@ -10157,28 +10113,6 @@ exports[`getClassList 1`] = `
1015710113
"text-nowrap",
1015810114
"text-pretty",
1015910115
"text-right",
10160-
"text-shadow",
10161-
"text-shadow/0",
10162-
"text-shadow/5",
10163-
"text-shadow/10",
10164-
"text-shadow/15",
10165-
"text-shadow/20",
10166-
"text-shadow/25",
10167-
"text-shadow/30",
10168-
"text-shadow/35",
10169-
"text-shadow/40",
10170-
"text-shadow/45",
10171-
"text-shadow/50",
10172-
"text-shadow/55",
10173-
"text-shadow/60",
10174-
"text-shadow/65",
10175-
"text-shadow/70",
10176-
"text-shadow/75",
10177-
"text-shadow/80",
10178-
"text-shadow/85",
10179-
"text-shadow/90",
10180-
"text-shadow/95",
10181-
"text-shadow/100",
1018210116
"text-shadow-current",
1018310117
"text-shadow-current/0",
1018410118
"text-shadow-current/5",

packages/tailwindcss/src/intellisense.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -598,3 +598,33 @@ test('Theme keys with underscores are suggested with underscores', async () => {
598598
expect(entries).not.toContainEqual(['p-2_5', { modifiers: [] }])
599599
expect(entries).not.toContainEqual(['p-logo.margin', { modifiers: [] }])
600600
})
601+
602+
test('shadow utility default suggestions', async () => {
603+
let input = css`
604+
@theme {
605+
/* nothing */
606+
}
607+
`
608+
609+
let design = await __unstable__loadDesignSystem(input)
610+
let classNames = design.getClassList().map(([name]) => name)
611+
612+
expect(classNames).not.toContain('shadow')
613+
expect(classNames).not.toContain('inset-shadow')
614+
expect(classNames).not.toContain('text-shadow')
615+
616+
input = css`
617+
@theme {
618+
--shadow: 0 0 0 solid black;
619+
--text-shadow: 0 0 0 solid black;
620+
--inset-shadow: 0 0 0 solid black;
621+
}
622+
`
623+
624+
design = await __unstable__loadDesignSystem(input)
625+
classNames = design.getClassList().map(([name]) => name)
626+
627+
expect(classNames).toContain('shadow')
628+
expect(classNames).toContain('inset-shadow')
629+
expect(classNames).toContain('text-shadow')
630+
})

packages/tailwindcss/src/utilities.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5182,7 +5182,7 @@ export function createUtilities(theme: Theme) {
51825182
{
51835183
valueThemeKeys: ['--text-shadow'],
51845184
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
5185-
hasDefaultValue: true,
5185+
hasDefaultValue: theme.get(['--text-shadow']) !== null,
51865186
},
51875187
])
51885188

@@ -5335,7 +5335,7 @@ export function createUtilities(theme: Theme) {
53355335
{
53365336
valueThemeKeys: ['--shadow'],
53375337
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
5338-
hasDefaultValue: true,
5338+
hasDefaultValue: theme.get(['--shadow']) !== null,
53395339
},
53405340
])
53415341

@@ -5462,7 +5462,7 @@ export function createUtilities(theme: Theme) {
54625462
{
54635463
valueThemeKeys: ['--inset-shadow'],
54645464
modifiers: Array.from({ length: 21 }, (_, index) => `${index * 5}`),
5465-
hasDefaultValue: true,
5465+
hasDefaultValue: theme.get(['--inset-shadow']) !== null,
54665466
},
54675467
])
54685468

0 commit comments

Comments
 (0)