@@ -3,7 +3,13 @@ import { computed, ComputedRef, Ref } from 'vue';
33import { generateHours , generateMinutes , getCalendarDays } from './util' ;
44
55export const useMontYearPick = ( props : MonthYearPickerProps , emit : VueEmit ) : IMonthYearHook => {
6+ const months = props . months . map ( ( month ) => month . value ) ;
7+ const years = props . years . map ( ( year ) => year . value ) ;
8+ const excludedMonths = months . filter ( ( month ) => ! props . filters . months . some ( ( mon ) => mon === month ) ) ;
9+ const excludedYears = years . filter ( ( year ) => ! props . filters . years . some ( ( yr ) => yr === year ) ) ;
10+
611 const onNext = ( ) : void => {
12+ let tempMonth ;
713 let month = props . month ;
814 let year = props . year ;
915 if ( props . month === 11 ) {
@@ -12,10 +18,29 @@ export const useMontYearPick = (props: MonthYearPickerProps, emit: VueEmit): IMo
1218 } else {
1319 month += 1 ;
1420 }
21+ if ( props . filters . months . includes ( month ) ) {
22+ if ( month === 0 ) {
23+ month = Math . min ( ...excludedMonths ) ;
24+ } else {
25+ month = Math . max ( ...excludedMonths ) ;
26+ }
27+ tempMonth = month ;
28+ }
29+ if ( month === tempMonth ) {
30+ month = Math . min ( ...excludedMonths ) ;
31+ year = props . year + 1 ;
32+ }
33+ if ( props . filters . years . includes ( year ) ) {
34+ const foundYear = excludedYears . find ( ( availableYear ) => availableYear > year ) ;
35+ if ( foundYear ) {
36+ year = foundYear ;
37+ }
38+ }
1539 updateMonthYear ( month , year ) ;
1640 } ;
1741
1842 const onPrev = ( ) : void => {
43+ let tempMonth ;
1944 let month = props . month ;
2045 let year = props . year ;
2146 if ( props . month === 0 ) {
@@ -24,6 +49,24 @@ export const useMontYearPick = (props: MonthYearPickerProps, emit: VueEmit): IMo
2449 } else {
2550 month -= 1 ;
2651 }
52+ if ( props . filters . months . includes ( month ) ) {
53+ if ( month === 11 ) {
54+ month = Math . max ( ...excludedMonths ) ;
55+ } else {
56+ month = Math . min ( ...excludedMonths ) ;
57+ }
58+ tempMonth = month ;
59+ }
60+ if ( month === tempMonth ) {
61+ month = Math . max ( ...excludedMonths ) ;
62+ year = props . year - 1 ;
63+ }
64+ if ( props . filters . years . includes ( year ) ) {
65+ const foundYear = excludedYears . reverse ( ) . find ( ( availableYear ) => availableYear < year ) ;
66+ if ( foundYear ) {
67+ year = foundYear ;
68+ }
69+ }
2770 updateMonthYear ( month , year ) ;
2871 } ;
2972
0 commit comments