Skip to content

Commit c14d735

Browse files
committed
fix: left and right arrows of MonthPicker cannot be worked #1543
1 parent 9dcc648 commit c14d735

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

components/vc-calendar/src/calendar/CalendarHeader.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ const CalendarHeader = {
7070
this.__emit('valueChange', value);
7171
},
7272

73+
changeYear(direction) {
74+
if (direction > 0) {
75+
this.nextYear();
76+
} else {
77+
this.previousYear();
78+
}
79+
},
80+
7381
monthYearElement(showTimePicker) {
7482
const props = this.$props;
7583
const prefixCls = props.prefixCls;
@@ -158,6 +166,7 @@ const CalendarHeader = {
158166
cellRender={props.monthCellRender}
159167
contentRender={props.monthCellContentRender}
160168
renderFooter={renderFooter}
169+
changeYear={this.changeYear}
161170
/>
162171
);
163172
}

components/vc-calendar/src/month/MonthPanel.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { hasProp } from '../../../_util/props-util';
44
import MonthTable from './MonthTable';
55

66
function goYear(direction) {
7-
const next = this.sValue.clone();
8-
next.add(direction, 'year');
9-
this.setAndChangeValue(next);
7+
this.changeYear(direction);
108
}
119

1210
function noop() {}
@@ -25,6 +23,7 @@ const MonthPanel = {
2523
disabledDate: PropTypes.func,
2624
// onSelect: PropTypes.func,
2725
renderFooter: PropTypes.func,
26+
changeYear: PropTypes.func.def(noop),
2827
},
2928

3029
data() {
@@ -44,18 +43,13 @@ const MonthPanel = {
4443
},
4544
},
4645
methods: {
47-
setAndChangeValue(value) {
48-
this.setValue(value);
49-
this.__emit('change', value);
50-
},
51-
5246
setAndSelectValue(value) {
5347
this.setValue(value);
5448
this.__emit('select', value);
5549
},
5650

5751
setValue(value) {
58-
if (!hasProp(this, 'value')) {
52+
if (hasProp(this, 'value')) {
5953
this.setState({
6054
sValue: value,
6155
});

0 commit comments

Comments
 (0)