@@ -56,6 +56,14 @@ function goToLastMonth(container: HTMLElement) {
5656 fireEvent . click ( lastMonthButton ! ) ;
5757}
5858
59+ function goToNextMonth ( container : HTMLElement ) {
60+ const nextMonthButton = safeQuerySelector (
61+ container ,
62+ ".react-datepicker__navigation-icon--next" ,
63+ ) ;
64+ fireEvent . click ( nextMonthButton ! ) ;
65+ }
66+
5967function formatDayWithZeros ( day : number ) {
6068 const dayString = day . toString ( ) ;
6169
@@ -3109,6 +3117,65 @@ describe("DatePicker", () => {
31093117 } ) ;
31103118 } ) ;
31113119
3120+ describe ( "is-selecting-range" , ( ) => {
3121+ const IN_RANGE_DAY_CLASS_NAME = "react-datepicker__day--in-selecting-range" ;
3122+
3123+ it ( "should apply '--in-selecting-range' class to the days till the preselected keyboard date on navigating to the next month without selecting endDate in the endDatePicker" , ( ) => {
3124+ const preselectedDay = 5 ;
3125+ const startDate = new Date ( `2025/02/${ preselectedDay } ` ) ;
3126+
3127+ const { container } = render (
3128+ < DatePicker
3129+ inline
3130+ selectsEnd
3131+ startDate = { startDate }
3132+ minDate = { startDate }
3133+ /> ,
3134+ ) ;
3135+
3136+ goToNextMonth ( container ) ;
3137+
3138+ for ( let i = 1 ; i <= preselectedDay ; i ++ ) {
3139+ const inSelectionRangeDay = safeQuerySelector (
3140+ container ,
3141+ `.react-datepicker__day--00${ i } ` ,
3142+ ) ;
3143+ expect (
3144+ inSelectionRangeDay . classList . contains ( IN_RANGE_DAY_CLASS_NAME ) ,
3145+ ) . toBe ( true ) ;
3146+ }
3147+ } ) ;
3148+
3149+ it ( "should not apply '--in-selecting-range' class to the days till the date that matched selectedDate in the next months (endDatePicker)" , ( ) => {
3150+ const startDay = 3 ;
3151+ const endDay = 8 ;
3152+ const startDate = new Date ( `2025/02/${ startDay } ` ) ;
3153+ const endDate = new Date ( `2025/02/${ endDay } ` ) ;
3154+
3155+ const { container } = render (
3156+ < DatePicker
3157+ inline
3158+ selectsEnd
3159+ startDate = { startDate }
3160+ endDate = { endDate }
3161+ minDate = { startDate }
3162+ /> ,
3163+ ) ;
3164+
3165+ goToNextMonth ( container ) ;
3166+
3167+ for ( let i = 1 ; i <= endDay ; i ++ ) {
3168+ const inSelectionRangeDay = safeQuerySelector (
3169+ container ,
3170+ `.react-datepicker__day--00${ i } ` ,
3171+ ) ;
3172+ expect (
3173+ inSelectionRangeDay . classList . contains ( IN_RANGE_DAY_CLASS_NAME ) ,
3174+ ) . toBe ( false ) ;
3175+ }
3176+ } ) ;
3177+ } ) ;
3178+
31123179 describe ( "selectsRange without inline" , ( ) => {
31133180 it ( "should have preSelection set to startDate upon opening" , ( ) => {
31143181 const startDate = new Date ( "2021-04-20 00:00:00" ) ;
0 commit comments