From 9b5f5773e59561697c4dfd4218de1575e1bdad37 Mon Sep 17 00:00:00 2001 From: Ali Idrizi <20397725+ali-idrizi@users.noreply.github.com> Date: Thu, 14 Aug 2025 16:08:28 +0200 Subject: [PATCH] fix: add compound variant array className to base when slot key is unspecified --- src/__tests__/tv.test.ts | 13 +++++++++++++ src/index.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/__tests__/tv.test.ts b/src/__tests__/tv.test.ts index b18f95e..47fab01 100644 --- a/src/__tests__/tv.test.ts +++ b/src/__tests__/tv.test.ts @@ -1156,6 +1156,7 @@ describe("Tailwind Variants (TV) - Slots", () => { base: "color--secondary-base", title: "color--secondary-title", }, + tertiary: {}, }, }, compoundVariants: [ @@ -1165,6 +1166,16 @@ describe("Tailwind Variants (TV) - Slots", () => { title: "truncate", }, }, + { + color: "tertiary", + class: ["color--tertiary-base"], + }, + { + color: "tertiary", + class: { + title: "color--tertiary-title", + }, + }, ], defaultVariants: { color: "primary", @@ -1181,6 +1192,8 @@ describe("Tailwind Variants (TV) - Slots", () => { "color--secondary-title", "truncate", ]); + expect(base({color: "tertiary"})).toHaveClass(["text-3xl", "color--tertiary-base"]); + expect(title({color: "tertiary"})).toHaveClass(["text-2xl", "color--tertiary-title"]); }); }); diff --git a/src/index.js b/src/index.js index a2315f9..512b1b6 100644 --- a/src/index.js +++ b/src/index.js @@ -360,7 +360,7 @@ export const tv = (options, configProp) => { for (let i = 0; i < compoundClassNames.length; i++) { const className = compoundClassNames[i]; - if (typeof className === "string") { + if (typeof className === "string" || Array.isArray(className)) { result.base = cnFn(result.base, className)(config); } else if (typeof className === "object") { for (const slot in className) {