@@ -8,7 +8,12 @@ import {
88import { spy } from 'sinon' ;
99import IgcCalendarComponent from '../calendar/calendar.js' ;
1010import { CalendarDay } from '../calendar/model.js' ;
11- import { escapeKey } from '../common/controllers/key-bindings.js' ;
11+ import {
12+ altKey ,
13+ arrowDown ,
14+ arrowUp ,
15+ escapeKey ,
16+ } from '../common/controllers/key-bindings.js' ;
1217import { defineComponents } from '../common/definitions/defineComponents.js' ;
1318import {
1419 isFocused ,
@@ -134,7 +139,7 @@ describe('Date range picker - single input', () => {
134139 await elementUpdated ( picker ) ;
135140
136141 input . focus ( ) ;
137- simulateKeyboard ( input , 'ArrowDown' ) ;
142+ simulateKeyboard ( input , arrowDown ) ;
138143 await elementUpdated ( picker ) ;
139144
140145 expect ( isFocused ( input ) ) . to . be . true ;
@@ -588,6 +593,47 @@ describe('Date range picker - single input', () => {
588593 expect ( picker . value ) . to . deep . equal ( null ) ;
589594 expect ( input . value ) . to . equal ( '' ) ;
590595 } ) ;
596+
597+ it ( 'should toggle the calendar with keyboard combinations and keep focus' , async ( ) => {
598+ const eventSpy = spy ( picker , 'emitEvent' ) ;
599+ const input = picker . renderRoot ! . querySelector (
600+ IgcInputComponent . tagName
601+ ) ! ;
602+ input . focus ( ) ;
603+
604+ expect ( isFocused ( input ) ) . to . be . true ;
605+
606+ simulateKeyboard ( input , [ altKey , arrowDown ] ) ;
607+ await elementUpdated ( picker ) ;
608+
609+ expect ( picker . open ) . to . be . true ;
610+ expect ( isFocused ( input ) ) . to . be . false ;
611+ expect ( eventSpy . firstCall ) . calledWith ( 'igcOpening' ) ;
612+ expect ( eventSpy . lastCall ) . calledWith ( 'igcOpened' ) ;
613+ eventSpy . resetHistory ( ) ;
614+
615+ simulateKeyboard ( input , [ altKey , arrowUp ] ) ;
616+ await elementUpdated ( picker ) ;
617+
618+ expect ( picker . open ) . to . be . false ;
619+ expect ( isFocused ( input ) ) . to . be . true ;
620+ expect ( eventSpy . firstCall ) . calledWith ( 'igcClosing' ) ;
621+ expect ( eventSpy . lastCall ) . calledWith ( 'igcClosed' ) ;
622+ eventSpy . resetHistory ( ) ;
623+
624+ simulateKeyboard ( input , [ altKey , arrowDown ] ) ;
625+ await elementUpdated ( picker ) ;
626+ eventSpy . resetHistory ( ) ;
627+
628+ simulateKeyboard ( picker , escapeKey ) ;
629+ await elementUpdated ( picker ) ;
630+ await elementUpdated ( input ) ;
631+
632+ expect ( picker . open ) . to . be . false ;
633+ expect ( isFocused ( input ) ) . to . be . true ;
634+ expect ( eventSpy . firstCall ) . calledWith ( 'igcClosing' ) ;
635+ expect ( eventSpy . lastCall ) . calledWith ( 'igcClosed' ) ;
636+ } ) ;
591637 } ) ;
592638
593639 describe ( 'Readonly state' , ( ) => {
0 commit comments