Skip to content

Commit 6b82ca8

Browse files
authored
Fix modifiers for arbitrary values (#6199)
* fix modifiers for arbitrary properties The main issue was that we are splitting on the separator and popping the last section of to know the _base_ utility. However, in this case it would be something like `markers]` which is incorrect. Instead we only split by the separator and ignore the separtor if it exists between square brackets. * add tests for modifiers + arbitrary values that contain the separator
1 parent 22b7cb5 commit 6b82ca8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/util/formatVariantSelector.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ export function formatVariantSelector(current, ...others) {
3030
}
3131

3232
export function finalizeSelector(format, { selector, candidate, context }) {
33-
let base = candidate.split(context?.tailwindConfig?.separator ?? ':').pop()
33+
let separator = context?.tailwindConfig?.separator ?? ':'
34+
35+
// Split by the separator, but ignore the separator inside square brackets:
36+
//
37+
// E.g.: dark:lg:hover:[paint-order:markers]
38+
// ┬ ┬ ┬ ┬
39+
// │ │ │ ╰── We will not split here
40+
// ╰──┴─────┴─────────────── We will split here
41+
//
42+
let splitter = new RegExp(`\\${separator}(?![^[]*\\])`)
43+
let base = candidate.split(splitter).pop()
3444

3545
if (context?.tailwindConfig?.prefix) {
3646
format = prefixSelector(context.tailwindConfig.prefix, format)

tests/arbitrary-values.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ test('arbitrary values', () => {
1616
})
1717
})
1818

19+
it('should support modifiers for arbitrary values that contain the separator', () => {
20+
let config = {
21+
content: [
22+
{
23+
raw: html` <div class="hover:bg-[url('https://github.com/tailwindlabs.png')]"></div> `,
24+
},
25+
],
26+
}
27+
28+
return run('@tailwind utilities', config).then((result) => {
29+
return expect(result.css).toMatchFormattedCss(css`
30+
.hover\:bg-\[url\(\'https\:\/\/github\.com\/tailwindlabs\.png\'\)\]:hover {
31+
background-image: url('https://github.com/tailwindlabs.png');
32+
}
33+
`)
34+
})
35+
})
36+
1937
it('should support arbitrary values for various background utilities', () => {
2038
let config = {
2139
content: [

0 commit comments

Comments
 (0)