Skip to content

Commit

Permalink
fix(calendar-card): 选择范围时支持仅选择单个日期 (#2963)
Browse files Browse the repository at this point in the history
close #2950
  • Loading branch information
eiinu authored Mar 13, 2024
1 parent 2933216 commit 5be4aec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/packages/__VUE/calendarcard/__tests__/calendarcard.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils';
import CalendarCard from '..';
import { nextTick } from 'vue';
import { nextTick, ref } from 'vue';
import { CalendarCardDay } from '../types';

test('CalendarCard: test defaultValue mount(() => ', async () => {
Expand Down Expand Up @@ -72,11 +72,19 @@ test('CalendarCard: test type multiple', async () => {
});

test('CalendarCard: test type range', async () => {
const wrapper = mount(() => <CalendarCard modelValue={[new Date('2023-01-25')]} type="range" />);
const val = ref([new Date('2023-01-25')]);
const wrapper = mount(() => <CalendarCard v-model={val.value} type="range" />);

// current
const currentDays = wrapper.findAll('.nut-calendarcard-day.current');
currentDays[1].trigger('click'); // 0102
const active = wrapper.findAll('.nut-calendarcard-day.active');
expect(active.length).toBe(1);

currentDays[24].trigger('click'); // 0125
await nextTick();
const startAndEnd = wrapper.findAll('.nut-calendarcard-day.start.end');
expect(startAndEnd.length).toBe(1);

currentDays[3].trigger('click'); // 0104
currentDays[8].trigger('click'); // 0109
await nextTick();
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/calendarcard/calendar-card.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const handleDayClick = (day: CalendarCardDay) => {
change([day]);
} else if (len === 1) {
const t = compareDay(innerValue.value[0], day);
if (t === 0 || t === null || t === undefined) {
if (t === null || t === undefined) {
change([]);
} else if (t < 0) {
change([innerValue.value[0], day]);
Expand Down
2 changes: 1 addition & 1 deletion src/packages/__VUE/calendarcard/calendar-card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ const handleDayClick = (day: CalendarCardDay) => {
change([day]);
} else if (len === 1) {
const t = compareDay(innerValue.value[0], day);
if (t === 0 || t === null || t === undefined) {
if (t === null || t === undefined) {
change([]);
} else if (t < 0) {
change([innerValue.value[0], day]);
Expand Down

0 comments on commit 5be4aec

Please sign in to comment.