Skip to content

Commit 7055e3a

Browse files
committed
fix: icon compoennt not escaping id
1 parent a61c5da commit 7055e3a

File tree

2 files changed

+1286
-1283
lines changed

2 files changed

+1286
-1283
lines changed

src/component/Icon.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { svg } from "svg-sprites/sheet";
22

33
let svgSheet: HTMLDivElement;
44
let supportsAdoptingStyleSheets = true;
5+
let loaded: Promise<void>;
56

67
async function loadSvgSheet() {
78
svgSheet = document.createElement("div");
89
svgSheet.innerHTML = await svg();
910
}
1011

1112
if (typeof window !== "undefined") {
12-
loadSvgSheet();
13+
loaded = loadSvgSheet();
1314

1415
supportsAdoptingStyleSheets =
1516
globalThis.ShadowRoot &&
@@ -63,9 +64,11 @@ export class FraIcon extends HTMLElement {
6364
if (icon !== null) this.setAttribute("name", icon);
6465
}
6566

66-
attributeChangedCallback(): void {
67-
const name = this.name;
68-
const symbol = svgSheet.querySelector(`#${name}`);
67+
async attributeChangedCallback() {
68+
await loaded;
69+
70+
const symbol = svgSheet.querySelector(`#${this.name?.replace(/\//g, "\\/")}`);
71+
6972
if (this.shadowRoot && symbol) {
7073
this.shadowRoot.innerHTML = /*html*/ `
7174
<svg viewBox="${symbol.getAttribute("viewBox")}" aria-hidden="true">

0 commit comments

Comments
 (0)