Skip to content

fix(ui5-input): prevent typeahead during IME composition #11976

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

aleksandar-terziev
Copy link
Contributor

if (input) {
input.addEventListener("compositionstart", this._onCompositionStart.bind(this));
input.addEventListener("compositionend", this._onCompositionEnd.bind(this));
}
Copy link
Member

Choose a reason for hiding this comment

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

place this in the template file

Copy link
Contributor Author

@aleksandar-terziev aleksandar-terziev Jul 24, 2025

Choose a reason for hiding this comment

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

As we discussed, Preact does not support composition events so we need this workaround until Preact resolves the bug

}

onExitDOM() {
ResizeHandler.deregister(this, this._handleResizeBound);
deregisterUI5Element(this);
this._removeLinksEventListeners();
const input = this.getInputDOMRefSync();
Copy link
Member

Choose a reason for hiding this comment

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

if present in the template, this should not be required

}

onEnterDOM() {
ResizeHandler.register(this, this._handleResizeBound);
registerUI5Element(this, this._updateAssociatedLabelsTexts.bind(this));
const input = this.getInputDOMRefSync();
if (input) {
input.addEventListener("compositionstart", this._onCompositionStart.bind(this));
Copy link
Contributor

Choose a reason for hiding this comment

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

In addition to what Martin said - even if you were to write this here (and not in the template), you still can't use .bind for addEventListener and then again .bind for removeEventListener because each time you call bind, it returns a new function and this creates a memory leak. If you need to do something like this, you must assign to a variable and then call addEventListener with it, f.e.

this._onCompositionStartBound = this._onCompositionStart.bind(this);
input.addEventListener("compositionstart", this._onCompositionBound;

@@ -590,8 +590,10 @@ export namespace JSXInternal {

// Composition Events
onCompositionEnd?: CompositionEventHandler<Target> | undefined;
oncompositionend?: CompositionEventHandler<Target> | undefined;
Copy link
Member

Choose a reason for hiding this comment

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

add comment that this is a workaround for preactjs/preact#1978

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar approach as the initial one was used in other UI library: https://github.com/ionic-team/ionic-framework/pull/24735/files#diff-a39147111a459c7d50e285f51eddf2d3fee983bda67654c842a2c645565af6bcR281

It could be used as well in order to not change 3rd party files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added comment that this is a workaround and used the same approach used in other UI libraries as @nnaydenow shared in order to avoid changing third party files ( jsx.d.ts )

@aleksandar-terziev aleksandar-terziev self-assigned this Jul 24, 2025
@aleksandar-terziev aleksandar-terziev force-pushed the input-text-composition branch 2 times, most recently from 4ebc5b7 to 5f309da Compare July 28, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SF_ACC] [Input] Korean characters are duplicated when typing in the Input component with Suggestion Items.
4 participants