|
tailwind-merge: 3.3.0 I have some custom classes for CSS gap. They are added to the config, but some of them are not working. ConfigclassGroups: {
gap: [{ gap: ['surface'], spacing: ['xs', 'sm', 'base', 'lg'] }],
'gap-x': [{ 'gap-x': ['surface'], spacing: ['xs', 'sm', 'base', 'lg'] }],
'gap-y': [{ 'gap-y': ['surface'], spacing: ['xs', 'sm', 'base', 'lg'] }],
},Utilsexport const twMerge = extendTailwindMerge(twMergeConfig);
export const cn = (...inputs: ClassValue[]) => twMerge(clsx(inputs));Testsexpect(cn('gap-1 gap-surface')).toEqual('gap-surface'); // pass
expect(cn('gap-surface gap-1')).toEqual('gap-1'); // pass
expect(cn('gap-1 spacing-base')).toEqual('spacing-base'); // fail
expect(cn('spacing-base gap-1')).toEqual('gap-1'); // fail |
Answered by
dcastil
Jun 4, 2025
Replies: 1 comment 3 replies
|
Hey @rettimo! 👋 The problem is that you're defining the same classes in multiple groups while tailind-merge expects classes to be unique. The last defined classes override the previous in the internal logic of tailwind-merge, so it's the same as if you'd only define them in the What styles did you define in the import { extendTailwindMerge } from 'tailwind-merge'
const twMerge = extendTailwindMerge<'spacing'>({
extend: {
classGroups: {
gap: [{ gap: ['surface'] }],
'gap-x': [{ 'gap-x': ['surface'] }],
'gap-y': [{ 'gap-y': ['surface'] }],
// new group for spacing-* classes
spacing: [{ spacing: ['xs', 'sm', 'base', 'lg'] }],
},
conflictingClassGroups: {
// spacing group conflicts with all gap groups
spacing: ['gap', 'gap-x', 'gap-y'],
// all gap groups conflict with spacing group
gap: ['spacing'],
'gap-x': ['spacing'],
'gap-y': ['spacing'],
},
},
}) |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Ah got it, then you only need to add those to the
gapgroup.gap-xis for the CSS propertycolumn-gapandgap-yforrow-gap.