Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

twMerge is removing custom classes wrongly #276

Closed
sumanthyedoti opened this issue Aug 7, 2023 · 3 comments
Closed

twMerge is removing custom classes wrongly #276

sumanthyedoti opened this issue Aug 7, 2023 · 3 comments
Labels
context-v1 Related to tailwind-merge v1

Comments

@sumanthyedoti
Copy link

sumanthyedoti commented Aug 7, 2023

  • I have text-40 defined is tailwind config as 2.5rem
  • Had the class by default to a button
  • twMerge is removing the classes. I had to pass the classes explicitly, Button className="text-40",
    • 馃憠 then other custom class text-white-light got removed

Are the custom classes conflicting because they start with text-?

Note: I am using classnames library
config:

theme: {
  expand: {
      fontSize: {
        //...
        '40': '2.5rem',
      },
  }
}
@sumanthyedoti sumanthyedoti changed the title twMerge is removing existing custom class in a component twMerge is removing custom classes wrongly Aug 7, 2023
@dcastil
Copy link
Owner

dcastil commented Aug 7, 2023

Hey @sumanthyedoti! 馃憢

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-white-light when you use text-40 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.

Related: #275, #274, #250, #207

@sumanthyedoti
Copy link
Author

Thanks @dcastil

@dcastil
Copy link
Owner

dcastil commented Aug 19, 2023

Closing this issue. Please let me know if your issue isn't resolved and I should reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context-v1 Related to tailwind-merge v1
Projects
None yet
Development

No branches or pull requests

2 participants