@@ -580,7 +580,24 @@ describe("DatePicker", () => {
580580 } ) ;
581581 } ) ;
582582
583- it ( "should hide the calendar when the pressing Shift + Tab in the date input" , ( ) => {
583+ it ( "should auto-close the datepicker and lose focus when Tab key is pressed when the date input is focused" , async ( ) => {
584+ const { container } = render ( < DatePicker /> ) ;
585+ const input = safeQuerySelector ( container , "input" ) ;
586+ fireEvent . focus ( input ) ;
587+
588+ let reactCalendar = container . querySelector ( "div.react-datepicker" ) ;
589+ expect ( reactCalendar ) . not . toBeNull ( ) ;
590+
591+ fireEvent . keyDown ( input , getKey ( KeyType . Tab ) ) ;
592+
593+ reactCalendar = container . querySelector ( "div.react-datepicker" ) ;
594+ expect ( reactCalendar ) . toBeNull ( ) ;
595+ await waitFor ( ( ) => {
596+ expect ( document . activeElement ) . not . toBe ( input ) ;
597+ } ) ;
598+ } ) ;
599+
600+ it ( "should hide the calendar when the pressing Shift + Tab in the date input" , async ( ) => {
584601 // eslint-disable-next-line prefer-const
585602 let onBlurSpy : ReturnType < typeof jest . spyOn > ;
586603 const onBlur : React . FocusEventHandler < HTMLElement > = (
@@ -594,7 +611,9 @@ describe("DatePicker", () => {
594611 fireEvent . focus ( input ) ;
595612 fireEvent . keyDown ( input , getKey ( KeyType . Tab , true ) ) ;
596613 expect ( container . querySelector ( ".react-datepicker" ) ) . toBeNull ( ) ;
597- expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
614+ await waitFor ( ( ) => {
615+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
616+ } ) ;
598617 } ) ;
599618
600619 it ( "should not apply the react-datepicker-ignore-onclickoutside class to the date input when closed" , ( ) => {
0 commit comments