From c14d7357b807b667a75db713aafe7afeaf10d741 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 11 Dec 2019 21:02:31 +0800 Subject: [PATCH] fix: left and right arrows of MonthPicker cannot be worked #1543 --- .../vc-calendar/src/calendar/CalendarHeader.jsx | 9 +++++++++ components/vc-calendar/src/month/MonthPanel.jsx | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/components/vc-calendar/src/calendar/CalendarHeader.jsx b/components/vc-calendar/src/calendar/CalendarHeader.jsx index fdc924bc8..61d9ec6ec 100644 --- a/components/vc-calendar/src/calendar/CalendarHeader.jsx +++ b/components/vc-calendar/src/calendar/CalendarHeader.jsx @@ -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; @@ -158,6 +166,7 @@ const CalendarHeader = { cellRender={props.monthCellRender} contentRender={props.monthCellContentRender} renderFooter={renderFooter} + changeYear={this.changeYear} /> ); } diff --git a/components/vc-calendar/src/month/MonthPanel.jsx b/components/vc-calendar/src/month/MonthPanel.jsx index 8f8ee4d3b..e1d8c4519 100644 --- a/components/vc-calendar/src/month/MonthPanel.jsx +++ b/components/vc-calendar/src/month/MonthPanel.jsx @@ -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() {} @@ -25,6 +23,7 @@ const MonthPanel = { disabledDate: PropTypes.func, // onSelect: PropTypes.func, renderFooter: PropTypes.func, + changeYear: PropTypes.func.def(noop), }, data() { @@ -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, });