@@ -161,6 +161,8 @@ type InputSuggestionScrollEventDetail = {
161
161
scrollContainer : HTMLElement ;
162
162
}
163
163
164
+ type CompositionEventHandler = ( e ?: CompositionEvent ) => void ;
165
+
164
166
/**
165
167
* @class
166
168
* ### Overview
@@ -566,6 +568,13 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
566
568
@property ( { type : Array } )
567
569
_linksListenersArray : Array < ( args : any ) => void > = [ ] ;
568
570
571
+ /**
572
+ * Indicates whether the input is currently being composed (e.g. during IME input).
573
+ * @private
574
+ */
575
+ @property ( { type : Boolean , noAttribute : true } )
576
+ _isComposing = false ;
577
+
569
578
/**
570
579
* Defines the suggestion items.
571
580
*
@@ -606,6 +615,8 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
606
615
} )
607
616
valueStateMessage ! : Array < HTMLElement > ;
608
617
618
+ _onCompositionStartBound : CompositionEventHandler ;
619
+ _onCompositionEndBound : CompositionEventHandler ;
609
620
hasSuggestionItemSelected : boolean ;
610
621
valueBeforeItemSelection : string ;
611
622
valueBeforeSelectionStart : string ;
@@ -702,17 +713,43 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
702
713
this . _keepInnerValue = false ;
703
714
this . _focusedAfterClear = false ;
704
715
this . _valueStateLinks = [ ] ;
716
+
717
+ this . _onCompositionStartBound = this . _onCompositionStart . bind ( this ) ;
718
+ this . _onCompositionEndBound = this . _onCompositionEnd . bind ( this ) ;
705
719
}
706
720
707
721
onEnterDOM ( ) {
708
722
ResizeHandler . register ( this , this . _handleResizeBound ) ;
709
723
registerUI5Element ( this , this . _updateAssociatedLabelsTexts . bind ( this ) ) ;
724
+ const input = this . nativeInput ;
725
+ if ( input ) {
726
+ // Update to JSX bindings when Preact resolves bug with:
727
+ // https://github.com/preactjs/preact/issues/1978
728
+ input . addEventListener ( "compositionstart" , this . _onCompositionStartBound ) ;
729
+ input . addEventListener ( "compositionend" , this . _onCompositionEndBound ) ;
730
+ }
710
731
}
711
732
712
733
onExitDOM ( ) {
713
734
ResizeHandler . deregister ( this , this . _handleResizeBound ) ;
714
735
deregisterUI5Element ( this ) ;
715
736
this . _removeLinksEventListeners ( ) ;
737
+ const input = this . nativeInput ;
738
+ if ( input ) {
739
+ input . removeEventListener ( "compositionstart" , this . _onCompositionStartBound ) ;
740
+ input . removeEventListener ( "compositionend" , this . _onCompositionEndBound ) ;
741
+ }
742
+ }
743
+
744
+ _onCompositionStart ( ) {
745
+ this . _isComposing = true ;
746
+ }
747
+
748
+ _onCompositionEnd ( ) {
749
+ //use requestAnimationFrame to defer the typeahead and autocomplete logic inside onBeforeRendering to ensure the input value is up-to-date after IME composition.
750
+ requestAnimationFrame ( ( ) => {
751
+ this . _isComposing = false ;
752
+ } ) ;
716
753
}
717
754
718
755
_highlightSuggestionItem ( item : SuggestionItem ) {
@@ -773,7 +810,7 @@ class Input extends UI5Element implements SuggestionComponent, IFormInputElement
773
810
774
811
// Typehead causes issues on Android devices, so we disable it for now
775
812
// If there is already a selection the autocomplete has already been performed
776
- if ( this . _shouldAutocomplete && ! isAndroid ( ) && ! autoCompletedChars && ! this . _isKeyNavigation ) {
813
+ if ( this . _shouldAutocomplete && ! isAndroid ( ) && ! autoCompletedChars && ! this . _isKeyNavigation && ! this . _isComposing ) {
777
814
const item = this . _getFirstMatchingItem ( value ) ;
778
815
if ( item ) {
779
816
this . _handleTypeAhead ( item ) ;
0 commit comments