Skip to content

Commit

Permalink
fix(system-rsc): extendVariants with defaultVariants (#3299)
Browse files Browse the repository at this point in the history
  • Loading branch information
wingkwong committed Jun 22, 2024
1 parent 6951b1f commit f785d1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-cherries-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/system-rsc": patch
---

fixed `extendVariants` when having `defaultVariants` (#3009)
14 changes: 11 additions & 3 deletions packages/core/system-rsc/src/extend-variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,30 @@ 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);
}
}
}

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}),
},
Expand Down

0 comments on commit f785d1f

Please sign in to comment.