Skip to content

Commit

Permalink
Fix decoration utility ambiguity (#6217)
Browse files Browse the repository at this point in the history
* remove `any` data type for decoration color plugin

The main reason for the `any` type is so that we don't have to parse the
value and can assume that this plugin handles "any" value you give it.

This is useful because `decoration-[var(--something)]` would be
correctly translated to the correct decoration property. However, we
introduce another plugin with the same `decoration` prefix.

This means that now both `textDecorationColor` and
`textDecorationThickness` have the same base utility name: `decoration`.

- `textDecorationColor` had ['color', 'any']
- `textDecorationThickness` had ['length', 'percentage']

This means that `3px` fit both in the `length` data type of the
`textDecorationThickness` plugin and in the `any` data type of the
`textDecorationColor` plugin.

Removing the `any` fixes this.

TL;DR: Only have `any` when there are no conflicting utility names.

* remove utility that doesn't generate css

Having `decoration-[var(--abc)]` is ambiguous because there are multiple
plugins that have a `decoration` utility name. In order for this to work
you have to prefix it with the type: `decoration-[color:var(--abc)]`
which is already tested in this file.
  • Loading branch information
RobinMalfait committed Nov 29, 2021
1 parent 6b82ca8 commit 12ea363
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/corePlugins.js
Expand Up @@ -1670,7 +1670,7 @@ export let corePlugins = {
return { 'text-decoration-color': toColorValue(value) }
},
},
{ values: flattenColorPalette(theme('textDecorationColor')), type: ['color', 'any'] }
{ values: flattenColorPalette(theme('textDecorationColor')), type: ['color'] }
)
},

Expand Down
3 changes: 0 additions & 3 deletions tests/arbitrary-values.test.css
Expand Up @@ -822,9 +822,6 @@
.decoration-\[color\:var\(--color\)\] {
text-decoration-color: var(--color);
}
.decoration-\[var\(--color\)\] {
text-decoration-color: var(--color);
}
.decoration-\[length\:10px\] {
text-decoration-thickness: 10px;
}
Expand Down
1 change: 0 additions & 1 deletion tests/arbitrary-values.test.html
Expand Up @@ -303,7 +303,6 @@
<div class="decoration-[rgb(123,_123,_123)]"></div>
<div class="decoration-[rgb(123_123_123)]"></div>
<div class="decoration-[color:var(--color)]"></div>
<div class="decoration-[var(--color)]"></div>

<div class="decoration-[length:10px]"></div>

Expand Down
22 changes: 22 additions & 0 deletions tests/arbitrary-values.test.js
Expand Up @@ -16,6 +16,28 @@ test('arbitrary values', () => {
})
})

it('should be possible to differentiate between decoration utilities', () => {
let config = {
content: [
{
raw: html` <div class="decoration-[3px] decoration-[#ccc]"></div> `,
},
],
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.decoration-\[\#ccc\] {
text-decoration-color: #ccc;
}
.decoration-\[3px\] {
text-decoration-thickness: 3px;
}
`)
})
})

it('should support modifiers for arbitrary values that contain the separator', () => {
let config = {
content: [
Expand Down

0 comments on commit 12ea363

Please sign in to comment.