@@ -6,7 +6,14 @@ import getEffectiveAriaLabelText from "@ui5/webcomponents-base/dist/util/getEffe
6
6
import "@ui5/webcomponents-icons/dist/icons/slim-arrow-down.js" ;
7
7
import "@ui5/webcomponents-icons/dist/icons/decline.js" ;
8
8
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
9
- import { isBackSpace , isDelete , isShow } from "@ui5/webcomponents-base/dist/Keys.js" ;
9
+ import {
10
+ isBackSpace ,
11
+ isDelete ,
12
+ isShow ,
13
+ isUp ,
14
+ isDown ,
15
+ isEnter ,
16
+ } from "@ui5/webcomponents-base/dist/Keys.js" ;
10
17
import * as Filters from "./ComboBoxFilters.js" ;
11
18
12
19
import {
@@ -324,6 +331,7 @@ class ComboBox extends UI5Element {
324
331
this . _filteredItems = [ ] ;
325
332
this . _initialRendering = true ;
326
333
this . _itemFocused = false ;
334
+ this . _tempFilterValue = "" ;
327
335
this . i18nBundle = getI18nBundle ( "@ui5/webcomponents" ) ;
328
336
}
329
337
@@ -348,7 +356,15 @@ class ComboBox extends UI5Element {
348
356
}
349
357
350
358
this . _selectMatchingItem ( ) ;
359
+
360
+ if ( this . _isKeyNavigation && this . responsivePopover && this . responsivePopover . opened ) {
361
+ this . focused = false ;
362
+ } else {
363
+ this . focused = this === document . activeElement ;
364
+ }
365
+
351
366
this . _initialRendering = false ;
367
+ this . _isKeyNavigation = false ;
352
368
}
353
369
354
370
async onAfterRendering ( ) {
@@ -381,14 +397,19 @@ class ComboBox extends UI5Element {
381
397
382
398
_focusout ( ) {
383
399
this . focused = false ;
400
+
401
+ this . _inputChange ( ) ;
384
402
}
385
403
386
404
_afterOpenPopover ( ) {
387
405
this . _iconPressed = true ;
406
+ this . _clearFocus ( ) ;
388
407
}
389
408
390
409
_afterClosePopover ( ) {
391
410
this . _iconPressed = false ;
411
+ this . _filteredItems = this . items ;
412
+ this . _tempFilterValue = "" ;
392
413
393
414
// close device's keyboard and prevent further typing
394
415
if ( isPhone ( ) ) {
@@ -424,6 +445,8 @@ class ComboBox extends UI5Element {
424
445
event . stopImmediatePropagation ( ) ;
425
446
}
426
447
448
+ this . _clearFocus ( ) ;
449
+ this . _tempFilterValue = value ;
427
450
this . filterValue = value ;
428
451
this . fireEvent ( "input" ) ;
429
452
@@ -440,9 +463,56 @@ class ComboBox extends UI5Element {
440
463
return Filters . StartsWith ( str , this . _filteredItems ) ;
441
464
}
442
465
466
+ _clearFocus ( ) {
467
+ this . _filteredItems . map ( item => {
468
+ item . focused = false ;
469
+
470
+ return item ;
471
+ } ) ;
472
+ }
473
+
474
+ handleArrowKeyPress ( event ) {
475
+ if ( this . readonly || ! this . _filteredItems . length ) {
476
+ return ;
477
+ }
478
+
479
+ const isArrowDown = isDown ( event ) ;
480
+ const isArrowUp = isUp ( event ) ;
481
+ const currentItem = this . _filteredItems . find ( item => {
482
+ return this . responsivePopover . opened ? item . focused : item . selected ;
483
+ } ) ;
484
+ let indexOfItem = this . _filteredItems . indexOf ( currentItem ) ;
485
+
486
+ event . preventDefault ( ) ;
487
+
488
+ if ( ( indexOfItem === 0 && isArrowUp ) || ( this . _filteredItems . length - 1 === indexOfItem && isArrowDown ) ) {
489
+ return ;
490
+ }
491
+
492
+ this . _clearFocus ( ) ;
493
+
494
+ indexOfItem += isArrowDown ? 1 : - 1 ;
495
+ indexOfItem = indexOfItem < 0 ? 0 : indexOfItem ;
496
+
497
+ this . _filteredItems [ indexOfItem ] . focused = true ;
498
+ this . filterValue = this . _filteredItems [ indexOfItem ] . text ;
499
+ this . _isKeyNavigation = true ;
500
+ this . _itemFocused = true ;
501
+ this . fireEvent ( "input" ) ;
502
+ }
503
+
443
504
_keydown ( event ) {
505
+ const isArrowKey = isDown ( event ) || isUp ( event ) ;
444
506
this . _autocomplete = ! ( isBackSpace ( event ) || isDelete ( event ) ) ;
445
507
508
+ if ( isArrowKey ) {
509
+ this . handleArrowKeyPress ( event ) ;
510
+ }
511
+
512
+ if ( isEnter ( event ) ) {
513
+ this . _inputChange ( ) ;
514
+ }
515
+
446
516
if ( isShow ( event ) && ! this . readonly && ! this . disabled ) {
447
517
event . preventDefault ( ) ;
448
518
this . _resetFilter ( ) ;
@@ -472,16 +542,21 @@ class ComboBox extends UI5Element {
472
542
_autoCompleteValue ( current ) {
473
543
const currentValue = current ;
474
544
const matchingItems = this . _startsWithMatchingItems ( currentValue ) ;
545
+ const selectionValue = this . _tempFilterValue ? this . _tempFilterValue : currentValue ;
475
546
476
547
if ( matchingItems . length ) {
477
548
this . _tempValue = matchingItems [ 0 ] ? matchingItems [ 0 ] . text : current ;
478
549
} else {
479
550
this . _tempValue = current ;
480
551
}
481
552
482
- if ( matchingItems . length && ( currentValue !== this . _tempValue ) ) {
553
+ if ( matchingItems . length && ( selectionValue !== this . _tempValue ) ) {
554
+ setTimeout ( ( ) => {
555
+ this . inner . setSelectionRange ( selectionValue . length , this . _tempValue . length ) ;
556
+ } , 0 ) ;
557
+ } else if ( this . _isKeyNavigation ) {
483
558
setTimeout ( ( ) => {
484
- this . inner . setSelectionRange ( currentValue . length , this . _tempValue . length ) ;
559
+ this . inner . setSelectionRange ( 0 , this . _tempValue . length ) ;
485
560
} , 0 ) ;
486
561
}
487
562
}
@@ -504,6 +579,10 @@ class ComboBox extends UI5Element {
504
579
this . _closeRespPopover ( ) ;
505
580
}
506
581
582
+ _itemMousedown ( event ) {
583
+ event . preventDefault ( ) ;
584
+ }
585
+
507
586
_selectItem ( event ) {
508
587
const listItem = event . detail . item ;
509
588
@@ -569,6 +648,10 @@ class ComboBox extends UI5Element {
569
648
return this . responsivePopover ? this . responsivePopover . opened : false ;
570
649
}
571
650
651
+ get itemTabIndex ( ) {
652
+ return undefined ;
653
+ }
654
+
572
655
get ariaLabelText ( ) {
573
656
return getEffectiveAriaLabelText ( this ) ;
574
657
}
0 commit comments