@@ -324,10 +324,6 @@ class Select extends UI5Element {
324
324
if ( ! this . _listWidth ) {
325
325
this . _listWidth = this . responsivePopover . offsetWidth ;
326
326
}
327
- if ( this . responsivePopover . querySelector ( "[ui5-li][focused]:not([selected])" ) ) {
328
- // selection changed programmatically => apply focus to the newly selected item
329
- this . _applyFocusAfterOpen ( ) ;
330
- }
331
327
}
332
328
}
333
329
@@ -385,9 +381,11 @@ class Select extends UI5Element {
385
381
}
386
382
387
383
opt . selected = false ;
384
+ opt . _focused = false ;
388
385
389
386
return {
390
387
selected : false ,
388
+ _focused : false ,
391
389
disabled : opt . disabled ,
392
390
icon : opt . icon ,
393
391
value : opt . value ,
@@ -399,15 +397,19 @@ class Select extends UI5Element {
399
397
400
398
if ( lastSelectedOptionIndex > - 1 && ! opts [ lastSelectedOptionIndex ] . disabled ) {
401
399
opts [ lastSelectedOptionIndex ] . selected = true ;
400
+ opts [ lastSelectedOptionIndex ] . _focused = true ;
402
401
this . options [ lastSelectedOptionIndex ] . selected = true ;
402
+ this . options [ lastSelectedOptionIndex ] . _focused = true ;
403
403
this . _text = opts [ lastSelectedOptionIndex ] . textContent ;
404
404
this . _selectedIndex = lastSelectedOptionIndex ;
405
405
} else {
406
406
this . _text = "" ;
407
407
this . _selectedIndex = - 1 ;
408
408
if ( opts [ firstEnabledOptionIndex ] ) {
409
409
opts [ firstEnabledOptionIndex ] . selected = true ;
410
+ opts [ firstEnabledOptionIndex ] . _focused = true ;
410
411
this . options [ firstEnabledOptionIndex ] . selected = true ;
412
+ this . options [ firstEnabledOptionIndex ] . _focused = true ;
411
413
this . _selectedIndex = firstEnabledOptionIndex ;
412
414
this . _text = this . options [ firstEnabledOptionIndex ] . textContent ;
413
415
}
@@ -444,14 +446,24 @@ class Select extends UI5Element {
444
446
event . preventDefault ( ) ;
445
447
}
446
448
447
- if ( ! this . _isPickerOpen ) {
448
- this . _handleArrowNavigation ( event , true ) ;
449
+ if ( isEscape ( event ) && this . _isPickerOpen ) {
450
+ this . _escapePressed = true ;
451
+ }
452
+
453
+ if ( isEnter ( event ) ) {
454
+ this . _handleSelectionChange ( ) ;
449
455
}
456
+
457
+ this . _handleArrowNavigation ( event , true ) ;
450
458
}
451
459
452
460
_onkeyup ( event ) {
453
- if ( isSpace ( event ) && ! this . _isPickerOpen ) {
454
- this . _toggleRespPopover ( ) ;
461
+ if ( isSpace ( event ) ) {
462
+ if ( this . _isPickerOpen ) {
463
+ this . _handleSelectionChange ( ) ;
464
+ } else {
465
+ this . _toggleRespPopover ( ) ;
466
+ }
455
467
}
456
468
}
457
469
@@ -472,9 +484,13 @@ class Select extends UI5Element {
472
484
_handleItemPress ( event ) {
473
485
const item = event . detail . item ;
474
486
const selectedItemIndex = this . _getSelectedItemIndex ( item ) ;
475
- this . _select ( selectedItemIndex ) ;
476
487
477
- this . _toggleRespPopover ( ) ;
488
+ this . _handleSelectionChange ( selectedItemIndex ) ;
489
+ }
490
+
491
+ _itemMousedown ( event ) {
492
+ // prevent actual focus of items
493
+ event . preventDefault ( ) ;
478
494
}
479
495
480
496
_onclick ( event ) {
@@ -483,36 +499,13 @@ class Select extends UI5Element {
483
499
}
484
500
485
501
/**
486
- * The user used arrow up/down on the list
502
+ * The user selected an item with Enter or Space
487
503
* @private
488
504
*/
489
- _handleSelectionChange ( event ) {
490
- const item = event . detail . selectedItems [ 0 ] ;
491
- const selectedItemIndex = this . _getSelectedItemIndex ( item ) ;
492
- this . _select ( selectedItemIndex ) ;
493
- }
505
+ _handleSelectionChange ( index = this . _selectedIndex ) {
506
+ this . _select ( index ) ;
494
507
495
- _applyFocusAfterOpen ( ) {
496
- if ( ! this . _currentlySelectedOption ) {
497
- return ;
498
- }
499
-
500
- const li = this . responsivePopover . querySelector ( `#${ this . _currentlySelectedOption . _id } -li` ) ;
501
- if ( ! li ) {
502
- return ;
503
- }
504
-
505
- this . responsivePopover . querySelector ( "[ui5-list]" ) . focusItem ( li ) ;
506
- }
507
-
508
- _handlePickerKeydown ( event ) {
509
- if ( isEscape ( event ) && this . _isPickerOpen ) {
510
- this . _escapePressed = true ;
511
- }
512
-
513
- if ( isEnter ( event ) || isSpace ( event ) ) {
514
- this . _shouldClosePopover = true ;
515
- }
508
+ this . _toggleRespPopover ( ) ;
516
509
}
517
510
518
511
_handleArrowNavigation ( event , shouldFireEvent ) {
@@ -530,14 +523,22 @@ class Select extends UI5Element {
530
523
}
531
524
532
525
this . options [ this . _selectedIndex ] . selected = false ;
526
+ this . options [ this . _selectedIndex ] . _focused = false ;
527
+
533
528
this . options [ nextIndex ] . selected = true ;
529
+ this . options [ nextIndex ] . _focused = true ;
530
+
534
531
this . _selectedIndex = nextIndex === - 1 ? this . _selectedIndex : nextIndex ;
535
532
536
533
if ( currentIndex !== this . _selectedIndex ) {
534
+ // Announce new item even if picker is opened.
535
+ // The aria-activedescendents attribute can't be used,
536
+ // because listitem elements are in different shadow dom
537
537
this . itemSelectionAnnounce ( ) ;
538
538
}
539
539
540
- if ( shouldFireEvent ) {
540
+ if ( shouldFireEvent && ! this . _isPickerOpen ) {
541
+ // arrow pressed on closed picker - do selection change
541
542
this . _fireChangeEvent ( this . options [ nextIndex ] ) ;
542
543
}
543
544
}
@@ -556,7 +557,12 @@ class Select extends UI5Element {
556
557
this . _lastSelectedOption = this . options [ this . _selectedIndex ] ;
557
558
}
558
559
560
+ _afterOpen ( ) {
561
+ this . opened = true ;
562
+ }
563
+
559
564
_afterClose ( ) {
565
+ this . opened = false ;
560
566
this . _iconPressed = false ;
561
567
this . _listWidth = 0 ;
562
568
@@ -674,7 +680,7 @@ class Select extends UI5Element {
674
680
itemSelectionAnnounce ( ) {
675
681
const invisibleText = this . shadowRoot . querySelector ( `#${ this . _id } -selectionText` ) ;
676
682
677
- if ( this . focused && ! this . _isPickerOpen && this . _currentlySelectedOption ) {
683
+ if ( this . focused && this . _currentlySelectedOption ) {
678
684
invisibleText . textContent = this . _currentlySelectedOption . textContent ;
679
685
} else {
680
686
invisibleText . textContent = "" ;
0 commit comments