Commit d15d92c
Allow trailing dash in functional utility names (#19696)
## Problem
Tailwind 4.2.0 introduced stricter `@utility` name validation (#19524)
that rejects functional utility names where the root ends with a dash
after stripping the `-*` suffix. This breaks a valid and useful naming
pattern where a double dash separates the CSS property from a value
scale:
```css
@Utility border--* {
border-color: --value(--color-border-*, [color]);
}
```
This produces: `border--0`, `border--1`, `border--2`, etc.
The error message is:
> `@utility border--*` defines an invalid utility name. Utilities should
be alphanumeric and start with a lowercase letter.
## Why this pattern matters
The double-dash convention creates a clear visual grammar in class
names. The first segment names the CSS property, and the double dash
separates it from the semantic scale value. In a dense className string
like `border border--0 background--0 content--4`, the scale values (0,
0, 4) are immediately scannable, distinct from the single-dash property
names around them.
This pattern is actively used in production design systems for semantic
color scales (background, content, border, shadow) with values from
0-10.
## Why the restriction is unnecessary
The validation comment states the concern is that `border--*` could
match the bare class `border-` when using default values. However, this
edge case is already handled:
1. **`findRoots` in `candidate.ts`** (line 887) already rejects empty
values: `if (root[1] === '') break`
2. **The Oxide scanner** already extracts double-dash candidates
correctly, as confirmed by existing tests: `("items--center",
vec!["items--center"])`
The candidate parser and scanner both handle this case. The validation
was an overcorrection.
## Changes
- Removed the trailing-dash check from `isValidFunctionalUtilityName` in
`utilities.ts`
- Updated the existing unit test from `['foo--*', false]` to `['foo--*',
true]`
- Added an integration test proving `@utility border--*` compiles
correctly with theme values
## Test results
All 4121 tests pass across the tailwindcss package, including the new
integration test.
---------
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>1 parent 7a54d15 commit d15d92c
File tree
3 files changed
+47
-12
lines changed- packages/tailwindcss/src
3 files changed
+47
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28428 | 28428 | | |
28429 | 28429 | | |
28430 | 28430 | | |
28431 | | - | |
| 28431 | + | |
28432 | 28432 | | |
28433 | 28433 | | |
28434 | 28434 | | |
| |||
28900 | 28900 | | |
28901 | 28901 | | |
28902 | 28902 | | |
| 28903 | + | |
| 28904 | + | |
| 28905 | + | |
| 28906 | + | |
| 28907 | + | |
| 28908 | + | |
| 28909 | + | |
| 28910 | + | |
| 28911 | + | |
| 28912 | + | |
| 28913 | + | |
| 28914 | + | |
| 28915 | + | |
| 28916 | + | |
| 28917 | + | |
| 28918 | + | |
| 28919 | + | |
| 28920 | + | |
| 28921 | + | |
| 28922 | + | |
| 28923 | + | |
| 28924 | + | |
| 28925 | + | |
| 28926 | + | |
| 28927 | + | |
| 28928 | + | |
| 28929 | + | |
| 28930 | + | |
| 28931 | + | |
| 28932 | + | |
| 28933 | + | |
| 28934 | + | |
28903 | 28935 | | |
28904 | 28936 | | |
28905 | 28937 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6659 | 6659 | | |
6660 | 6660 | | |
6661 | 6661 | | |
6662 | | - | |
6663 | | - | |
6664 | | - | |
6665 | | - | |
6666 | | - | |
6667 | | - | |
6668 | | - | |
6669 | | - | |
6670 | | - | |
6671 | | - | |
6672 | | - | |
6673 | 6662 | | |
6674 | 6663 | | |
6675 | 6664 | | |
6676 | 6665 | | |
6677 | 6666 | | |
| 6667 | + | |
| 6668 | + | |
| 6669 | + | |
| 6670 | + | |
| 6671 | + | |
| 6672 | + | |
| 6673 | + | |
| 6674 | + | |
| 6675 | + | |
| 6676 | + | |
6678 | 6677 | | |
6679 | 6678 | | |
6680 | 6679 | | |
| |||
0 commit comments