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

TW4 + TW merge + CVA some base classes are not applied #540

Open
sebalaini opened this issue Feb 23, 2025 · 1 comment
Open

TW4 + TW merge + CVA some base classes are not applied #540

sebalaini opened this issue Feb 23, 2025 · 1 comment
Labels
context-v3 Related to tailwind-merge v3

Comments

@sebalaini
Copy link

sebalaini commented Feb 23, 2025

Describe the bug

I opened the issue in cva 335 but after some digging, I think is related to TW merge 🤔 looks like some classes are removed from the final class list.

The classes I'm having a problem with are font-xxx & leading-xxx

To Reproduce

This is my config:

import { extendTailwindMerge } from 'tailwind-merge'

export const customTwMerge = extendTailwindMerge({
  extend: {
    theme: {
      spacing: ['0', 'xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl', 'auto'],
      // leading: ['sm', 'md', 'lg'],
      radius: ['none', 'sm', 'md', 'lg', 'xl', 'round', 'pill'],
    },
  },
})
import clsx, { type ClassValue } from 'clsx'
import { customTwMerge } from './tailwind-merge'

// export function cn(...inputs: ClassValue[]) {
//  return customTwMerge(clsx(inputs))
// }
export function cn(...inputs) {
  return customTwMerge(inputs)
}

This is the new way I have to do it to make it work, which doesn't seem correct.

The commented out way or even the one posted in the above issue doesn't work anymore with TW4 and the new version of TW Merge

export const Typography = ({
  as,
  size,
  bold,
  light,
  className,
  children,
  ...props
}: Props) => {
  const TypographyTag = React.createElement<any>(
    as,
    {
      className: `font-secondary font-normal leading-md tracking-md mb-md ${cn(typographyVariants({ size, bold, light }), className)}`,
      // className: `${cn(`font-secondary font-normal leading-md tracking-md mb-md ${typographyVariants({ size, bold, light })}`, className)}`,
      ...props,
    },
    children
  )

  return TypographyTag
}

Especially because I can override one of those classes that doesn't work, like this:

            <Typography
              as='span'
              className={cn(
                `font-tertiary mx-auto ${index === 2 ? 'text-red-500' : 'text-neutral-white'}`
              )}
            >
              {price ? price : '/'}
            </Typography>

Expected behavior

both font-xxx & leading-xxx should be applied to the final class list.

@github-actions github-actions bot added the context-v3 Related to tailwind-merge v3 label Feb 23, 2025
@paleite
Copy link

paleite commented Feb 25, 2025

I'm having the same issue with "leading-" not being set when it's inside the first argument.

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

No branches or pull requests

2 participants