@@ -189,6 +189,14 @@ const metadata = {
189
189
type : Boolean ,
190
190
} ,
191
191
192
+ /**
193
+ * Indicates whether the visual focus is on the value state header
194
+ * @private
195
+ */
196
+ _isValueStateFocused : {
197
+ type : Boolean ,
198
+ } ,
199
+
192
200
/**
193
201
* Sets the accessible aria name of the component.
194
202
*
@@ -390,13 +398,6 @@ class ComboBox extends UI5Element {
390
398
}
391
399
392
400
this . _selectMatchingItem ( ) ;
393
-
394
- if ( this . _isKeyNavigation && this . responsivePopover && this . responsivePopover . opened ) {
395
- this . focused = false ;
396
- } else if ( this . shadowRoot . activeElement ) {
397
- this . focused = this . shadowRoot . activeElement . id === "ui5-combobox-input" ;
398
- }
399
-
400
401
this . _initialRendering = false ;
401
402
this . _isKeyNavigation = false ;
402
403
}
@@ -410,15 +411,16 @@ class ComboBox extends UI5Element {
410
411
411
412
if ( this . shouldClosePopover ( ) && ! isPhone ( ) ) {
412
413
this . responsivePopover . close ( false , false , true ) ;
414
+ this . _clearFocus ( ) ;
415
+ this . _itemFocused = false ;
413
416
}
414
417
415
- this . _itemFocused = false ;
416
418
this . toggleValueStatePopover ( this . shouldOpenValueStateMessagePopover ) ;
417
419
this . storeResponsivePopoverWidth ( ) ;
418
420
}
419
421
420
422
shouldClosePopover ( ) {
421
- return this . responsivePopover . opened && ! this . focused && ! this . _itemFocused ;
423
+ return this . responsivePopover . opened && ! this . focused && ! this . _itemFocused && ! this . _isValueStateFocused ;
422
424
}
423
425
424
426
_focusin ( event ) {
@@ -519,6 +521,8 @@ class ComboBox extends UI5Element {
519
521
if ( event . target === this . inner ) {
520
522
// stop the native event, as the semantic "input" would be fired.
521
523
event . stopImmediatePropagation ( ) ;
524
+ this . focused = true ;
525
+ this . _isValueStateFocused = false ;
522
526
}
523
527
524
528
this . _filteredItems = this . _filterItems ( value ) ;
@@ -538,8 +542,6 @@ class ComboBox extends UI5Element {
538
542
} ) ;
539
543
540
544
this . _selectionChanged = false ;
541
-
542
- item . focused = true ;
543
545
}
544
546
}
545
547
@@ -573,40 +575,62 @@ class ComboBox extends UI5Element {
573
575
return ;
574
576
}
575
577
578
+ const isOpen = this . open ;
576
579
const isArrowDown = isDown ( event ) ;
577
580
const isArrowUp = isUp ( event ) ;
578
581
const currentItem = this . _filteredItems . find ( item => {
579
- return this . responsivePopover . opened ? item . focused : item . selected ;
582
+ return isOpen ? item . focused : item . selected ;
580
583
} ) ;
581
- let indexOfItem = this . _filteredItems . indexOf ( currentItem ) ;
584
+ const indexOfItem = this . _filteredItems . indexOf ( currentItem ) ;
582
585
583
586
event . preventDefault ( ) ;
584
587
585
- if ( ( indexOfItem === 0 && isArrowUp ) || ( this . _filteredItems . length - 1 === indexOfItem && isArrowDown ) ) {
588
+ if ( ( this . focused === true && isArrowUp && isOpen ) || ( this . _filteredItems . length - 1 === indexOfItem && isArrowDown ) ) {
586
589
return ;
587
590
}
588
591
589
- this . _clearFocus ( ) ;
592
+ this . _isKeyNavigation = true ;
590
593
591
- indexOfItem += isArrowDown ? 1 : - 1 ;
592
- indexOfItem = indexOfItem < 0 ? 0 : indexOfItem ;
593
- this . _filteredItems [ indexOfItem ] . focused = true ;
594
+ if ( isArrowDown ) {
595
+ this . _handleArrowDown ( event , indexOfItem ) ;
596
+ }
594
597
595
- if ( this . responsivePopover . opened ) {
596
- this . announceSelectedItem ( indexOfItem ) ;
598
+ if ( isArrowUp ) {
599
+ this . _handleArrowUp ( event , indexOfItem ) ;
597
600
}
601
+ }
598
602
599
- this . value = this . _filteredItems [ indexOfItem ] . isGroupItem ? this . filterValue : this . _filteredItems [ indexOfItem ] . text ;
603
+ _handleItemNavigation ( event , indexOfItem , isForward ) {
604
+ const isOpen = this . open ;
605
+ const currentItem = this . _filteredItems [ indexOfItem ] ;
606
+ const nextItem = isForward ? this . _filteredItems [ indexOfItem + 1 ] : this . _filteredItems [ indexOfItem - 1 ] ;
607
+ const isGroupItem = currentItem && currentItem . isGroupItem ;
600
608
601
- this . _isKeyNavigation = true ;
602
- this . _itemFocused = true ;
609
+ if ( ( ! isOpen ) && ( ( isGroupItem && ! nextItem ) || ( ! isGroupItem && ! currentItem ) ) ) {
610
+ return ;
611
+ }
612
+
613
+ this . _clearFocus ( ) ;
614
+
615
+ if ( isOpen ) {
616
+ this . _itemFocused = true ;
617
+ this . value = isGroupItem ? this . filterValue : currentItem . text ;
618
+ this . focused = false ;
619
+ currentItem . focused = true ;
620
+ } else {
621
+ this . focused = true ;
622
+ this . value = isGroupItem ? nextItem . text : currentItem . text ;
623
+ currentItem . focused = false ;
624
+ }
625
+
626
+ this . _isValueStateFocused = false ;
603
627
this . _selectionChanged = true ;
604
628
605
- if ( this . _filteredItems [ indexOfItem ] . isGroupItem ) {
629
+ if ( isGroupItem && isOpen ) {
606
630
return ;
607
631
}
608
632
609
- this . _filteredItems [ indexOfItem ] . selected = true ;
633
+ this . _announceSelectedItem ( indexOfItem ) ;
610
634
611
635
// autocomplete
612
636
const item = this . _autoCompleteValue ( this . value ) ;
@@ -621,6 +645,48 @@ class ComboBox extends UI5Element {
621
645
this . _fireChangeEvent ( ) ;
622
646
}
623
647
648
+ _handleArrowDown ( event , indexOfItem ) {
649
+ const isOpen = this . open ;
650
+
651
+ if ( this . focused && indexOfItem === - 1 && this . hasValueStateText && isOpen ) {
652
+ this . _isValueStateFocused = true ;
653
+ this . focused = false ;
654
+ return ;
655
+ }
656
+
657
+ indexOfItem = ! isOpen && this . hasValueState && indexOfItem === - 1 ? 0 : indexOfItem ;
658
+
659
+ this . _handleItemNavigation ( event , ++ indexOfItem , true /* isForward */ ) ;
660
+ }
661
+
662
+ _handleArrowUp ( event , indexOfItem ) {
663
+ const isOpen = this . open ;
664
+
665
+ if ( indexOfItem === 0 && ! this . hasValueStateText ) {
666
+ this . _clearFocus ( ) ;
667
+ this . focused = true ;
668
+ this . _itemFocused = false ;
669
+ return ;
670
+ }
671
+
672
+ if ( indexOfItem === 0 && this . hasValueStateText && isOpen ) {
673
+ this . _clearFocus ( ) ;
674
+ this . _itemFocused = false ;
675
+ this . _isValueStateFocused = true ;
676
+ this . _filteredItems [ 0 ] . selected = false ;
677
+ return ;
678
+ }
679
+
680
+ if ( this . _isValueStateFocused ) {
681
+ this . focused = true ;
682
+ this . _isValueStateFocused = false ;
683
+ return ;
684
+ }
685
+
686
+ indexOfItem = ! isOpen && this . hasValueState && indexOfItem === - 1 ? 0 : indexOfItem ;
687
+ this . _handleItemNavigation ( event , -- indexOfItem , false /* isForward */ ) ;
688
+ }
689
+
624
690
_keydown ( event ) {
625
691
const isArrowKey = isDown ( event ) || isUp ( event ) ;
626
692
this . _autocomplete = ! ( isBackSpace ( event ) || isDelete ( event ) ) ;
@@ -632,16 +698,32 @@ class ComboBox extends UI5Element {
632
698
if ( isEnter ( event ) ) {
633
699
this . _fireChangeEvent ( ) ;
634
700
this . _closeRespPopover ( ) ;
701
+ this . focused = true ;
635
702
}
636
703
637
- if ( isEscape ( event ) && ! this . open ) {
638
- this . value = this . _lastValue ;
704
+ if ( isEscape ( event ) ) {
705
+ this . focused = true ;
706
+ this . value = ! this . open ? this . _lastValue : this . value ;
707
+ this . _isValueStateFocused = false ;
639
708
}
640
709
641
710
if ( isShow ( event ) && ! this . readonly && ! this . disabled ) {
642
711
event . preventDefault ( ) ;
712
+
643
713
this . _resetFilter ( ) ;
644
714
this . _toggleRespPopover ( ) ;
715
+
716
+ const selectedItem = this . _filteredItems . find ( item => {
717
+ return item . selected ;
718
+ } ) ;
719
+
720
+ if ( selectedItem && this . open ) {
721
+ this . _itemFocused = true ;
722
+ selectedItem . focused = true ;
723
+ this . focused = false ;
724
+ } else {
725
+ this . focused = true ;
726
+ }
645
727
}
646
728
}
647
729
@@ -657,6 +739,9 @@ class ComboBox extends UI5Element {
657
739
this . filterValue = this . _selectedItemText ;
658
740
}
659
741
742
+ this . _isValueStateFocused = false ;
743
+ this . _clearFocus ( ) ;
744
+
660
745
this . responsivePopover . close ( ) ;
661
746
}
662
747
@@ -786,7 +871,7 @@ class ComboBox extends UI5Element {
786
871
this . _itemFocused = true ;
787
872
}
788
873
789
- announceSelectedItem ( indexOfItem ) {
874
+ _announceSelectedItem ( indexOfItem ) {
790
875
const itemPositionText = this . i18nBundle . getText ( LIST_ITEM_POSITION , [ indexOfItem + 1 ] , [ this . _filteredItems . length ] ) ;
791
876
const itemSelectionText = this . i18nBundle . getText ( LIST_ITEM_SELECTED ) ;
792
877
0 commit comments