Replies: 4 comments 15 replies
-
This isn't a Tailwind problem. Rather, you haven't configured Tailwind Merge to handle your custom theme token. You'd need to extend Tailwind Merge's default configuration: --- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,8 +1,16 @@
import { clsx } from "clsx";
-import { twMerge } from "tailwind-merge";
+import { extendTailwindMerge } from "tailwind-merge";
import type { ClassValue } from "clsx";
+const twMerge = extendTailwindMerge({
+ extend: {
+ theme: {
+ text: ['tiny'],
+ },
+ },
+});
+
function cn(...inputs: Array<ClassValue>) {
return twMerge(clsx(inputs));
}
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the tip. If it's a configuration issue, why does it only happen with text sizes and not with any other attributes like color? Having Is it and expected inconsistent behavior? |
Beta Was this translation helpful? Give feedback.
-
tailwindcss/packages/tailwindcss/src/utilities.ts Line 5075 in 85575a4 Color resolution uses tailwindcss/packages/tailwindcss/src/utilities.ts Line 5083 in 85575a4 Font-size resolution uses I don't have much time to dig deeper, but I'm assuming that the bug is that custom Improving the implementation would make tailwind more consistent and intuitive. |
Beta Was this translation helpful? Give feedback.
-
I know it's not a solution, but I'll leave it here anyway: do you really need to allow any className to be passed from the parent into the component? With an enum-like approach, you could pre-declare the component's styles and thus avoid class name collisions. I know it doesn't solve the problem - it just sweeps it under the rug - but it seems more consistent to predefine the component's appearance within the component itself. Something like this: const styles = {
blue: 'text-blue-500 text-lg',
red: 'text-red-500 text-xl',
}
function MyComponent({ children, style = 'blue' }) {
return <p class={styles[style]}>{children}</p>
} <MyComponent>I am blue</MyComponent>
<MyComponent style="red">I am red</MyComponent> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What version of Tailwind CSS are you using?
4.1.11
What build tool (or framework if it abstracts the build tool) are you using?
Vite 7.1.7
What version of Node.js are you using?
bun 1.2.22
What browser are you using?
Chrome
What operating system are you using?
macOS
Reproduction URL
https://github.com/ali-issa/tailwind-text-utilities-bug
Describe your issue
When creating a custom text size utility using CSS theme variables as documented in the Tailwind CSS v4 documentation, the custom size cannot be overridden by standard text utilities when using
tailwind-merge
withclsx
.Steps to reproduce:
Expected behavior:
The
text-xl
class should override thetext-tiny
class, resulting in the text being displayed at the xl size.Actual behavior:
The custom
text-tiny
class takes precedence and the text remains at the tiny size (0.625rem), ignoring the text-xl override and all other text-* classes.Additional context:
Beta Was this translation helpful? Give feedback.
All reactions