-
-
Notifications
You must be signed in to change notification settings - Fork 63
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-position
classes are being removed wrongly
#297
Comments
Hi @iduuck! 👋 That's a bug indeed, thanks for reporting! I'll fix that. I'll include this in a v2 release I'm working on, so I won't be able to ship the fix immediately. As a temporary workaround you can use the tag
Tailwind CSS accepts that value and tailwind-merge will detect it as a background-image class. |
Note to myself:
|
@iduuck I just realized that arbitrary values in background-position and background-size classes are currently only supported by using tags I'll either fix this as well or make this clear in the documentation. |
@dcastil Having similar issue here, when applying classNames like |
Hey @locbqvmo! 👋 Could you open a separate issue for that and provide a reproduction example? I just played around on https://codesandbox.io/s/tailwind-merge-playground-cssr35?file=/src/index.ts with const mergeData: MergeData[] = [
{
args: ['text-red-500 text-lg'],
},
] and it outputs |
background-image
and background-position
)background-image
and background-position
classes are being removed wrongly
Hi @dcastil. Try with a custom tailwind config. I define new fontSize: "40px". //tailwind.config.js
module.exports = {
...
theme: {
extend: {
fontSize: {
"40px": ["40px", "56px"],
},
},
},
...
}; My component pass props className={twMerge("mb-10 text-center text-40px font-semibold text-bbc-brand-800 ")} and I got result: The text-40px is in conflict with text-bbc-brand-800 so text-40px class are being removed wrongly. But, if I try with name is "text-40xl": //tailwind.config.js
module.exports = {
...
theme: {
extend: {
fontSize: {
"40xl": ["40px", "56px"],
},
},
},
...
}; className={twMerge("mb-10 text-center text-40xl font-semibold text-bbc-brand-800 ")} The text-40xl isn't in conflict with text-bbc-brand-800. The same issue if I try text-40size, text-40abc,... Only text-40xl same suffix "xl" with text-xl, text-2xl,.. of tailwind default return true. |
Hey @ankhoa18599! 👋 tailwind-merge doesn't have access to the tailwind.config.js file and you need to configure it separately. The default out-of-the-box config of tailwind-merge assumes all unknown classes which could be a color are a color, this is why it de-duplicated text-40px when you use text-bbc-brand-800 afterwards. Here is an example on how to configure tailwind-merge: https://github.com/dcastil/tailwind-merge/blob/v1.14.0/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/v1.14.0/docs/configuration.md#usage-with-custom-tailwind-config. |
Hi. I have the same issue as @ankhoa18599. @dcastil could you expand on how one can configure Even though I added all my custom color names inside |
Hey @Senneer! 👋 When the group isn't in the theme, then you need to check the default config and find the class group ID. For So your config should look like this: const twMerge = extendTailwindMerge({
classGroups: {
'font-size': ['text-custom-1', …]
}
}) |
This was addressed in release v2.0.0. |
I had to add an extra export const twm = extendTailwindMerge({
extend: {
classGroups: {
'font-size': [
'text-h1',
...
],
},
},
}); |
@noorvir Yes, that is due to the change from v1 to v2 → https://github.com/dcastil/tailwind-merge/blob/v2.2.0/docs/changelog/v1-to-v2-migration.md#extendtailwindmerge-object-shape-changed |
I was wondering why |
Hey @mrleblanc101! 👋 Just tested it and I get the result |
@dcastil Might be a tailwind issue then. |
@dcastil It looks like So, it's partially improper use from my part, but seems also like a bug in I can create a seperate issue if needed. EDIT: Updated with the proper link to the repro |
@mrleblanc101 |
@dcastil But why and how does Tailwindcss infer it correctly ? Should tailwind-merge have the same inference ? |
Yes, I try to be close to Tailwind's implementation. It's not always possible to use the exact same approach because tailwind-merge has much bigger constraints when it comes to how fast it needs to process data and how much code it can ship since it's typically within the frontend bundle. But the biggest obstacle is usually how much time I have to research and build. In case you really want to have this feature, feel free to research how Tailwind detects which of the two it is and post a new issue with the info. I could pick it up from there or you could continue and submit a PR. A good starting point is Tailwind's definition of the |
@dcastil Thanks for you explaination. |
Spent some time figuring this out, might help someone. Pay attention to the custom class you need to extend in the config, you need to type the whole class, while on const tailwindConfig = {
theme: {
extend: {
fontSize: {
'xs': ...,
'sm': ...
}
... const twMergeConfig = extendTailwindMerge({
extend: {
classGroups: {
'font-size': [
'text-xs', // <-- include 'text'
'text-sm',
... |
Describe the bug
When supplying multiple "similar" classes, some are removed wrongly.
To Reproduce
https://codesandbox.io/s/magical-sound-6sfws8?file=/src/index.ts
Expected behavior
Background size, and image should be included.
Environment
Additional context
N/A
The text was updated successfully, but these errors were encountered: