Browse Source

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.
master
chris 1 month ago
parent
commit
6de0aca195
  1. 6
      src/component/ChildbearerComponent.js
  2. 18
      src/component/InputComponent.js

6
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;
}

18
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

Loading…
Cancel
Save