I have quite an odd problem:
I want to dynamically fill the content of an after:
pseudo element within a computed value.
The fun part is, that it works if the key is a string literal before returning the object, but not if the string is created within the property and then added to the object before returning it.
staticClassObject() {
return {
'after:content-["04:00"]': true,
"after:h-8": true,
"after:w-min": true,
"after:p-1": true,
"after:rounded-full": true,
"after:border": true,
"after:border-ns-black": true,
"after:bg-white": true,
"after:-translate-x-1/2": true,
"after:block": true,
};
// this one works as expected, the after element has the text '04:00' showing.
},
dynamicClassObject() {
const content = '04:00';
const dynamicKey = `after:content-["${content}"]`;
const object = {
"after:h-8": true,
"after:w-min": true,
"after:p-1": true,
"after:rounded-full": true,
"after:border": true,
"after:border-ns-black": true,
"after:bg-white": true,
"after:-translate-x-1/2": true,
"after:block": true,
}
object[dynamicKey] = true;
return object;
// This one doesn't work, even though it's the same object as the one above.
},
furthermore this problem only persists when using a package version of tailwind, but not when using a cdn version of it. Does anyone know why this happens, and do you have a pointer to a different approach?