Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support false-only variant with fallback behaviour #159

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/__tests__/tv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,42 @@
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"]);
});


Check warning on line 353 in src/__tests__/tv.test.ts

View workflow job for this annotation

GitHub Actions / pnpm (lint)

Delete `⏎`
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",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" &&
Expand Down
Loading