11import { For , createEffect , createMemo , createSignal } from "solid-js" ;
22import { Divider , Grid , Paper } from "@suid/material" ;
33import { extractCommonCalendarProps } from "./MonthCalendar" ;
4- import { CommonCalendarProps , DateRange } from "./models" ;
5- import { addMonths , getToday } from "./dateUtils" ;
4+ import { CommonCalendarProps , DateRange , Optional } from "./models" ;
5+ import { addMonths , getToday , isSameDay } from "./dateUtils" ;
66import DateRangeMonthCalendar from "./DateRangeMonthCalendar" ;
77
88type CalendarCount = 1 | 2 | 3 ;
@@ -26,9 +26,18 @@ export default function DateRangeCalendar(props: DateRangeCalendarProps) {
2626
2727 const calendarCount = createMemo ( ( ) => props . calendars || 2 ) ;
2828
29- createEffect ( ( ) => {
29+ createEffect ( ( prevStartDate : Optional < Date > ) => {
3030 setRange ( props . value ) ;
31- } ) ;
31+
32+ const startDate = props . value [ 0 ] ;
33+
34+ // When the start date changes, update the calendar date.
35+ if ( prevStartDate && startDate && ! isSameDay ( prevStartDate , startDate ) ) {
36+ setCalendarDate ( startDate ) ;
37+ }
38+
39+ return startDate ;
40+ } , props . value [ 0 ] ) ;
3241
3342 const calendarDates = createMemo ( ( ) =>
3443 Array . from ( { length : calendarCount ( ) } , ( _ , i ) => addMonths ( calendarDate ( ) , i ) ) ,
0 commit comments