Skip to content

Merging prefixed and non-prefixed classes with Tailwind v4 #537

Answered by dcastil
djpsychofogbear asked this question in Help
Discussion options

You must be logged in to vote

Hey @djpsychofogbear! 👋

Indeed, the syntax of prefixes changed to look like a modifier, so the old way won't work anymore. But you can use experimentalParseClassName to get what you want:

const twMerge = extendTailwindMerge({
    experimentalParseClassName({ className, parseClassName }) {
        return parseClassName(
            className.startsWith('ui:') ? className.substring(3) : className
        )
    }
})

That will make tailwind-merge treat classes with ui: at the beginning as if that part wasn't there while preserving the original className that was passed to tailwind-merge. Just keep in mind that the experimentalParseClassName function can have breaking changes in minor version …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@djpsychofogbear
Comment options

Answer selected by djpsychofogbear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
context-v3 Related to tailwind-merge v3
2 participants