Skip to content

Commit

Permalink
Fix the icon being duplicated when notices are inserted again
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Oct 10, 2024
1 parent d2cf7ba commit 9886f77
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
22 changes: 15 additions & 7 deletions ts/WoltLabSuite/WebComponent/woltlab-core-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@
}

class WoltlabCoreNoticeElement extends HTMLElement {
#iconElement?: FaIcon;
readonly #iconElement: FaIcon;
#contentWrapper?: HTMLElement;

connectedCallback() {
const shadow = this.attachShadow({ mode: "open" });
constructor() {
super();

this.#iconElement = document.createElement("fa-icon");
this.#iconElement.size = 24;
this.#iconElement.setIcon(this.icon, true);
this.#iconElement.slot = "icon";
}

connectedCallback() {
this.#setupShadowRoot();
this.#updateType();

this.querySelector(':scope > fa-icon[slot="icon"]')?.remove();
this.append(this.#iconElement);
}

#setupShadowRoot(): void {
const shadow = this.attachShadow({ mode: "open" });

const style = document.createElement("style");
style.textContent = `
Expand All @@ -46,12 +56,10 @@
iconSlot.name = "icon";

shadow.append(style, iconSlot, this.#contentWrapper);

this.#updateType();
}

#updateType(): void {
this.#iconElement!.setIcon(this.icon, true);
this.#iconElement.setIcon(this.icon, true);
this.#contentWrapper!.setAttribute("role", this.type === Type.Error ? "alert" : "status");
this.classList.remove(...Object.values(Type));
this.classList.add(this.type);
Expand Down
Loading

0 comments on commit 9886f77

Please sign in to comment.