Skip to content

Commit 8165e04

Browse files
Show suggestions for known matchVariant values (#18798)
Given this variant: ```js matchVariant( "foo", (value) => `&:is([data-foo='${value}'])`, { values: { DEFAULT: "", bar: "bar", baz: "bar", }, } ) ``` We weren't listing `foo-bar` and `foo-baz` in IntelliSense. This PR fixes that.
1 parent ee987e3 commit 8165e04

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Don't transition `visibility` when using `transition` ([#18795](https://github.com/tailwindlabs/tailwindcss/pull/18795))
1717
- Discard matched variants with unknown named values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
1818
- Discard matched variants with non-string values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
19+
- Show suggestions for known `matchVariant` values ([#18798](https://github.com/tailwindlabs/tailwindcss/pull/18798))
1920

2021
## [4.1.12] - 2025-08-13
2122

packages/tailwindcss/src/compat/plugin-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ export function buildPluginApi({
247247
return aValue < zValue ? -1 : 1
248248
},
249249
)
250+
251+
designSystem.variants.suggest(name, () =>
252+
Object.keys(options?.values ?? {}).filter((v) => v !== 'DEFAULT'),
253+
)
250254
},
251255

252256
addUtilities(utilities) {

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,3 +675,40 @@ test('Custom @utility and existing utility with names matching theme keys dont g
675675
expect(matches).toHaveLength(1)
676676
expect(classMap.get('text-header')?.modifiers).toEqual(['sm'])
677677
})
678+
679+
test('matchVariant', async () => {
680+
let input = css`
681+
@import 'tailwindcss/utilities';
682+
@plugin "./plugin.js";
683+
`
684+
685+
let design = await __unstable__loadDesignSystem(input, {
686+
loadStylesheet: async (_, base) => ({
687+
path: '',
688+
base,
689+
content: '@tailwind utilities;',
690+
}),
691+
loadModule: async () => ({
692+
path: '',
693+
base: '',
694+
module: plugin(({ matchVariant }) => {
695+
matchVariant('foo', (val) => `&:is(${val})`, {
696+
values: {
697+
DEFAULT: '1',
698+
a: 'a',
699+
b: 'b',
700+
},
701+
})
702+
}),
703+
}),
704+
})
705+
706+
let variants = design.getVariants()
707+
let v1 = variants.find((v) => v.name === 'foo')!
708+
expect(v1).not.toBeUndefined()
709+
710+
expect(v1.hasDash).toEqual(true)
711+
expect(v1.isArbitrary).toEqual(true)
712+
expect(v1.name).toEqual('foo')
713+
expect(v1.values).toEqual(['a', 'b'])
714+
})

0 commit comments

Comments
 (0)