Skip to content

Commit

Permalink
fix: variant as array when extending (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: Giuliano Crivelli <giuliano.crivelli@byside.com>
  • Loading branch information
thefalked and Giuliano Crivelli authored Oct 30, 2023
1 parent e07e421 commit 1080de7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/__tests__/tv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,7 @@ describe("Tailwind Variants (TV) - Extends", () => {
false: "text-2xl",
},
color: {
red: "text-red-500 bg-red-100",
red: "text-red-500 bg-red-100 tracking-normal",
blue: "text-blue-500",
},
},
Expand All @@ -1949,7 +1949,7 @@ describe("Tailwind Variants (TV) - Extends", () => {
base: "text-3xl font-bold",
variants: {
color: {
red: "text-red-200",
red: ["text-red-200", "bg-red-200"],
green: "text-green-500",
},
},
Expand All @@ -1960,7 +1960,13 @@ describe("Tailwind Variants (TV) - Extends", () => {
color: "red",
});

const expectedResult = ["font-bold", "text-red-200", "bg-red-100", "text-5xl"];
const expectedResult = [
"font-bold",
"text-red-200",
"bg-red-200",
"tracking-normal",
"text-5xl",
];

expectTv(result, expectedResult);
});
Expand Down
2 changes: 2 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const mergeObjects = (obj1, obj2) => {

if (typeof val1 === "object" && typeof val2 === "object") {
result[key] = mergeObjects(val1, val2);
} else if (Array.isArray(val1) || Array.isArray(val2)) {
result[key] = flatMergeArrays(val2, val1);
} else {
result[key] = val2 + " " + val1;
}
Expand Down

0 comments on commit 1080de7

Please sign in to comment.