-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Describe the problem:
If I define a color using a function like this:
{
...
colors: {
'primary': ({ opacityVariable }) => `rgba(255,0,0,var(${ opacityVariable }))`
}
...
}
The CSS variable passed in by opacityVariable is not set by default, breaking the color.
Looking at
tailwindcss/src/util/withAlphaVariable.js
Line 21 in 05406f9
| export default function withAlphaVariable({ color, property, variable }) { |
[variable]: '1' in the returned object, the default variable is set and everything works as anticipated.
After some discussion on discord, Robin suggested adding a default to the css variable to resolve this such as: var(${opacitiyVariable}, 1). However crswll pointed out this results in specificity issues (see repro below).
My use case is that I need to pass in my own CSS variable as the color so I cannot use the toRgba function. This is for a vite plugin so I would like to retain identical behavior to default.
Link to a minimal reproduction:
I expect the text to be red (#FF0000) but it is black: https://play.tailwindcss.com/8uIqAsBJHR?layout=vertical&file=html
Inspecting the CSS shows the --text-opacity variable is not defined.
Specificity problem from @crswll on Discord: https://play.tailwindcss.com/b2b9JVJeNf?layout=vertical&file=html