Custom tailwind utilities and colors are not applying in a monorepo setting #18797
-
What version of Tailwind CSS are you using? v4.0.2 What build tool (or framework if it abstracts the build tool) are you using?
What version of Node.js are you using? For example: v22.15.0 What browser are you using? Chrome, always latest version What operating system are you using? Windows Reproduction URL https://github.com/dragos-cojocaru/tailwind-bug https://tailwind-bug-web.vercel.app/ Describe your issue When adding I actually have a real project where I managed to be able to use either an With the reproduction code I fastly set up, these utilities are not working at all, unless applied with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
In default:
"… text-indigo … text-primary-foreground …", Notice how you have two classes that apply Since So, if you want the text color value in the --- a/packages/ui/src/components/button.tsx
+++ b/packages/ui/src/components/button.tsx
@@ -10,7 +10,7 @@ const buttonVariants = cva(
variants: {
variant: {
default:
- "bg-primary text-indigo text-h10 text-primary-foreground shadow-xs hover:bg-primary/90",
+ "bg-primary text-indigo text-h10 shadow-xs hover:bg-primary/90",
destructive:
"bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline: Though you may notice that this still doesn't make the text the indigo color and the --- a/packages/ui/src/lib/utils.ts
+++ b/packages/ui/src/lib/utils.ts
@@ -1,5 +1,21 @@
import { clsx, type ClassValue } from "clsx"
-import { twMerge } from "tailwind-merge"
+import { extendTailwindMerge } from "tailwind-merge"
+
+const twMerge = extendTailwindMerge({
+ extend: {
+ theme: {
+ color: [
+ 'indigo',
+ 'primary-foreground',
+ // Add any more text-<color> tokens here.
+ ],
+ text: [
+ 'h10',
+ // Add any more text-<font-size> tokens here.
+ ],
+ },
+ },
+})
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)) |
Beta Was this translation helpful? Give feedback.
In
packages/ui/src/components/button.tsx
line 13, you have:Notice how you have two classes that apply
color
. On line 53, you then pass the result of this cva function throughcn()
which usestailwind-merge
.Since
text-primary-foreground
appears aftertext-indigo
,text-indigo
is removed from the class names rendered on the element. Generally, you only want one class name per element for the same variant (in this case, no variants) regardless if you are usingtailwind-merge
or not.So, if you want the text color value in the
default
CVA variant to betext-indigo
, removetext-primary-foreground
:--- a/packages/ui/src/components/button.tsx