Skip to content

Commit

Permalink
fix: the compoundSlots does not accept an array in the property
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-reinfoce authored and mskelton committed Sep 5, 2023
1 parent a9753ac commit 73bdb53
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
29 changes: 29 additions & 0 deletions src/__tests__/tv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,35 @@ describe("Tailwind Variants (TV) - Slots", () => {
expectTv(subtitle({color: "secondary"}), ["text-xl", "color--secondary-subtitle", "truncate"]);
});

test("should support slot level variant and array variants overrides - compoundSlots", () => {
const menu = tv({
slots: {
base: "flex flex-wrap",
cursor: ["absolute", "flex", "overflow-visible"],
},
variants: {
size: {
xs: {},
sm: {},
},
},
compoundSlots: [
{
slots: ["base"],
size: ["xs", "sm"],
class: "w-7 h-7 text-xs",
},
],
});

const {base, cursor} = menu();

expect(base()).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(base({size: "xs"})).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(base({size: "sm"})).toEqual("flex flex-wrap w-7 h-7 text-xs");
expect(cursor()).toEqual("absolute flex overflow-visible");
});

test("should support slot level variant overrides - compoundVariants", () => {
const menu = tv({
base: "text-3xl",
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,11 @@ export const tv = (options, configProp) => {
className: slotClassName,
...slotVariants
} of compoundSlots) {
for (const slotName of slots) {
result[slotName] = result[slotName] || [];
result[slotName].push([slotClass, slotClassName]);
}

if (!isEmptyObject(slotVariants)) {
let isValid = true;

Expand All @@ -363,11 +368,6 @@ export const tv = (options, configProp) => {
continue;
}
}

for (const slotName of slots) {
result[slotName] = result[slotName] || [];
result[slotName].push([slotClass, slotClassName]);
}
}

return result;
Expand Down

0 comments on commit 73bdb53

Please sign in to comment.