From 6de0aca1953ddac782bca3cc4934aca47da7f837 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 15 May 2025 06:32:11 +0200 Subject: [PATCH] REFA,FIX,IMPRO: changed default behaviour of text() Instead of catching the default behaviour for HTMLInputElements when calling text() on every component, It is now an extension for InputComponents. --- src/component/ChildbearerComponent.js | 6 +----- src/component/InputComponent.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/component/ChildbearerComponent.js b/src/component/ChildbearerComponent.js index 4219b1a..0336112 100644 --- a/src/component/ChildbearerComponent.js +++ b/src/component/ChildbearerComponent.js @@ -61,11 +61,7 @@ class ElementWrapper { * @returns {Component} this component object */ text(text) { - if (this._element instanceof HTMLInputElement && this._element.type === "text") { - this._element.value = text; - } else { - this._element.innerText = text; - } + this._element.innerText = text; return this; } diff --git a/src/component/InputComponent.js b/src/component/InputComponent.js index 151684c..5681660 100644 --- a/src/component/InputComponent.js +++ b/src/component/InputComponent.js @@ -18,6 +18,24 @@ class InputComponent extends Component { } } + /** + * This overrides the text() method in such a way, + * that it sets the value attribute for input elements instead. + * + * @override + * @inheritdoc + * @param {string} text + * @returns {InputComponent} + */ + text(text){ + if (this._element instanceof HTMLInputElement) { + this._element.value = text; + } else { + super.text(text); + } + return this; + } + /** * The parameter makes it optional to trigger the state by a variable * @param {boolean} readonly