@@ -33,20 +33,22 @@ export function DatePickerWithRange({
3333} : React . HTMLAttributes < HTMLDivElement > & DatePickerWithRangeProps ) {
3434 function handleDayClick ( date : Date ) {
3535 if ( ! dates . startDate ) {
36- // If no start date set it as both start and end date
36+ // If no start date, set it as both start and end date
3737 onDatesChange ( { startDate : date , endDate : date } ) ;
38- } else if ( ! dates . endDate ) {
38+ } else if ( dates . startDate && ! dates . endDate ) {
3939 const startDate = date < dates . startDate ? date : dates . startDate ;
4040 const endDate = date < dates . startDate ? dates . startDate : date ;
4141 onDatesChange ( { startDate, endDate } ) ;
42- } else {
42+ } else if ( dates . startDate && dates . endDate ) {
4343 // If both dates exist
44- if ( date . getTime ( ) === dates . startDate . getTime ( ) && dates . endDate ) {
44+ if ( date . getTime ( ) === dates . startDate . getTime ( ) ) {
4545 onDatesChange ( { startDate : date , endDate : date } ) ;
46- } else if ( date <= dates . endDate ) {
47- onDatesChange ( { startDate : date , endDate : dates . endDate } ) ;
48- } else {
46+ } else if ( date . getTime ( ) === dates . endDate ?. getTime ( ) ) {
4947 onDatesChange ( { startDate : date , endDate : date } ) ;
48+ } else if ( date < dates . startDate ) {
49+ onDatesChange ( { startDate : date , endDate : dates . endDate } ) ;
50+ } else if ( date > dates . startDate ) {
51+ onDatesChange ( { startDate : dates . startDate , endDate : date } ) ;
5052 }
5153 }
5254 }
0 commit comments