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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom text sizes and colors get merged #519

Open
nikita-bashaiev opened this issue Jan 24, 2025 · 2 comments
Open

Custom text sizes and colors get merged #519

nikita-bashaiev opened this issue Jan 24, 2025 · 2 comments
Labels
context-v2 Related to tailwind-merge v2

Comments

@nikita-bashaiev
Copy link

nikita-bashaiev commented Jan 24, 2025

Describe the bug

twMerge seems to treat custom text sizes as colors and merges them with colors.

To Reproduce

https://codesandbox.io/p/sandbox/agitated-almeida-zxfjff

Expected behavior

Recongnize all text sizes as distinct from colors.

Edit: I read the docs and understand that twMerge treats only clothing sizes (optionally preceded by a number) as text-size. My suggestion is to include the ability to add suffixes/prefixes to the above formula (e.g. text-2xl-suffix), or (more radical and probably problematic) treat all text- classes that contain clothing sizes as text-size.

Environment

  • tailwind-merge version: 2.6.0

Additional context

Use-case: secondary type scale aside from tw's default (e.g. a fluid one using clamp as in my case)

@github-actions github-actions bot added the context-v2 Related to tailwind-merge v2 label Jan 24, 2025
@jurend
Copy link

jurend commented Jan 25, 2025

We experience the same problem because we have defined custom text sizes (like text-h1, text-h2,...). Our issue was fixed by extending twMerge classGroups "font-size" like that:

import { extendTailwindMerge } from "tailwind-merge";
const twMerge = extendTailwindMerge({
  extend: {
    classGroups: {
      'font-size': [{ text: ["h1", "h2", "h3", "h4", "h5", "h6"] }]
    }
  },
})

This adds h1, h2,... suffixes to the existing list of "shirt sizes".

See the relevant source code where original twmerge config is implemented, that can be extended or overridden: https://github.com/dcastil/tailwind-merge/blob/v2.6.0/src/lib/default-config.ts#L665
As you can see, you can also attach a custom validation function if you want to add additional suffixes with based on dynamic formula.

@dcastil
Copy link
Owner

dcastil commented Jan 26, 2025

Hey @nikita-bashaiev! 👋

The comment above #519 (comment) says it all, that's the intended solution for that. tailwind-merge doesn't have access to your Tailwind config and you have to configure it separately.

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

No branches or pull requests

3 participants