Handle editable-area display resize better

This commit is contained in:
Adrian Gruntkowski 2024-12-07 20:17:29 +01:00
parent e24bc938c1
commit 23a1929ddd

View file

@ -23,6 +23,11 @@ class EditableArea extends HTMLElement {
this.#sync(); this.#sync();
}); });
new ResizeObserver(() => {
this.inputElement.style.height = this.displayElement.scrollHeight + "px";
this.inputElement.style.width = this.displayElement.scrollWidth + "px";
}).observe(this.displayElement);
this.#updateReadonly(); this.#updateReadonly();
this.#sync(); this.#sync();
} }
@ -87,8 +92,6 @@ class EditableArea extends HTMLElement {
#sync() { #sync() {
this.displayElement.replaceChildren(...renderText(this.inputElement.value)); this.displayElement.replaceChildren(...renderText(this.inputElement.value));
this.inputElement.style.height = this.displayElement.scrollHeight + "px";
this.inputElement.style.width = this.displayElement.scrollWidth + "px";
} }
} }