feat(Calendar): scroll to current month when show (#5526)

This commit is contained in:
neverland
2020-01-09 16:22:40 +08:00
committed by GitHub
parent ac3808cd47
commit c6489f4006
3 changed files with 49 additions and 1 deletions
+24 -1
View File
@@ -117,6 +117,7 @@ export default createComponent({
value(val) {
if (val) {
this.initRect();
this.scrollIntoView();
}
},
@@ -126,7 +127,7 @@ export default createComponent({
},
mounted() {
if (!this.poppable) {
if (this.value || !this.poppable) {
this.initRect();
}
},
@@ -144,6 +145,28 @@ export default createComponent({
});
},
// scroll to current month
scrollIntoView() {
this.$nextTick(() => {
const { type, currentDate } = this;
const targetDate = type === 'range' ? currentDate[0] : currentDate;
/* istanbul ignore if */
if (!targetDate) {
return;
}
this.months.some((month, index) => {
if (compareMonth(month, targetDate) === 0) {
this.$refs.months[index].$el.scrollIntoView();
return true;
}
return false;
});
});
},
getInitialDate() {
const { type, defaultDate, minDate } = this;