@@ -323,8 +323,10 @@ define(["../notjQuery"], function ($) {
323323
324324 if ( ! stopAtEdge && this . completedValue !== null ) {
325325 if ( input === this . completedInput ) {
326+ this . hasBeenManuallyChanged = true ;
326327 this . suggest ( this . completedInput , this . completedValue ) ;
327328 } else {
329+ this . hasBeenManuallyChanged = false ;
328330 this . suggest ( this . completedInput , input . value , { ...input . dataset } ) ;
329331 }
330332 }
@@ -478,16 +480,20 @@ define(["../notjQuery"], function ($) {
478480 }
479481
480482 onFocusOut ( event ) {
481- // Autosubmit if the user leaves the input and the input has been manually changed.
482- // Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
483- // autosubmit themselves via BaseInput.autoSubmit() with proper term data.
484- if ( ! this . instrumented && this . hasBeenManuallyChanged && this . shouldAutoSubmit ( ) ) {
485- this . hasBeenManuallyChanged = false ;
486- let input = event . target ;
487- setTimeout ( ( ) => {
488- $ ( input . form ) . trigger ( 'submit' , { submittedBy : input } ) ;
489- } , 300 ) ;
490- }
483+ setTimeout ( ( ) => {
484+ // Autosubmit if the user leaves the input and the input has been manually changed.
485+ // Only for non-instrumented mode — instrumented inputs (e.g. TermInput) handle
486+ // autosubmit themselves via BaseInput.autoSubmit() with proper term data.
487+ if (
488+ ! this . instrumented
489+ && this . hasBeenManuallyChanged
490+ && ! this . hasSuggestions ( )
491+ && this . shouldAutoSubmit ( )
492+ ) {
493+ this . hasBeenManuallyChanged = false ;
494+ $ ( this . input . form ) . trigger ( 'submit' , { submittedBy : this . input } ) ;
495+ }
496+ } , 300 ) ;
491497
492498 if ( this . completedInput === null ) {
493499 // If there are multiple instances of Completer bound to the same suggestion container
@@ -511,6 +517,7 @@ define(["../notjQuery"], function ($) {
511517 }
512518
513519 this . hideSuggestions ( ) ;
520+
514521 this . hasBeenManuallyChanged = true ;
515522 }
516523 } , 250 ) ;
@@ -645,6 +652,10 @@ define(["../notjQuery"], function ($) {
645652
646653 onKeyDown ( event ) {
647654 let suggestions ;
655+ const keys = [ 'Tab' , 'ArrowDown' , 'ArrowUp' ] ;
656+ if ( keys . includes ( event . key ) && ( event . target === this . input && this . hasSuggestions ( ) ) ) {
657+ this . hasBeenManuallyChanged = false ;
658+ }
648659
649660 switch ( event . key ) {
650661 case ' ' :
@@ -669,7 +680,6 @@ define(["../notjQuery"], function ($) {
669680 break ;
670681 case 'Tab' :
671682 suggestions = this . termSuggestions . querySelectorAll ( '[type="button"]' ) ;
672- this . hasBeenManuallyChanged = false ;
673683 if ( suggestions . length === 1 ) {
674684 event . preventDefault ( ) ;
675685 let input = event . target ;
@@ -699,7 +709,6 @@ define(["../notjQuery"], function ($) {
699709 break ;
700710 case 'ArrowUp' :
701711 suggestions = this . termSuggestions . querySelectorAll ( '[type="button"]' ) ;
702- this . hasBeenManuallyChanged = false ;
703712 if ( suggestions . length ) {
704713 event . preventDefault ( ) ;
705714 this . moveToSuggestion ( true ) ;
@@ -708,7 +717,6 @@ define(["../notjQuery"], function ($) {
708717 break ;
709718 case 'ArrowDown' :
710719 suggestions = this . termSuggestions . querySelectorAll ( '[type="button"]' ) ;
711- this . hasBeenManuallyChanged = false ;
712720 if ( suggestions . length ) {
713721 event . preventDefault ( ) ;
714722 this . moveToSuggestion ( ) ;
@@ -730,8 +738,6 @@ define(["../notjQuery"], function ($) {
730738
731739 onInput ( event ) {
732740 let input = event . target ;
733- this . hasBeenManuallyChanged = true ;
734-
735741 if ( input . minLength > 0 && input . value . length < input . minLength ) {
736742 return ;
737743 }
@@ -749,6 +755,7 @@ define(["../notjQuery"], function ($) {
749755 dataElement . value = input . value ;
750756 }
751757
758+ this . hasBeenManuallyChanged = true ;
752759 let [ value , data ] = this . prepareCompletionData ( input ) ;
753760 this . completedInput = input ;
754761 this . completedValue = value ;
0 commit comments