Skip to content

Commit 10e750c

Browse files
fix(ui5-input): prevent typeahead during IME composition
1 parent a35b932 commit 10e750c

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/base/src/thirdparty/preact/jsx.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,10 @@ export namespace JSXInternal {
590590

591591
// Composition Events
592592
onCompositionEnd?: CompositionEventHandler<Target> | undefined;
593+
oncompositionend?: CompositionEventHandler<Target> | undefined;
593594
onCompositionEndCapture?: CompositionEventHandler<Target> | undefined;
594595
onCompositionStart?: CompositionEventHandler<Target> | undefined;
596+
oncompositionstart?: CompositionEventHandler<Target> | undefined;
595597
onCompositionStartCapture?: CompositionEventHandler<Target> | undefined;
596598
onCompositionUpdate?: CompositionEventHandler<Target> | undefined;
597599
onCompositionUpdateCapture?: CompositionEventHandler<Target> | undefined;

packages/main/src/Input.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
606606
})
607607
valueStateMessage!: Array<HTMLElement>;
608608

609+
_isComposing: boolean;
609610
hasSuggestionItemSelected: boolean;
610611
valueBeforeItemSelection: string;
611612
valueBeforeSelectionStart: string;
@@ -702,6 +703,9 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
702703
this._keepInnerValue = false;
703704
this._focusedAfterClear = false;
704705
this._valueStateLinks = [];
706+
707+
// Used to track if the user is composing text.
708+
this._isComposing = false;
705709
}
706710

707711
onEnterDOM() {
@@ -715,6 +719,14 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
715719
this._removeLinksEventListeners();
716720
}
717721

722+
_onCompositionStart() {
723+
this._isComposing = true;
724+
}
725+
726+
_onCompositionEnd() {
727+
this._isComposing = false;
728+
}
729+
718730
_highlightSuggestionItem(item: SuggestionItem) {
719731
item.markupText = this.typedInValue ? this.Suggestions?.hightlightInput((item.text || ""), this.typedInValue) : encodeXML(item.text || "");
720732
}
@@ -773,7 +785,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
773785

774786
// Typehead causes issues on Android devices, so we disable it for now
775787
// If there is already a selection the autocomplete has already been performed
776-
if (this._shouldAutocomplete && !isAndroid() && !autoCompletedChars && !this._isKeyNavigation) {
788+
if (this._shouldAutocomplete && !isAndroid() && !autoCompletedChars && !this._isKeyNavigation && !this._isComposing) {
777789
const item = this._getFirstMatchingItem(value);
778790
if (item) {
779791
this._handleTypeAhead(item);

packages/main/src/InputTemplate.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ export default function InputTemplate(this: Input, hooks?: { preContent: Templat
5858
onKeyUp={this._onkeyup}
5959
onClick={this._click}
6060
onFocusIn={this.innerFocusIn}
61+
oncompositionstart={this._onCompositionStart}
62+
oncompositionend={this._onCompositionEnd}
6163
/>
6264

6365
{this._effectiveShowClearIcon &&

0 commit comments

Comments
 (0)