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