diff --git a/src/__tests__/tv.test.ts b/src/__tests__/tv.test.ts index 641f612..3e84406 100644 --- a/src/__tests__/tv.test.ts +++ b/src/__tests__/tv.test.ts @@ -334,6 +334,42 @@ describe("Tailwind Variants (TV) - Default", () => { expect(h1({bool: undefined})).toHaveClass(["text-3xl", "truncate"]); }); + test("should support false only variant", () => { + const h1 = tv({ + base: "text-3xl", + variants: { + bool: { + false: "truncate", + }, + }, + }); + + expect(h1()).toHaveClass(["text-3xl", "truncate"]); + expect(h1({bool: true})).toHaveClass(["text-3xl"]); + expect(h1({bool: false})).toHaveClass(["text-3xl", "truncate"]); + expect(h1({bool: undefined})).toHaveClass(["text-3xl", "truncate"]); + }); + + + test("should support false only variant -- default variant", () => { + const h1 = tv({ + base: "text-3xl", + variants: { + bool: { + false: "truncate", + }, + }, + defaultVariants: { + bool: true, + }, + }); + + expect(h1()).toHaveClass(["text-3xl"]); + expect(h1({bool: true})).toHaveClass(["text-3xl"]); + expect(h1({bool: false})).toHaveClass(["text-3xl", "truncate"]); + expect(h1({bool: undefined})).toHaveClass(["text-3xl"]); + }); + test("should support boolean variants -- default variants", () => { const h1 = tv({ base: "text-3xl", diff --git a/src/index.js b/src/index.js index 920dc2b..8b0e806 100644 --- a/src/index.js +++ b/src/index.js @@ -217,7 +217,7 @@ export const tv = (options, configProp) => { ? variantKey : falsyToString(defaultVariantProp); - const value = variantObj[key] || variantObj["false"]; + const value = variantObj[key || "false"]; if ( typeof screenValues === "object" &&