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

wrong merge #482

Closed
kratess opened this issue Oct 13, 2024 · 2 comments
Closed

wrong merge #482

kratess opened this issue Oct 13, 2024 · 2 comments
Labels
context-v2 Related to tailwind-merge v2

Comments

@kratess
Copy link

kratess commented Oct 13, 2024

Describe the bug

To Reproduce

const textAreaVariants = cva(
  "block bg-white text-gray1 leading-1.25 border-gray4 placeholder-opacity-50 border rounded-5 outline-none",
  {
    variants: {
      componentSize: {
        lg: "text-16",
        md: "text-14",
        sm: "text-12"
      }
    },
    defaultVariants: {
      componentSize: "md"
    }
  }
);
const _twMerge = extendTailwindMerge({
  extend: {
    classGroups: {
      "text-color": [
        {
          text: [
            "white",
            "black",
            "gray1",
            "gray2",
            "gray3",
            "gray4",
            "gray5",
            "gray6",
            "gray7",
            "gray8",
            "gray9",
            "gold",
            "red"
          ]
        }
      ],
      "font-size": [
        {
          text: [
            "0",
            "2",
            "4",
            "6",
            "8",
            "10",
            "12",
            "14",
            "16",
            "18",
            "20",
            "22",
            "24",
            "26",
            "28",
            "30",
            "32",
            "34",
            "36",
            "38",
            "40",
            "42",
            "44",
            "46",
            "48",
            "50",
            "52",
            "54",
            "56",
            "58",
            "60",
            "62",
            "64",
            "96",
            "128"
          ]
        }
      ],
      "leading": [
        {
          text: ["1.0", "1.1", "1.2", "1.25", "1.3", "1.4", "1.5"]
        }
      ]
    }
  }
});

results in this:

block bg-white text-gray1 border-gray4 placeholder-opacity-50 rounded-5 outline-none text-14 w-100 border-0

Expected behavior

block bg-white text-gray1 leading-1.25 border-gray4 placeholder-opacity-50 rounded-5 outline-none text-14 w-100 border-0

@github-actions github-actions bot added the context-v2 Related to tailwind-merge v2 label Oct 13, 2024
@dcastil
Copy link
Owner

dcastil commented Oct 15, 2024

Hey @kratess! 👋

The reason why the leading-1.25 class gets removed is because text-14 sets a line-height CSS property, overriding line-height classes if you place it afterwards. If you want to change this overriding behavior and don't use line-heights in your font-size classes, you can override the conflict between the font-size and line-height classes:

import { extendTailwindMerge } from 'tailwind-merge'

const twMerge = extendTailwindMerge({
    override: {
        conflictingClassGroups: {
            // In the default config the value is ['leading']
            // See https://github.com/dcastil/tailwind-merge/blob/v2.5.4/src/lib/default-config.ts#L1786
            'font-size': []
        }
    },
    // … rest of your config
})

Related: #446, #257, #218, #187, #59

@kratess
Copy link
Author

kratess commented Oct 15, 2024

Hi @dcastil

Indeed only native font-size of tailwind has the line-height set. Custom-ones i made does not have that feature.

But yeah, conflictingClassGroups solved my issue. Thanks

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

2 participants