@@ -16,6 +16,7 @@ import { defineComponents } from '../common/definitions/defineComponents.js';
1616import { first } from '../common/util.js' ;
1717import {
1818 createFormAssociatedTestBed ,
19+ isFocused ,
1920 simulateClick ,
2021 simulateKeyboard ,
2122} from '../common/utils.spec.js' ;
@@ -187,16 +188,16 @@ describe('Combo', () => {
187188 > </ igc-combo > `
188189 ) ;
189190
190- options = combo . shadowRoot ! . querySelector (
191+ options = combo . renderRoot . querySelector (
191192 '[part="list"]'
192193 ) as IgcComboListComponent ;
193- input = combo . shadowRoot ! . querySelector (
194+ input = combo . renderRoot . querySelector (
194195 'igc-input#target'
195196 ) as IgcInputComponent ;
196- searchInput = combo . shadowRoot ! . querySelector (
197+ searchInput = combo . renderRoot . querySelector (
197198 '[part="search-input"]'
198199 ) as IgcInputComponent ;
199- list = combo . shadowRoot ! . querySelector (
200+ list = combo . renderRoot . querySelector (
200201 'igc-combo-list'
201202 ) as IgcComboListComponent ;
202203 } ) ;
@@ -697,8 +698,8 @@ describe('Combo', () => {
697698 simulateKeyboard ( options , endKey ) ;
698699 await elementUpdated ( combo ) ;
699700
700- const itms = items ( combo ) ;
701- expect ( itms [ itms . length - 1 ] . active ) . to . be . true ;
701+ const _items = items ( combo ) ;
702+ expect ( _items [ _items . length - 1 ] . active ) . to . be . true ;
702703 } ) ;
703704
704705 it ( 'should select the active item by pressing the Space key' , async ( ) => {
@@ -712,12 +713,72 @@ describe('Combo', () => {
712713 simulateKeyboard ( options , spaceBar ) ;
713714 await elementUpdated ( combo ) ;
714715
715- const itms = items ( combo ) ;
716- expect ( itms [ 1 ] . active ) . to . be . true ;
717- expect ( itms [ 1 ] . selected ) . to . be . true ;
716+ const _items = items ( combo ) ;
717+ expect ( _items [ 1 ] . active ) . to . be . true ;
718+ expect ( _items [ 1 ] . selected ) . to . be . true ;
718719 expect ( combo . open ) . to . be . true ;
719720 } ) ;
720721
722+ it ( 'should move focus to the filter input and the close the dropdown on subsequent Arrow Up keypress' , async ( ) => {
723+ await combo . show ( ) ;
724+ await list . layoutComplete ;
725+
726+ // Move active state to first item and focus to the dropdown
727+ simulateKeyboard ( searchInput , arrowDown ) ;
728+ await elementUpdated ( combo ) ;
729+
730+ expect ( isFocused ( list ) ) . to . be . true ;
731+ expect ( isFocused ( searchInput ) ) . to . be . false ;
732+
733+ // Move focus to the search input
734+ simulateKeyboard ( list , arrowUp ) ;
735+ await elementUpdated ( combo ) ;
736+
737+ expect ( isFocused ( list ) ) . to . be . false ;
738+ expect ( isFocused ( searchInput ) ) . to . be . true ;
739+
740+ simulateKeyboard ( searchInput , arrowUp ) ;
741+ await elementUpdated ( combo ) ;
742+
743+ expect ( combo . open ) . to . be . false ;
744+ } ) ;
745+
746+ it ( 'should close the dropdown on Arrow Up when disable-filtering is set' , async ( ) => {
747+ combo . disableFiltering = true ;
748+ await elementUpdated ( combo ) ;
749+
750+ await combo . show ( ) ;
751+ await list . layoutComplete ;
752+
753+ // Activate first item
754+ simulateKeyboard ( list , arrowDown ) ;
755+ await elementUpdated ( combo ) ;
756+
757+ expect ( isFocused ( list ) ) . to . be . true ;
758+
759+ simulateKeyboard ( list , arrowUp ) ;
760+ await elementUpdated ( combo ) ;
761+
762+ expect ( combo . open ) . to . be . false ;
763+ } ) ;
764+
765+ it ( 'should close the dropdown on Arrow Up in single-select mode' , async ( ) => {
766+ combo . singleSelect = true ;
767+ await elementUpdated ( combo ) ;
768+
769+ await combo . show ( ) ;
770+ await list . layoutComplete ;
771+
772+ // Activate first item
773+ simulateKeyboard ( list , arrowDown ) ;
774+ await elementUpdated ( combo ) ;
775+
776+ simulateKeyboard ( list , arrowUp ) ;
777+ await elementUpdated ( combo ) ;
778+
779+ expect ( combo . open ) . to . be . false ;
780+ } ) ;
781+
721782 it ( 'should close the menu by pressing the Tab key' , async ( ) => {
722783 await combo . show ( ) ;
723784 await list . layoutComplete ;
@@ -1221,7 +1282,7 @@ describe('Combo', () => {
12211282 } ) ;
12221283 } ) ;
12231284
1224- it ( 'should be able to get the currently selected items by calling the `selectoin ` getter' , async ( ) => {
1285+ it ( 'should be able to get the currently selected items by calling the `selection ` getter' , async ( ) => {
12251286 combo . select ( [ cities [ 0 ] . id , cities [ 1 ] . id , cities [ 2 ] . id ] ) ;
12261287 await elementUpdated ( combo ) ;
12271288
0 commit comments