Skip to content

Commit

Permalink
monthCalendar按键事件
Browse files Browse the repository at this point in the history
  • Loading branch information
502218 committed Mar 13, 2019
1 parent 856f781 commit 64d41c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/MonthCalendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -106,6 +126,8 @@ class MonthCalendar extends React.Component {
onMonthSelect={this.onSelect}
onValueChange={this.setValue}
onPanelChange={this.handlePanelChange}
previousYear={this.previousYear}
nextYear={this.nextYear}
/>
</div>
<CalendarFooter
Expand Down
6 changes: 5 additions & 1 deletion src/calendar/CalendarHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,25 @@ export default class CalendarHeader extends React.Component {
enablePrev,
disabledMonth,
renderFooter,
previousYear,
nextYear,
} = props;

let panel = null;
if (mode === 'month') {
panel = (
<MonthPanel
locale={locale}
defaultValue={value}
value={value}
rootPrefixCls={prefixCls}
onSelect={this.onMonthSelect}
onYearPanelShow={() => this.showYearPanel('month')}
disabledDate={disabledMonth}
cellRender={props.monthCellRender}
contentRender={props.monthCellContentRender}
renderFooter={renderFooter}
previousYear={previousYear}
nextYear={nextYear}
/>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/month/MonthPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -87,7 +87,7 @@ class MonthPanel extends React.Component {
<a
className={`${prefixCls}-prev-year-btn`}
role="button"
onClick={this.previousYear}
onClick={previousYear}
title={locale.previousYear}
/>

Expand All @@ -104,7 +104,7 @@ class MonthPanel extends React.Component {
<a
className={`${prefixCls}-next-year-btn`}
role="button"
onClick={this.nextYear}
onClick={nextYear}
title={locale.nextYear}
/>
</div>
Expand Down

0 comments on commit 64d41c4

Please sign in to comment.