Skip to content

Commit ceeb18a

Browse files
committed
fix prefix:; adding a 0 as prefix for variables. closes: #3807
1 parent db00a04 commit ceeb18a

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

packages/daisyui/functions/addPrefix.js

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const processArrayValue = (value, prefix, excludedPrefixes) => {
132132
}
133133

134134
const processStringValue = (value, prefix, excludedPrefixes) => {
135+
if (prefix === 0) return value
135136
return value.replace(/var\(--([^)]+)\)/g, (match, variableName) => {
136137
if (shouldExcludeVariable(variableName, excludedPrefixes)) {
137138
return match

packages/daisyui/functions/addPrefix.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,25 @@ test("addPrefix with nested combinators and :not(:has()) selector", () => {
399399
}
400400
expect(addPrefix(input, prefix)).toEqual(expected)
401401
})
402+
403+
// with 0 prefix
404+
test("addPrefix with 0 prefix should not affect CSS variables", () => {
405+
const input = {
406+
"--custom-var": "10px",
407+
"--another-var": "var(--custom-var)",
408+
".btn": {
409+
margin: "var(--custom-var)",
410+
"--local-var": "20px",
411+
},
412+
}
413+
const prefix = 0
414+
const expected = {
415+
"--custom-var": "10px",
416+
"--another-var": "var(--custom-var)",
417+
".btn": {
418+
margin: "var(--custom-var)",
419+
"--local-var": "20px",
420+
},
421+
}
422+
expect(addPrefix(input, prefix)).toEqual(expected)
423+
})

0 commit comments

Comments
 (0)