@@ -68,14 +68,14 @@ const metadata = {
68
68
/**
69
69
* Defines the "live" value of the <code>ui5-combobox</code>.
70
70
* <br><br>
71
- * <b>Note:</b> The property is updated upon typing .
71
+ * <b>Note:</b> If we have an item e.g. "Bulgaria", "B" is typed, "ulgaria" is typed ahead, value will be "Bulgaria", filterValue will be "B" .
72
72
*
73
73
* <br><br>
74
74
* <b>Note:</b> Initially the filter value is synced with value.
75
75
*
76
76
* @type {string }
77
77
* @defaultvalue ""
78
- * @public
78
+ * @private
79
79
*/
80
80
filterValue : {
81
81
type : String ,
@@ -214,11 +214,6 @@ const metadata = {
214
214
noAttribute : true ,
215
215
} ,
216
216
217
- _tempValue : {
218
- type : String ,
219
- defaultValue : "" ,
220
- } ,
221
-
222
217
_filteredItems : {
223
218
type : Object ,
224
219
} ,
@@ -389,27 +384,8 @@ class ComboBox extends UI5Element {
389
384
}
390
385
391
386
onBeforeRendering ( ) {
392
- let domValue ;
393
-
394
387
if ( this . _initialRendering ) {
395
- domValue = this . value ;
396
388
this . _filteredItems = this . items ;
397
- } else {
398
- domValue = this . filterValue ;
399
- }
400
-
401
- if ( this . _autocomplete && domValue !== "" ) {
402
- const item = this . _autoCompleteValue ( domValue ) ;
403
-
404
- if ( ! this . _selectionChanged && ( item && ! item . selected ) ) {
405
- this . fireEvent ( "selection-change" , {
406
- item,
407
- } ) ;
408
-
409
- this . _selectionChanged = false ;
410
- }
411
- } else {
412
- this . _tempValue = domValue ;
413
389
}
414
390
415
391
if ( ! this . _initialRendering && this . popover && document . activeElement === this && ! this . _filteredItems . length ) {
@@ -418,12 +394,6 @@ class ComboBox extends UI5Element {
418
394
419
395
this . _selectMatchingItem ( ) ;
420
396
421
- if ( this . _isKeyNavigation && this . responsivePopover && this . responsivePopover . opened ) {
422
- this . focused = false ;
423
- } else if ( this . shadowRoot . activeElement ) {
424
- this . focused = this . shadowRoot . activeElement . id === "ui5-combobox-input" ;
425
- }
426
-
427
397
this . _initialRendering = false ;
428
398
this . _isKeyNavigation = false ;
429
399
}
@@ -452,28 +422,21 @@ class ComboBox extends UI5Element {
452
422
_focusin ( event ) {
453
423
this . focused = true ;
454
424
455
- if ( this . filterValue !== this . value ) {
456
- this . filterValue = this . value ;
457
- }
425
+ this . _lastValue = this . value ;
458
426
459
427
! isPhone ( ) && event . target . setSelectionRange ( 0 , this . value . length ) ;
460
428
}
461
429
462
430
_focusout ( ) {
463
431
this . focused = false ;
464
432
465
- this . _inputChange ( ) ;
433
+ this . _fireChangeEvent ( ) ;
434
+
466
435
! isPhone ( ) && this . _closeRespPopover ( ) ;
467
436
}
468
437
469
438
_afterOpenPopover ( ) {
470
439
this . _iconPressed = true ;
471
-
472
- if ( isPhone ( ) && this . value ) {
473
- this . filterValue = this . value
474
- }
475
-
476
- this . _clearFocus ( ) ;
477
440
}
478
441
479
442
_afterClosePopover ( ) {
@@ -485,6 +448,11 @@ class ComboBox extends UI5Element {
485
448
if ( isPhone ( ) ) {
486
449
this . blur ( ) ;
487
450
}
451
+
452
+ if ( this . _selectionPerformed ) {
453
+ this . _lastValue = this . value ;
454
+ this . _selectionPerformed = false ;
455
+ }
488
456
}
489
457
490
458
_toggleRespPopover ( ) {
@@ -544,12 +512,28 @@ class ComboBox extends UI5Element {
544
512
event . stopImmediatePropagation ( ) ;
545
513
}
546
514
547
- this . _clearFocus ( ) ;
548
- this . _tempFilterValue = value ;
515
+ this . _filteredItems = this . _filterItems ( value ) ;
516
+ this . value = value ;
549
517
this . filterValue = value ;
550
- this . fireEvent ( "input" ) ;
551
518
552
- this . _filteredItems = this . _filterItems ( value ) ;
519
+ this . _clearFocus ( ) ;
520
+
521
+ // autocomplete
522
+ if ( this . _autocomplete && value !== "" ) {
523
+ const item = this . _autoCompleteValue ( value ) ;
524
+
525
+ if ( ! this . _selectionChanged && ( item && ! item . selected ) ) {
526
+ this . fireEvent ( "selection-change" , {
527
+ item,
528
+ } ) ;
529
+
530
+ this . _selectionChanged = false ;
531
+
532
+ item . focused = true ;
533
+ }
534
+ }
535
+
536
+ this . fireEvent ( "input" ) ;
553
537
554
538
if ( isPhone ( ) ) {
555
539
return ;
@@ -598,14 +582,23 @@ class ComboBox extends UI5Element {
598
582
indexOfItem = indexOfItem < 0 ? 0 : indexOfItem ;
599
583
600
584
this . _filteredItems [ indexOfItem ] . focused = true ;
601
- this . filterValue = this . _filteredItems [ indexOfItem ] . text ;
585
+ this . _filteredItems [ indexOfItem ] . selected = true ;
586
+
587
+ this . value = this . _filteredItems [ indexOfItem ] . text ;
588
+
589
+ // autocomplete
590
+ const item = this . _autoCompleteValue ( this . value ) ;
591
+
592
+ if ( ( item && ! item . selected ) ) {
593
+ this . fireEvent ( "selection-change" , {
594
+ item,
595
+ } ) ;
596
+ }
597
+
602
598
this . _isKeyNavigation = true ;
603
599
this . _itemFocused = true ;
604
600
this . fireEvent ( "input" ) ;
605
-
606
- this . fireEvent ( "selection-change" , {
607
- item : this . _filteredItems [ indexOfItem ] ,
608
- } ) ;
601
+ this . _fireChangeEvent ( ) ;
609
602
610
603
this . _selectionChanged = true ;
611
604
}
@@ -619,7 +612,7 @@ class ComboBox extends UI5Element {
619
612
}
620
613
621
614
if ( isEnter ( event ) ) {
622
- this . _inputChange ( ) ;
615
+ this . _fireChangeEvent ( ) ;
623
616
this . _closeRespPopover ( ) ;
624
617
}
625
618
@@ -640,7 +633,6 @@ class ComboBox extends UI5Element {
640
633
if ( isPhone ( ) && event && event . target . classList . contains ( "ui5-responsive-popover-close-btn" ) && this . _selectedItemText ) {
641
634
this . value = this . _selectedItemText ;
642
635
this . filterValue = this . _selectedItemText ;
643
- this . _tempValue = this . _selectedItemText ;
644
636
}
645
637
646
638
this . responsivePopover . close ( ) ;
@@ -655,23 +647,21 @@ class ComboBox extends UI5Element {
655
647
}
656
648
657
649
_autoCompleteValue ( current ) {
658
- const currentValue = current ;
659
- const matchingItems = this . _startsWithMatchingItems ( currentValue ) ;
660
- const selectionValue = this . _tempFilterValue ? this . _tempFilterValue : currentValue ;
650
+ const matchingItems = this . _startsWithMatchingItems ( current ) ;
661
651
662
652
if ( matchingItems . length ) {
663
- this . _tempValue = matchingItems [ 0 ] ? matchingItems [ 0 ] . text : current ;
653
+ this . value = matchingItems [ 0 ] ? matchingItems [ 0 ] . text : current ;
664
654
} else {
665
- this . _tempValue = current ;
655
+ this . value = current ;
666
656
}
667
657
668
- if ( matchingItems . length && ( selectionValue !== this . _tempValue && this . value !== this . _tempValue ) ) {
658
+ if ( this . _isKeyNavigation ) {
669
659
setTimeout ( ( ) => {
670
- this . inner . setSelectionRange ( selectionValue . length , this . _tempValue . length ) ;
660
+ this . inner . setSelectionRange ( 0 , this . value . length ) ;
671
661
} , 0 ) ;
672
- } else if ( this . _isKeyNavigation ) {
662
+ } else if ( matchingItems . length ) {
673
663
setTimeout ( ( ) => {
674
- this . inner . setSelectionRange ( 0 , this . _tempValue . length ) ;
664
+ this . inner . setSelectionRange ( this . filterValue . length , this . value . length ) ;
675
665
} , 0 ) ;
676
666
}
677
667
@@ -682,30 +672,41 @@ class ComboBox extends UI5Element {
682
672
683
673
_selectMatchingItem ( ) {
684
674
this . _filteredItems = this . _filteredItems . map ( item => {
685
- item . selected = ( item . text === this . _tempValue ) ;
675
+ item . selected = ( item . text === this . value ) ;
686
676
687
677
return item ;
688
678
} ) ;
689
679
}
690
680
691
- _inputChange ( ) {
692
- if ( this . value !== this . _tempValue ) {
693
- this . value = this . _tempValue ;
681
+ _fireChangeEvent ( ) {
682
+ if ( this . value !== this . _lastValue ) {
694
683
this . fireEvent ( "change" ) ;
695
- this . inner . setSelectionRange ( this . value . length , this . value . length ) ;
684
+ this . _lastValue = this . value ;
696
685
}
697
686
}
698
687
688
+ _inputChange ( event ) {
689
+ event . preventDefault ( ) ;
690
+ }
691
+
699
692
_itemMousedown ( event ) {
700
693
event . preventDefault ( ) ;
701
694
}
702
695
703
696
_selectItem ( event ) {
704
697
const listItem = event . detail . item ;
705
698
706
- this . _tempValue = listItem . mappedItem . text ;
707
699
this . _selectedItemText = listItem . mappedItem . text ;
708
- this . filterValue = this . _tempValue ;
700
+ this . _selectionPerformed = true ;
701
+
702
+ const sameItemSelected = this . value === this . _selectedItemText ;
703
+ const sameSelectionPerformed = this . value . toLowerCase ( ) === this . filterValue . toLowerCase ( ) ;
704
+
705
+ if ( sameItemSelected && sameSelectionPerformed ) {
706
+ return this . _closeRespPopover ( ) ;
707
+ }
708
+
709
+ this . value = this . _selectedItemText ;
709
710
710
711
if ( ! listItem . mappedItem . selected ) {
711
712
this . fireEvent ( "selection-change" , {
@@ -721,8 +722,11 @@ class ComboBox extends UI5Element {
721
722
return item ;
722
723
} ) ;
723
724
724
- this . _inputChange ( ) ;
725
+ this . _fireChangeEvent ( ) ;
725
726
this . _closeRespPopover ( ) ;
727
+
728
+ // reset selection
729
+ this . inner . setSelectionRange ( this . value . length , this . value . length ) ;
726
730
}
727
731
728
732
_onItemFocus ( event ) {
0 commit comments