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

Tailwind size rules not being merged #510

Closed
mhuggins opened this issue Dec 27, 2024 · 3 comments
Closed

Tailwind size rules not being merged #510

mhuggins opened this issue Dec 27, 2024 · 3 comments
Labels
context-v1 Related to tailwind-merge v1 context-v2 Related to tailwind-merge v2

Comments

@mhuggins
Copy link

mhuggins commented Dec 27, 2024

Describe the bug

When trying to merge size rules, both rules remain in the class list, which may inadvertently result in the incorrect class being used.

To Reproduce

Pass two size-* classes into twMerge, e.g.:

import React from "react";
import { twMerge } from "tailwind-merge";

const MyComponent = () => (
  <div className={cn("bg-red size-4", "size-10")} />
);

Expected behavior

The resulting class on the div should be "bg-red size-10", but it ends up being "bg-red size-4 size-10" instead.

Environment

  • tailwind-merge version: 1.14.0
  • tailwindcss version: 3.4.14

Additional context

I seem to be able to work around this by extending tailwind-merge with the following. However, I haven't played with it enough to know if there are any negative side effects with how size interacts with w/h.

import { extendTailwindMerge, fromTheme } from "tailwind-merge";

const arbitraryValueRegex = /^\[(?:([a-z-]+):)?(.+)\]$/i;
const isArbitraryValue = (value: string) => arbitraryValueRegex.test(value);

const spacing = fromTheme("spacing");

export const twMerge = extendTailwindMerge({
  classGroups: {
    size: [
      {
        size: ["auto", "min", "max", "fit", isArbitraryValue, spacing],
      },
    ],
  },
});
@github-actions github-actions bot added the context-v2 Related to tailwind-merge v2 label Dec 27, 2024
@dcastil dcastil added the context-v1 Related to tailwind-merge v1 label Dec 29, 2024
@dcastil
Copy link
Owner

dcastil commented Dec 29, 2024

Hey @mhuggins! 👋

That's because your tailwind-merge version only supports Tailwind CSS v3.0 up to v3.3, but the size-* classes were added in Tailwind CSS v3.4. You'll need to upgrade to tailwind-merge v2.2.0 or higher to get support for size classes.

@mhuggins
Copy link
Author

Ahh, thanks for letting me know! I'll upgrade & report back. 😄

@mhuggins
Copy link
Author

Upgrading fixed it, thank you! 😄

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 context-v2 Related to tailwind-merge v2
Projects
None yet
Development

No branches or pull requests

2 participants