Fix web component initialization timing

This commit is contained in:
Sascha Ißbrücker
2026-01-01 01:08:54 +01:00
parent b82d07c588
commit df595f2219
8 changed files with 99 additions and 99 deletions

View File

@@ -1,28 +1,19 @@
class ClearButton extends HTMLElement {
connectedCallback() {
requestAnimationFrame(() => {
this.field = document.getElementById(this.dataset.for);
if (!this.field) {
console.error(`Field with ID ${this.dataset.for} not found`);
return;
}
this.update = this.update.bind(this);
this.clear = this.clear.bind(this);
import { HeadlessElement } from "../utils/element";
this.addEventListener("click", this.clear);
this.field.addEventListener("input", this.update);
this.field.addEventListener("value-changed", this.update);
this.update();
});
}
disconnectedCallback() {
class ClearButton extends HeadlessElement {
init() {
this.field = document.getElementById(this.dataset.for);
if (!this.field) {
console.error(`Field with ID ${this.dataset.for} not found`);
return;
}
this.removeEventListener("click", this.clear);
this.field.removeEventListener("input", this.update);
this.field.removeEventListener("value-changed", this.update);
this.update = this.update.bind(this);
this.clear = this.clear.bind(this);
this.addEventListener("click", this.clear);
this.field.addEventListener("input", this.update);
this.field.addEventListener("value-changed", this.update);
this.update();
}
update() {