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.
This commit is contained in:
Jordan Pittman 2025-08-26 10:25:35 -04:00 committed by GitHub
parent ee987e3f6a
commit 8165e04564
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 0 deletions

View File

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don't transition `visibility` when using `transition` ([#18795](https://github.com/tailwindlabs/tailwindcss/pull/18795))
- Discard matched variants with unknown named values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
- Discard matched variants with non-string values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
- Show suggestions for known `matchVariant` values ([#18798](https://github.com/tailwindlabs/tailwindcss/pull/18798))
## [4.1.12] - 2025-08-13

View File

@ -247,6 +247,10 @@ export function buildPluginApi({
return aValue < zValue ? -1 : 1
},
)
designSystem.variants.suggest(name, () =>
Object.keys(options?.values ?? {}).filter((v) => v !== 'DEFAULT'),
)
},
addUtilities(utilities) {

View File

@ -675,3 +675,40 @@ test('Custom @utility and existing utility with names matching theme keys dont g
expect(matches).toHaveLength(1)
expect(classMap.get('text-header')?.modifiers).toEqual(['sm'])
})
test('matchVariant', async () => {
let input = css`
@import 'tailwindcss/utilities';
@plugin "./plugin.js";
`
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: plugin(({ matchVariant }) => {
matchVariant('foo', (val) => `&:is(${val})`, {
values: {
DEFAULT: '1',
a: 'a',
b: 'b',
},
})
}),
}),
})
let variants = design.getVariants()
let v1 = variants.find((v) => v.name === 'foo')!
expect(v1).not.toBeUndefined()
expect(v1.hasDash).toEqual(true)
expect(v1.isArbitrary).toEqual(true)
expect(v1.name).toEqual('foo')
expect(v1.values).toEqual(['a', 'b'])
})