Skip to content

Commit 1dc2ffb

Browse files
fix(ui5-input): prevent typeahead during IME composition
1 parent 1101b09 commit 1dc2ffb

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

packages/main/src/Input.ts

Lines changed: 23 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,17 +703,38 @@ 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() {
708712
ResizeHandler.register(this, this._handleResizeBound);
709713
registerUI5Element(this, this._updateAssociatedLabelsTexts.bind(this));
714+
const input = this.getInputDOMRefSync();
715+
if (input) {
716+
input.addEventListener("compositionstart", this._onCompositionStart.bind(this));
717+
input.addEventListener("compositionend", this._onCompositionEnd.bind(this));
718+
}
710719
}
711720

712721
onExitDOM() {
713722
ResizeHandler.deregister(this, this._handleResizeBound);
714723
deregisterUI5Element(this);
715724
this._removeLinksEventListeners();
725+
const input = this.getInputDOMRefSync();
726+
if (input) {
727+
input.removeEventListener("compositionstart", this._onCompositionStart.bind(this));
728+
input.removeEventListener("compositionend", this._onCompositionEnd.bind(this));
729+
}
730+
}
731+
732+
_onCompositionStart() {
733+
this._isComposing = true;
734+
}
735+
736+
_onCompositionEnd() {
737+
this._isComposing = false;
716738
}
717739

718740
_highlightSuggestionItem(item: SuggestionItem) {
@@ -773,7 +795,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
773795

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

0 commit comments

Comments
 (0)