diff --git a/packages/vant/src/calendar/Calendar.tsx b/packages/vant/src/calendar/Calendar.tsx index 2da16a6a4..1ed7d4a32 100644 --- a/packages/vant/src/calendar/Calendar.tsx +++ b/packages/vant/src/calendar/Calendar.tsx @@ -165,6 +165,11 @@ export default defineComponent({ defaultDate = []; } + // reset invalid default date + if (defaultDate.length === 1 && compareDay(defaultDate[0], now) === 1) { + defaultDate = []; + } + const min = minDate.value; const max = maxDate.value; diff --git a/packages/vant/src/calendar/test/index.spec.ts b/packages/vant/src/calendar/test/index.spec.ts index f566beed5..e31b16516 100644 --- a/packages/vant/src/calendar/test/index.spec.ts +++ b/packages/vant/src/calendar/test/index.spec.ts @@ -655,3 +655,19 @@ test('should render confirm-text slot correctly', async () => { expect(wrapper.find('.van-calendar__confirm').html()).toMatchSnapshot(); }); + +test('the defaultDate length of 1 should be handled correctly', async () => { + const wrapper = mount(Calendar, { + props: { + poppable: false, + defaultDate: [getNextDay(now)], + type: 'range', + }, + }); + + wrapper.find('.van-calendar__confirm').trigger('click'); + expect(wrapper.emitted<[Date]>('confirm')![0][0]).toEqual([ + now, + getNextDay(now), + ]); +});