diff --git a/src/MonthCalendar.jsx b/src/MonthCalendar.jsx index 7f4c7eeb..b8bb7a79 100644 --- a/src/MonthCalendar.jsx +++ b/src/MonthCalendar.jsx @@ -83,6 +83,26 @@ class MonthCalendar extends React.Component { } } + previousYear = () => { + const stateValue = this.state.value; + const value = stateValue.clone(); + value.add(-1, 'years'); + + if (value !== stateValue) { + this.setValue(value); + } + } + + nextYear = () => { + const stateValue = this.state.value; + const value = stateValue.clone(); + value.add(1, 'years'); + + if (value !== stateValue) { + this.setValue(value); + } + } + handlePanelChange = (_, mode) => { if (mode !== 'date') { this.setState({ mode }); @@ -106,6 +126,8 @@ class MonthCalendar extends React.Component { onMonthSelect={this.onSelect} onValueChange={this.setValue} onPanelChange={this.handlePanelChange} + previousYear={this.previousYear} + nextYear={this.nextYear} /> this.showYearPanel('month')} @@ -161,6 +163,8 @@ export default class CalendarHeader extends React.Component { cellRender={props.monthCellRender} contentRender={props.monthCellContentRender} renderFooter={renderFooter} + previousYear={previousYear} + nextYear={nextYear} /> ); } diff --git a/src/month/MonthPanel.jsx b/src/month/MonthPanel.jsx index 875db412..c8de95b5 100644 --- a/src/month/MonthPanel.jsx +++ b/src/month/MonthPanel.jsx @@ -74,7 +74,7 @@ class MonthPanel extends React.Component { render() { const props = this.props; const value = this.state.value; - const { locale, cellRender, contentRender, renderFooter } = props; + const { locale, cellRender, contentRender, renderFooter, previousYear, nextYear } = props; const year = value.year(); const prefixCls = this.prefixCls; @@ -87,7 +87,7 @@ class MonthPanel extends React.Component { @@ -104,7 +104,7 @@ class MonthPanel extends React.Component {