-
Notifications
You must be signed in to change notification settings - Fork 278
feat(ui5-textarea): implement input event #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be081cc
feat(ui5-textarea): implement input event
fifoosid 6a2d9ff
fix eslint
fifoosid 6db7a97
remove binding of event handler
fifoosid 3a161fb
Merge branch 'master' into 'textarea-input-event'
fifoosid 15676cf
skip input event for placeholder in IE
fifoosid 69c057d
resolve comments
fifoosid 5398a09
Add angular two way data binding support
fifoosid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -189,9 +190,6 @@ const metadata = { | |
type: String, | ||
noAttribute: true, | ||
}, | ||
_listeners: { | ||
type: Object, | ||
}, | ||
}, | ||
events: /** @lends sap.ui.webcomponents.main.TextArea.prototype */ { | ||
/** | ||
|
@@ -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: {}, | ||
}, | ||
}; | ||
|
||
|
@@ -249,10 +257,6 @@ class TextArea extends UI5Element { | |
super(); | ||
|
||
this.i18nBundle = getI18nBundle("@ui5/webcomponents"); | ||
|
||
this._listeners = { | ||
change: this._handleChange.bind(this), | ||
}; | ||
} | ||
|
||
onBeforeRendering() { | ||
|
@@ -294,6 +298,14 @@ class TextArea extends UI5Element { | |
this.value = inputValue; | ||
} | ||
|
||
onkeydown() { | ||
this._keyDown = true; | ||
} | ||
|
||
onkeyup() { | ||
this._keyDown = false; | ||
} | ||
|
||
onfocusin() { | ||
this.focused = true; | ||
} | ||
|
@@ -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", {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, "&").replace(/"/gm, """).replace(/"/gm, "'").replace(/</gm, "<") | ||
.replace(/>/gm, ">") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.