Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

monthCalendar按键事件无效 #534

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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