diff --git a/frontend/src/components/button.ts b/frontend/src/components/button.ts index e4db0a1..13b9965 100644 --- a/frontend/src/components/button.ts +++ b/frontend/src/components/button.ts @@ -4,6 +4,7 @@ export class TesoftButton extends TesoftComponent { static observedAttributes = ["disabled", "href", "selected"]; private readonly rootDiv: HTMLDivElement; + private linkOrButton: HTMLElement; constructor() { super(); @@ -15,33 +16,42 @@ export class TesoftButton extends TesoftComponent { shadowRoot.appendChild(templateContent.cloneNode(true)); this.rootDiv = shadowRoot.querySelector("div")!; + this.linkOrButton = shadowRoot.querySelector("button")!; } // noinspection JSUnusedGlobalSymbols attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) { if (name === "disabled") { if (newValue === null) { - this.rootDiv.onclick = null; + this.linkOrButton.removeAttribute("disabled"); } else { - this.rootDiv.onclick = (e) => { - e.stopPropagation(); - }; + this.linkOrButton.setAttribute("disabled", ""); } } else if (name === "href") { this.rootDiv.innerHTML = ""; - let linkOrButton: HTMLElement; if (newValue) { - linkOrButton = document.createElement("a"); - (linkOrButton as HTMLAnchorElement).href = newValue; + this.linkOrButton = document.createElement("a"); + (this.linkOrButton as HTMLAnchorElement).href = newValue; } else { - linkOrButton = document.createElement("button"); + this.linkOrButton = document.createElement("button"); } - linkOrButton.part = "children"; - this.rootDiv.appendChild(linkOrButton); + this.linkOrButton.part = "children"; + if (this.hasAttribute("disabled")) { + this.linkOrButton.setAttribute("disabled", ""); + } + this.rootDiv.appendChild(this.linkOrButton); const slot = document.createElement("slot"); - linkOrButton.appendChild(slot); + this.linkOrButton.appendChild(slot); + } + } + + set disabled(value: string | null) { + if (value === null) { + this.removeAttribute("disabled"); + } else { + this.setAttribute("disabled", ""); } }