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

font-[inherit] should override font-bold (or any other weight) #499

Closed
hmaesta opened this issue Dec 11, 2024 · 3 comments
Closed

font-[inherit] should override font-bold (or any other weight) #499

hmaesta opened this issue Dec 11, 2024 · 3 comments
Labels
context-v2 Related to tailwind-merge v2

Comments

@hmaesta
Copy link

hmaesta commented Dec 11, 2024

tailwind-merge 2.5.5 doesn't correctly override font-weight for inherit as an arbitrary value.

Expected

  • twMerge('font-bold', 'font-[inherit]') should result in font-[inherit]

  • font-[inherit] should override all Tailwind CSS font weights.

To Reproduce

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

dcastil commented Dec 13, 2024

Hey @hmaesta! 👋

tailwind-merge recognizes font-[inherit] as a font-family class because that's also what Tailwind CSS generates for that class: font-family: inherit. In Tailwind CSS the only way to set the CSS you want is to use arbitrary properties: [font-weight:inherit]. But that won't help with tailwind-merge since it won't override arbitrary properties with default classes.

This is really quite tricky. 🤔 I'm afraid there is no solution for this within tailwind-merge.

Looking at your real-life example, a workaround could be to add a prop like noFontWeight to the Button component and not set the font-normal class when that prop is true. Then the button will inherit the font-weight by default.

function Button({ children, className, style, noFontWeight }) {
  return (
    <div
      className={twMerge("text-green-600", !noFontWeight && "font-normal", className)}
      style={style}
    >
      {children}
    </div>
  );
}

@hmaesta
Copy link
Author

hmaesta commented Dec 17, 2024

Ooof, I forgot that Tailwind CSS uses the font- prefix for both font-family and font-weight 😞

That makes sense.

Thanks for the answer, Dany.

@dcastil
Copy link
Owner

dcastil commented Dec 20, 2024

No worries. 😊 I'll close this issue for now. Let me know if this isn't resolved for you and I'll reopen.

@dcastil dcastil closed this as completed Dec 20, 2024
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