@@ -46,10 +46,18 @@ export const useDatePicker = (
46
46
) => {
47
47
const tempRange = ref < Date [ ] > ( [ ] ) ;
48
48
const lastScrollTime = ref ( new Date ( ) ) ;
49
+ const clickedDate = ref < ICalendarDay | undefined > ( ) ;
49
50
50
51
const { modelValue, calendars, time } = useModel ( props , emit ) ;
51
- const { defaultedMultiCalendars, defaultedStartTime, defaultedRange, defaultedTz, propDates, defaultedMultiDates } =
52
- useDefaults ( props ) ;
52
+ const {
53
+ defaultedMultiCalendars,
54
+ defaultedStartTime,
55
+ defaultedRange,
56
+ defaultedConfig,
57
+ defaultedTz,
58
+ propDates,
59
+ defaultedMultiDates,
60
+ } = useDefaults ( props ) ;
53
61
const { validateMonthYearInRange, isDisabled, isDateRangeAllowed, checkMinMaxRange } = useValidation ( props ) ;
54
62
const { updateTimeValues, getSetDateTime, setTime, assignStartTime, validateTime, disabledTimesConfig } =
55
63
useTimePickerUtils ( props , time , modelValue , updateFlow ) ;
@@ -67,13 +75,25 @@ export const useDatePicker = (
67
75
calendars . value [ instance ] ? calendars . value [ instance ] . year : 0 ,
68
76
) ;
69
77
78
+ const shouldUpdateMonthView = ( isAction : boolean ) => {
79
+ if ( ! defaultedConfig . value . keepViewOnOffsetClick || isAction ) return true ;
80
+ return ! clickedDate . value ;
81
+ } ;
82
+
70
83
// Any update for month or year value will go through this function
71
- const setCalendarMonthYear = ( instance : number , month : number | null , year : number | null ) : void => {
72
- if ( ! calendars . value [ instance ] ) {
73
- calendars . value [ instance ] = { month : 0 , year : 0 } ;
84
+ const setCalendarMonthYear = (
85
+ instance : number ,
86
+ month : number | null ,
87
+ year : number | null ,
88
+ isAction : boolean = false ,
89
+ ) : void => {
90
+ if ( shouldUpdateMonthView ( isAction ) ) {
91
+ if ( ! calendars . value [ instance ] ) {
92
+ calendars . value [ instance ] = { month : 0 , year : 0 } ;
93
+ }
94
+ calendars . value [ instance ] . month = isNumNullish ( month ) ? calendars . value [ instance ] ?. month : month ;
95
+ calendars . value [ instance ] . year = isNumNullish ( year ) ? calendars . value [ instance ] ?. year : year ;
74
96
}
75
- calendars . value [ instance ] . month = isNumNullish ( month ) ? calendars . value [ instance ] ?. month : month ;
76
- calendars . value [ instance ] . year = isNumNullish ( year ) ? calendars . value [ instance ] ?. year : year ;
77
97
} ;
78
98
79
99
const selectOnAutoApply = ( ) => {
@@ -552,6 +572,7 @@ export const useDatePicker = (
552
572
*/
553
573
const selectDate = ( day : ICalendarDay , isNext = false ) : void => {
554
574
if ( isDisabled ( day . value ) || ( ! day . current && props . hideOffsetDates ) ) return emit ( 'invalid-date' , day . value ) ;
575
+ clickedDate . value = JSON . parse ( JSON . stringify ( day ) ) ;
555
576
556
577
if ( ! defaultedRange . value . enabled ) return handleSingleDateSelect ( day ) ;
557
578
@@ -563,7 +584,7 @@ export const useDatePicker = (
563
584
564
585
// Handles selection of month/year
565
586
const updateMonthYear = ( instance : number , val : { month : number ; year : number ; fromNav ?: boolean } ) : void => {
566
- setCalendarMonthYear ( instance , val . month , val . year ) ;
587
+ setCalendarMonthYear ( instance , val . month , val . year , true ) ;
567
588
568
589
if ( defaultedMultiCalendars . value . count && ! defaultedMultiCalendars . value . solo ) {
569
590
autoChangeMultiCalendars ( instance ) ;
0 commit comments