feat(Calendar): allow default-date to be null (#7116)

This commit is contained in:
neverland
2020-09-05 15:22:40 +08:00
committed by GitHub
parent afb8ac5443
commit aefec84e14
4 changed files with 32 additions and 9 deletions
+26 -7
View File
@@ -136,12 +136,13 @@ export default createComponent({
buttonDisabled() {
const { type, currentDate } = this;
if (type === 'range') {
return !currentDate[0] || !currentDate[1];
}
if (type === 'multiple') {
return !currentDate.length;
if (currentDate) {
if (type === 'range') {
return !currentDate[0] || !currentDate[1];
}
if (type === 'multiple') {
return !currentDate.length;
}
}
return !currentDate;
@@ -198,6 +199,11 @@ export default createComponent({
scrollIntoView() {
this.$nextTick(() => {
const { currentDate } = this;
if (!currentDate) {
return;
}
const targetDate =
this.type === 'single' ? currentDate : currentDate[0];
const displayed = this.value || !this.poppable;
@@ -222,6 +228,10 @@ export default createComponent({
getInitialDate() {
const { type, minDate, maxDate, defaultDate } = this;
if (defaultDate === null) {
return defaultDate;
}
let defaultVal = new Date();
if (compareDay(defaultVal, minDate) === -1) {
@@ -295,6 +305,11 @@ export default createComponent({
const { type, currentDate } = this;
if (type === 'range') {
if (!currentDate) {
this.select([date, null]);
return;
}
const [startDay, endDay] = currentDate;
if (startDay && !endDay) {
@@ -311,8 +326,12 @@ export default createComponent({
this.select([date, null]);
}
} else if (type === 'multiple') {
let selectedIndex;
if (!currentDate) {
this.select([date]);
return;
}
let selectedIndex;
const selected = this.currentDate.some((dateItem, index) => {
const equal = compareDay(dateItem, date) === 0;
if (equal) {