Fix default theme fallback when an invalid theme is passed (#15)

* fix(color): invalid theme fallback to default

Fixes: #4641

* test(color): add test case for invalid theme fallback to default

* style(color): add back the tab space

* test(color): fix color default theme

* fix(color): use 'in' instead of '.hasOwnProperty'

* fix new test

* format code

---------

Co-authored-by: mikyll <righi.michy@gmail.com>
This commit is contained in:
martin-mfg
2026-01-19 18:59:32 +01:00
committed by GitHub
co-authored by mikyll
parent 17e6aee8fc
commit b654eaac2c
2 changed files with 16 additions and 1 deletions
+2 -1
View File
@@ -83,7 +83,8 @@ const getCardColors = ({
theme,
}) => {
const defaultTheme = themes["default"];
const isThemeProvided = theme !== null && theme !== undefined;
const isThemeProvided =
theme !== null && theme !== undefined && theme in themes;
// @ts-ignore
const selectedTheme = isThemeProvided ? themes[theme] : defaultTheme;
+14
View File
@@ -73,4 +73,18 @@ describe("Test color.js", () => {
borderColor: "#fff",
});
});
it("getCardColors: should fallback to default theme if theme is invalid", () => {
let colors = getCardColors({
theme: "invalidTheme",
});
expect(colors).toStrictEqual({
titleColor: "#2f80ed",
textColor: "#434d58",
iconColor: "#4c71f2",
ringColor: "#2f80ed",
bgColor: "#fffefe",
borderColor: "#e4e2e2",
});
});
});