-
Notifications
You must be signed in to change notification settings - Fork 577
fix(DatePicker): 修复DateRangePicker选择时的交互问题 #6143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
TDesign Component Site Preview Open
|
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the logic for managing the date range picker's state during date selection by improving how the component tracks whether any value has been selected. The changes ensure that the picker properly determines when to keep the popup open or close it after user interaction.
- Removed the redundant
!activeIndex.valuecondition from the popup close logic - Changed
isFirstValueSelectedto check if any value exists (not just the first one) usingnextValue.some((v) => !!v)instead of!!nextValue[0]
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // 首次点击不关闭、确保两端都有有效值并且无时间选择器时点击后自动关闭 | ||
| if (!isFirstValueSelected.value || !activeIndex.value) { | ||
| if (!isFirstValueSelected.value) { |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition was simplified by removing || !activeIndex.value, but this changes the behavior when activeIndex.value is 0. Previously, when activeIndex.value was 0 (selecting start date), the condition would evaluate to true even if isFirstValueSelected.value was true, keeping the popup open. Now it will close the popup. Verify this behavior change is intentional, especially for the start date selection flow where activeIndex.value is 0.
| if (!isFirstValueSelected.value) { | |
| if (!isFirstValueSelected.value || !activeIndex.value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!activeIndex.value判断时,如果先选择endDate后选择startDate,会让使用者再次选择endDate,但此时使用者已经选择了完整了日期区间。这里不能使用activeIndex下标去判断,因为用户选择的先后行为是不可预期的。
186 行改为isFirstValueSelected.value = nextValue.some((v) => !!v),那么不管使用者是先选择endDate or startDate,下次点击都会命中关闭逻辑。
@Wesley-0808
| if (nextIndex === -1) nextIndex = activeIndex.value ? 0 : 1; | ||
| activeIndex.value = nextIndex as 0 | 1; | ||
| isFirstValueSelected.value = !!nextValue[0]; | ||
| isFirstValueSelected.value = nextValue.some((v) => !!v); |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic change from !!nextValue[0] to nextValue.some((v) => !!v) fundamentally changes the meaning of isFirstValueSelected. The variable name suggests it tracks whether the first value has been selected, but now it checks if any value is selected. This creates a semantic mismatch. When selecting the end date first (index 1), this will set isFirstValueSelected to true even though the first position (index 0) is empty. This could break the logic at lines 160-162 that uses !isFirstValueSelected.value to determine if it's a second modification, potentially preventing proper start/end date validation.
| isFirstValueSelected.value = nextValue.some((v) => !!v); | |
| isFirstValueSelected.value = !!nextValue[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tdesign-vue-next/packages/components/date-picker/DateRangePicker.tsx
Lines 156 to 162 in 8f191aa
| // 当两端都有有效值时更改 value | |
| if (notValidIndex === -1 && nextValue.length === 2) { | |
| // 二次修改时当其中一侧不符合上次区间规范时,清空另一侧数据 | |
| if ( | |
| !isFirstValueSelected.value && | |
| parseToDayjs(nextValue[0], formatRef.value.format).isAfter(parseToDayjs(nextValue[1], formatRef.value.format)) | |
| ) { |
这里的先行逻辑是
startDate endDate都满足有效值,nextValue.some((v) => !!v)并不会影响此地方的逻辑。popupVisible关闭时都会重置isFirstValueSelected.value = false,二次修改日期区间的首次点击也会验证此地方值的合理性逻辑。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copilot按变量名来理解了,不过确实,改了之后的 不符合变量名的语义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么一想语意确实有歧义,我看到 isFirstValueSelected的当时注释写的是// 记录面板点击次数,两次后才自动关闭

🤔 这个 PR 的性质是?
🔗 相关 Issue
💡 需求背景和解决方案
activeIndex.value值会永远进入首次点击的逻辑tdesign-vue-next/packages/components/date-picker/DateRangePicker.tsx
Lines 181 to 182 in 8f191aa
nextValue<Array>中选择第一次后一定有开始日期或结束日期,则下次点击必定是第二次选择且执行关闭逻辑📝 更新日志
tdesign-vue-next
@tdesign-vue-next/chat
@tdesign-vue-next/auto-import-resolver
☑️ 请求合并前的自查清单