@@ -7,8 +7,10 @@ import {
77 arrowUp ,
88 endKey ,
99 enterKey ,
10+ escapeKey ,
1011 homeKey ,
1112 spaceBar ,
13+ tabKey ,
1214} from '../common/controllers/key-bindings.js' ;
1315import { defineComponents } from '../common/definitions/defineComponents.js' ;
1416import { first } from '../common/util.js' ;
@@ -716,6 +718,48 @@ describe('Combo', () => {
716718 expect ( combo . open ) . to . be . true ;
717719 } ) ;
718720
721+ it ( 'should close the menu by pressing the Tab key' , async ( ) => {
722+ await combo . show ( ) ;
723+ await list . layoutComplete ;
724+
725+ simulateKeyboard ( options , tabKey , 1 ) ;
726+ await elementUpdated ( combo ) ;
727+ expect ( combo . open ) . to . be . false ;
728+
729+ await combo . show ( ) ;
730+ simulateKeyboard ( searchInput , tabKey , 1 ) ;
731+ await elementUpdated ( combo ) ;
732+
733+ expect ( combo . open ) . to . be . false ;
734+
735+ await combo . show ( ) ;
736+ simulateKeyboard ( input , tabKey , 1 ) ;
737+ await elementUpdated ( combo ) ;
738+
739+ expect ( combo . open ) . to . be . false ;
740+ } ) ;
741+
742+ it ( 'should clear the selection by pressing the Escape key when the combo is closed' , async ( ) => {
743+ combo . autofocusList = true ;
744+ combo . select ( [ 'BG01' , 'BG02' ] ) ;
745+ await elementUpdated ( combo ) ;
746+
747+ await combo . show ( ) ;
748+ await list . layoutComplete ;
749+
750+ simulateKeyboard ( options , escapeKey , 1 ) ;
751+ await elementUpdated ( combo ) ;
752+
753+ expect ( combo . open ) . to . be . false ;
754+ expect ( combo . value . length ) . to . equal ( 2 ) ;
755+
756+ simulateKeyboard ( input , escapeKey , 1 ) ;
757+ await elementUpdated ( combo ) ;
758+
759+ expect ( combo . open ) . to . be . false ;
760+ expect ( combo . value . length ) . to . equal ( 0 ) ;
761+ } ) ;
762+
719763 it ( 'should select the active item and close the menu by pressing Enter in single selection' , async ( ) => {
720764 combo . singleSelect = true ;
721765 await elementUpdated ( combo ) ;
@@ -750,6 +794,43 @@ describe('Combo', () => {
750794 expect ( combo . open ) . to . be . false ;
751795 } ) ;
752796
797+ it ( 'should close the menu by pressing the Tab key in single selection' , async ( ) => {
798+ await combo . show ( ) ;
799+ await list . layoutComplete ;
800+
801+ simulateKeyboard ( options , tabKey , 1 ) ;
802+ await elementUpdated ( combo ) ;
803+
804+ expect ( combo . open ) . to . be . false ;
805+
806+ await combo . show ( ) ;
807+ simulateKeyboard ( input , tabKey , 1 ) ;
808+ await elementUpdated ( combo ) ;
809+
810+ expect ( combo . open ) . to . be . false ;
811+ } ) ;
812+
813+ it ( 'should clear the selection by pressing the Escape key in single selection' , async ( ) => {
814+ combo . singleSelect = true ;
815+ combo . select ( 'BG01' ) ;
816+ await elementUpdated ( combo ) ;
817+
818+ await combo . show ( ) ;
819+ await list . layoutComplete ;
820+
821+ simulateKeyboard ( options , escapeKey , 1 ) ;
822+ await elementUpdated ( combo ) ;
823+
824+ expect ( combo . open ) . to . be . false ;
825+ expect ( combo . value . length ) . to . equal ( 1 ) ;
826+
827+ simulateKeyboard ( input , escapeKey , 1 ) ;
828+ await elementUpdated ( combo ) ;
829+
830+ expect ( combo . open ) . to . be . false ;
831+ expect ( combo . value . length ) . to . equal ( 0 ) ;
832+ } ) ;
833+
753834 it ( 'should support a single selection variant' , async ( ) => {
754835 combo . singleSelect = true ;
755836 await elementUpdated ( combo ) ;
0 commit comments