Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/main/src/TextArea.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
maxlength="{{_exceededTextProps.calcedMaxLength}}"
aria-labelledby={{ariaLabelledBy}}
.value="{{value}}"
@change="{{_listeners.change}}"
@input="{{_handleInput}}"
@change="{{_handleChange}}"
data-sap-focus-ref>
</textarea>

Expand Down
50 changes: 43 additions & 7 deletions packages/main/src/TextArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import Integer from "@ui5/webcomponents-base/dist/types/Integer.js";
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
import { isIE } from "@ui5/webcomponents-core/dist/sap/ui/Device.js";
import TextAreaTemplate from "./generated/templates/TextAreaTemplate.lit.js";

import { TEXTAREA_CHARACTERS_LEFT, TEXTAREA_CHARACTERS_EXCEEDED } from "./generated/i18n/i18n-defaults.js";
Expand Down Expand Up @@ -189,9 +190,6 @@ const metadata = {
type: String,
noAttribute: true,
},
_listeners: {
type: Object,
},
},
events: /** @lends sap.ui.webcomponents.main.TextArea.prototype */ {
/**
Expand All @@ -201,6 +199,16 @@ const metadata = {
* @public
*/
change: {},

/**
* Fired when the value of the <code>ui5-textarea</code> changes at each keystroke or when
* something is pasted.
*
* @event
* @since 1.0.0-rc.5
* @public
*/
input: {},
},
};

Expand Down Expand Up @@ -249,10 +257,6 @@ class TextArea extends UI5Element {
super();

this.i18nBundle = getI18nBundle("@ui5/webcomponents");

this._listeners = {
change: this._handleChange.bind(this),
};
}

onBeforeRendering() {
Expand Down Expand Up @@ -294,6 +298,14 @@ class TextArea extends UI5Element {
this.value = inputValue;
}

onkeydown() {
this._keyDown = true;
}

onkeyup() {
this._keyDown = false;
}

onfocusin() {
this.focused = true;
}
Expand All @@ -306,6 +318,30 @@ class TextArea extends UI5Element {
this.fireEvent("change", {});
}

_handleInput(event) {
const nativeTextarea = this.getInputDomRef();

/* skip calling change event when an textarea with a placeholder is focused on IE
- value of the host and the internal textarea should be different in case of actual input
- input is called when a key is pressed => keyup should not be called yet
*/
const skipFiring = (this.getInputDomRef().value === this.value) && isIE() && !this._keyDown && !!this.placeholder;
if (event.target === nativeTextarea) {
// stop the native event, as the semantic "input" would be fired.
event.stopImmediatePropagation();
}

if (skipFiring) {
return;
}

this.value = nativeTextarea.value;
this.fireEvent("input", {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add "value-change" to make "origami" work?


// Angular two way data binding
this.fireEvent("value-changed");
}

_tokenizeText(value) {
const tokenizedText = value.replace(/&/gm, "&amp;").replace(/"/gm, "&quot;").replace(/"/gm, "&#39;").replace(/</gm, "&lt;")
.replace(/>/gm, "&gt;")
Expand Down