Skip to content

Commit

Permalink
fix: left and right arrows of MonthPicker cannot be worked #1543
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Dec 11, 2019
1 parent 9dcc648 commit c14d735
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 9 additions & 0 deletions components/vc-calendar/src/calendar/CalendarHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ const CalendarHeader = {
this.__emit('valueChange', value);
},

changeYear(direction) {
if (direction > 0) {
this.nextYear();
} else {
this.previousYear();
}
},

monthYearElement(showTimePicker) {
const props = this.$props;
const prefixCls = props.prefixCls;
Expand Down Expand Up @@ -158,6 +166,7 @@ const CalendarHeader = {
cellRender={props.monthCellRender}
contentRender={props.monthCellContentRender}
renderFooter={renderFooter}
changeYear={this.changeYear}
/>
);
}
Expand Down
12 changes: 3 additions & 9 deletions components/vc-calendar/src/month/MonthPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { hasProp } from '../../../_util/props-util';
import MonthTable from './MonthTable';

function goYear(direction) {
const next = this.sValue.clone();
next.add(direction, 'year');
this.setAndChangeValue(next);
this.changeYear(direction);
}

function noop() {}
Expand All @@ -25,6 +23,7 @@ const MonthPanel = {
disabledDate: PropTypes.func,
// onSelect: PropTypes.func,
renderFooter: PropTypes.func,
changeYear: PropTypes.func.def(noop),
},

data() {
Expand All @@ -44,18 +43,13 @@ const MonthPanel = {
},
},
methods: {
setAndChangeValue(value) {
this.setValue(value);
this.__emit('change', value);
},

setAndSelectValue(value) {
this.setValue(value);
this.__emit('select', value);
},

setValue(value) {
if (!hasProp(this, 'value')) {
if (hasProp(this, 'value')) {
this.setState({
sValue: value,
});
Expand Down

0 comments on commit c14d735

Please sign in to comment.