Skip to content

Commit 5306c99

Browse files
authored
fix(date-range-picker): logical judgment error when start and end values exist at the same time (#4868)
1 parent 5d2b9ae commit 5306c99

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/date-picker/DateRangePicker.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,11 @@ export default defineComponent({
181181
}
182182

183183
// 首次点击不关闭、确保两端都有有效值并且无时间选择器时点击后自动关闭
184-
if (!isFirstValueSelected.value) {
184+
if (!isFirstValueSelected.value || !activeIndex.value) {
185185
let nextIndex = notValidIndex;
186186
if (nextIndex === -1) nextIndex = activeIndex.value ? 0 : 1;
187187
activeIndex.value = nextIndex;
188-
isFirstValueSelected.value = true;
188+
isFirstValueSelected.value = !!nextValue[0];
189189
} else {
190190
popupVisible.value = false;
191191
}
@@ -228,7 +228,7 @@ export default defineComponent({
228228
const { hours, minutes, seconds, milliseconds, meridiem } = extractTimeObj(val);
229229

230230
const nextInputValue = [...(inputValue.value as DateValue[])];
231-
const changedInputValue = inputValue.value[activeIndex.value];
231+
const changedInputValue = nextInputValue[activeIndex.value];
232232
const currentDate = !dayjs(changedInputValue, formatRef.value.format).isValid()
233233
? dayjs().year(year.value[activeIndex.value]).month(month.value[activeIndex.value])
234234
: dayjs(changedInputValue, formatRef.value.format);
@@ -290,11 +290,11 @@ export default defineComponent({
290290
}
291291

292292
// 首次点击不关闭、确保两端都有有效值并且无时间选择器时点击后自动关闭
293-
if (!isFirstValueSelected.value || nextValue.length === 1) {
293+
if (!isFirstValueSelected.value || !activeIndex.value) {
294294
let nextIndex = notValidIndex;
295295
if (nextIndex === -1) nextIndex = activeIndex.value ? 0 : 1;
296296
activeIndex.value = nextIndex;
297-
isFirstValueSelected.value = true;
297+
isFirstValueSelected.value = !!nextValue[0];
298298
} else if (nextValue.length === 2) {
299299
popupVisible.value = false;
300300
}

0 commit comments

Comments
 (0)