-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
background image and background color is merged making it impossible to apply both #488
Comments
Hey @crtl! 👋 Thanks for your patience! tailwind-merge doesn't have access to the tailwind.config.js file and you need to configure it separately so it knows about the bg-my-gradient class. Here is an example on how to configure tailwind-merge: https://github.com/dcastil/tailwind-merge/blob/v2.5.4/docs/recipes.md#adding-custom-scale-from-tailwind-config-to-tailwind-merge-config. And here is the documentation on how the tailwind-merge configuration works: https://github.com/dcastil/tailwind-merge/blob/v2.5.4/docs/configuration.md#usage-with-custom-tailwind-config. (For myself) Related: #489, #469, #447, #368, #322, #321, #315, #302, #276, #275, #274, #250, #207 |
To make a note: For the shadcn/ui scenario, you can try this: import { clsx, type ClassValue } from "clsx";
import { extendTailwindMerge } from "tailwind-merge";
const customTwMerge = extendTailwindMerge({
extend: {
classGroups: {
// Add custom merging rules here
"font-size": [
"text-h1",
"text-h2",
"text-h3",
// ... and so on
],
"bg-color": [
"bg-background",
"bg-foreground",
"bg-card",
],
"text-color": [
"text-background",
"text-foreground",
"text-card-foreground",
],
"border-color": [
"border-background",
"border-foreground",
"border-card",
],
z: ["z-app-bar", "z-popup", "z-menu", "z-tooltip", "z-modal"],
},
},
});
export function cn(...inputs: ClassValue[]) {
return customTwMerge(clsx(inputs));
} It is a solution for me, and I am not sure if this will affect shadcn/ui because Copilot also send some shadcn/ui variable into it. |
tailwind-merge by default treats classes that could be a color class as a color class, e.g. The downside of course is that all unknown classes starting with |
I understand and that is just a note. I think maybe it will be a better practice to build the custom tailwind variables first, and then use it to generate the tailwind config and extended tailwind-merge function. Sadly that's not the shadcn/ui's style ❤ |
This happened to me as well, but with the |
@GuiSelair you can, you just need to configure tailwind-merge accordingly: import { extendTailwindMerge } from 'tailwind-merge'
export const twMerge = extendTailwindMerge({
extend: {
classGroups: {
'font-size': ['text-button-md']
}
}
}) You don't need to configure |
It's works! Thanks you! 🥇 |
Describe the bug
When using custom gradients you may want to apply both a gradient as background-image and a background-color.
Currently tailwind-merge will remove "duplicate" properties based on their prefix even though they apply different styles.
To Reproduce
Having following custom gradient:
Will generate a classname
bg-my-gradient
to apply the gradient.Environment
Additional context
As a workaround you can use media-query modifiers:
The text was updated successfully, but these errors were encountered: