@@ -12,23 +12,28 @@ export default class DateTimePickerMonths extends Component {
1212 showYears : PropTypes . func . isRequired ,
1313 setViewMonth : PropTypes . func . isRequired ,
1414 setSelectedMonth : PropTypes . func . isRequired ,
15+ minDate : PropTypes . object ,
16+ maxDate : PropTypes . object ,
1517 mode : PropTypes . oneOf ( [ Constants . MODE_DATE , Constants . MODE_MONTH , Constants . MODE_DATETIME ] )
1618 }
1719
1820 renderMonths = ( ) => {
19- var classes , i , month , months , monthsShort ;
21+ var classes , month , months , monthsShort , minDate , maxDate , currentMonth ;
2022 const onClick = this . props . mode === Constants . MODE_MONTH ? this . props . setSelectedMonth : this . props . setViewMonth ;
2123 month = this . props . selectedDate . month ( ) ;
2224 monthsShort = moment . monthsShort ( ) ;
23- i = 0 ;
25+ minDate = this . props . minDate ? this . props . minDate . clone ( ) . subtract ( 1 , "months" ) : this . props . minDate ;
26+ maxDate = this . props . maxDate ? this . props . maxDate . clone ( ) : this . props . maxDate ;
2427 months = [ ] ;
25- while ( i < 12 ) {
28+ currentMonth = moment ( [ this . props . viewDate . year ( ) , 0 , 1 ] ) ;
29+ for ( let i = 0 ; i < 12 ; i ++ ) {
2630 classes = {
2731 month : true ,
28- "active" : i === month && this . props . viewDate . year ( ) === this . props . selectedDate . year ( )
32+ "active" : i === month && this . props . viewDate . year ( ) === this . props . selectedDate . year ( ) ,
33+ disabled : ( minDate && currentMonth . isBefore ( minDate ) ) || ( maxDate && currentMonth . isAfter ( maxDate ) )
2934 } ;
3035 months . push ( < span className = { classnames ( classes ) } key = { i } onClick = { onClick } > { monthsShort [ i ] } </ span > ) ;
31- i ++ ;
36+ currentMonth . add ( 1 , "months" ) ;
3237 }
3338 return months ;
3439 }
0 commit comments