diff --git a/src/basic.test.ts b/src/basic.test.ts index 5dba863..e476abb 100644 --- a/src/basic.test.ts +++ b/src/basic.test.ts @@ -98,7 +98,7 @@ describe("size", () => { size: "2x", }); const style = getComputedStyle(getFa()); - expect(style["font-size"]).toBe("2em"); + expect(style.getPropertyValue("font-size")).toBe("2em"); }); test("lg", async () => { diff --git a/src/layers.test.ts b/src/layers.test.ts index 829e566..eb5adaf 100644 --- a/src/layers.test.ts +++ b/src/layers.test.ts @@ -56,14 +56,16 @@ test("basic", async () => { expect(getFaLayersText("b").getAttribute("id")).toBe("b"); expect(getFaLayersText("b").getAttribute("class")).toContain("class-b"); - expect(getComputedStyle(getFaLayersText("b").querySelector("span"))["color"]).toBe( + expect(getComputedStyle(getFaLayersText("b").querySelector("span")!)["color"]).toBe( "rgb(0, 0, 255)", ); }); test("color", async () => { mountFaLayers({}, { color: "red" }); - expect(getComputedStyle(getFaLayersText().querySelector("span"))["color"]).toBe("rgb(255, 0, 0)"); + expect(getComputedStyle(getFaLayersText().querySelector("span")!)["color"]).toBe( + "rgb(255, 0, 0)", + ); mountFaLayers({}, { color: undefined }); expect(getFaLayersText().querySelector("span")?.getAttribute("style")).not.toContain("color:red"); }); @@ -80,9 +82,9 @@ describe("size", () => { mountFaLayers({ size: "2x" }, { size: "2x" }); const style = getComputedStyle(getFaLayers()); - const styleText = getComputedStyle(getFaLayersText().querySelector("span")); - expect(style["font-size"]).toBe("2em"); - expect(styleText["font-size"]).toBe("2em"); + const styleText = getComputedStyle(getFaLayersText().querySelector("span")!); + expect(style.getPropertyValue("font-size")).toBe("2em"); + expect(styleText.getPropertyValue("font-size")).toBe("2em"); }); test("lg", async () => { diff --git a/src/lib/fa.svelte b/src/lib/fa.svelte index 17b551d..4d1d50c 100644 --- a/src/lib/fa.svelte +++ b/src/lib/fa.svelte @@ -31,7 +31,7 @@ export let secondaryOpacity: number | string = 0.4; export let swapOpacity = false; - let svgElement: HTMLElement; + let svgElement: HTMLElement | SVGElement; $: svgElement && size && setCutomFontSize(svgElement, size); $: i = (icon && icon.icon) || [0, 0, "", [], ""]; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 3803edc..b01fa63 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,8 +1,10 @@ -export function setCutomFontSize(element: HTMLElement, size: IconSize | ""): void { - if (size && size !== "lg" && size !== "sm" && size !== "xs" && size !== "") { +import type { IconSize } from "./types.js"; + +export function setCutomFontSize(element: HTMLElement | SVGElement, size: IconSize | ""): void { + if (size && size !== "lg" && size !== "sm" && size !== "xs") { element.style.fontSize = size.replace("x", "em"); } else { - element.style.fontSize = undefined; + element.style.fontSize = ""; } }