Skip to content

Commit cc228fb

Browse files
Add support for matching multiple utility definitions for one candidate (tailwindlabs#14231)
Currently if a plugin adds a utility called `duration` it will take precedence over the built-in utilities — or any utilities with the same name in previously included plugins. However, in v3, we emitted matches from _all_ plugins where possible. Take this plugin for example which adds utilities for `animation-duration` via the `duration-*` class: ```ts import plugin from 'tailwindcss/plugin' export default plugin( function ({ matchUtilities, theme }) { matchUtilities( { duration: (value) => ({ animationDuration: value }) }, { values: theme("animationDuration") }, ) }, { theme: { extend: { animationDuration: ({ theme }) => ({ ...theme("transitionDuration"), }), } }, } ) ``` Before this PR this plugin's `duration` utility would override the built-in `duration` utility so you'd get this for a class like `duration-3500`: ```css .duration-3000 { animation-duration: 3500ms; } ``` Now, after this PR, we'll emit rules for `transition-duration` (Tailwind's built-in `duration-*` utility) and `animation-duration` (from the above plugin) and you'll get this instead: ```css .duration-3000 { transition-duration: 3500ms; } .duration-3000 { animation-duration: 3500ms; } ``` These are output as separate rules to ensure that they can all be sorted appropriately against other utilities. --------- Co-authored-by: Philipp Spiess <hello@philippspiess.com>
1 parent bc88958 commit cc228fb

File tree

14 files changed

+985
-676
lines changed

14 files changed

+985
-676
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
- Add support for `tailwindcss/colors` and `tailwindcss/defaultTheme` exports for use with plugins ([#14221](https://github.com/tailwindlabs/tailwindcss/pull/14221))
1717
- Add support for the `@tailwindcss/typography` and `@tailwindcss/forms` plugins ([#14221](https://github.com/tailwindlabs/tailwindcss/pull/14221))
1818
- Add support for the `theme()` function in CSS and class names ([#14177](https://github.com/tailwindlabs/tailwindcss/pull/14177))
19+
- Add support for matching multiple utility definitions for one candidate ([#14231](https://github.com/tailwindlabs/tailwindcss/pull/14231))
1920

2021
### Fixed
2122

integrations/cli/plugins.test.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { candidate, css, html, json, test } from '../utils'
22

33
test(
4-
'builds the typography plugin utilities',
4+
'builds the `@tailwindcss/typography` plugin utilities',
55
{
66
fs: {
77
'package.json': json`
@@ -40,7 +40,7 @@ test(
4040
)
4141

4242
test(
43-
'builds the forms plugin utilities',
43+
'builds the `@tailwindcss/forms` plugin utilities',
4444
{
4545
fs: {
4646
'package.json': json`
@@ -76,3 +76,39 @@ test(
7676
])
7777
},
7878
)
79+
80+
test(
81+
'builds the `tailwindcss-animate` plugin utilities',
82+
{
83+
fs: {
84+
'package.json': json`
85+
{
86+
"dependencies": {
87+
"tailwindcss-animate": "^1.0.7",
88+
"tailwindcss": "workspace:^",
89+
"@tailwindcss/cli": "workspace:^"
90+
}
91+
}
92+
`,
93+
'index.html': html`
94+
<div class="animate-in fade-in zoom-in duration-350"></div>
95+
`,
96+
'src/index.css': css`
97+
@import 'tailwindcss';
98+
@plugin 'tailwindcss-animate';
99+
`,
100+
},
101+
},
102+
async ({ fs, exec }) => {
103+
await exec('pnpm tailwindcss --input src/index.css --output dist/out.css')
104+
105+
await fs.expectFileToContain('dist/out.css', [
106+
candidate`animate-in`,
107+
candidate`fade-in`,
108+
candidate`zoom-in`,
109+
candidate`duration-350`,
110+
'transition-duration: 350ms',
111+
'animation-duration: 350ms',
112+
])
113+
},
114+
)

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ exports[`getClassList 1`] = `
488488
"bg-gradient-to-tl",
489489
"bg-gradient-to-tr",
490490
"bg-inherit",
491-
"bg-inherit",
492491
"bg-left",
493492
"bg-left-bottom",
494493
"bg-left-top",
@@ -517,7 +516,6 @@ exports[`getClassList 1`] = `
517516
"bg-space",
518517
"bg-top",
519518
"bg-transparent",
520-
"bg-transparent",
521519
"block",
522520
"blur-none",
523521
"border",

packages/tailwindcss/src/candidate.bench.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ const designSystem = buildDesignSystem(new Theme())
1515

1616
bench('parseCandidate', () => {
1717
for (let candidate of candidates) {
18-
parseCandidate(candidate, designSystem)
18+
Array.from(parseCandidate(candidate, designSystem))
1919
}
2020
})

0 commit comments

Comments
 (0)