diff --git a/.changeset/clever-cherries-watch.md b/.changeset/clever-cherries-watch.md new file mode 100644 index 0000000000..0bcabdb379 --- /dev/null +++ b/.changeset/clever-cherries-watch.md @@ -0,0 +1,5 @@ +--- +"@nextui-org/system-rsc": patch +--- + +fixed `extendVariants` when having `defaultVariants` (#3009) diff --git a/packages/core/system-rsc/src/extend-variants.js b/packages/core/system-rsc/src/extend-variants.js index fbf1905595..27387cdf9a 100644 --- a/packages/core/system-rsc/src/extend-variants.js +++ b/packages/core/system-rsc/src/extend-variants.js @@ -31,14 +31,15 @@ function getClassNamesWithProps({ hasSlots, opts, }) { - // Do not apply default variants when the props variant is different + const keys = []; + if (defaultVariants && typeof defaultVariants === "object") { for (const key in defaultVariants) { const value = defaultVariants[key]; const propValue = props?.[key]; if (propValue && propValue !== value) { - delete defaultVariants[key]; + keys.push(key); } } } @@ -46,7 +47,14 @@ function getClassNamesWithProps({ const customTv = tv( { variants, - defaultVariants, + // Do not apply default variants when the props variant is different + defaultVariants: Object.keys(defaultVariants) + .filter((k) => !keys.includes(k)) + .reduce((o, k) => { + o[k] = defaultVariants[k]; + + return o; + }, []), compoundVariants, ...(hasSlots && {slots}), },