Skip to content
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

fix: 优化 datepicker 输入事件交互 #1736

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/date-picker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,20 @@ export default defineComponent({
);

watch(popupVisible, (visible) => {
cacheValue.value = formatDate(value.value, {
format: formatRef.value.format,
});
inputValue.value = formatDate(value.value, {
format: formatRef.value.format,
});

// 面板展开重置数据
if (visible) {
year.value = parseToDayjs(value.value, formatRef.value.format).year();
month.value = parseToDayjs(value.value, formatRef.value.format).month();
time.value = formatTime(value.value, formatRef.value.timeFormat);
if (value.value) {
cacheValue.value = formatDate(value.value, {
format: formatRef.value.format,
});
}
} else {
isHoverCell.value = false;
}
});

Expand Down
1 change: 1 addition & 0 deletions src/date-picker/DateRangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export default defineComponent({
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
}
month.value = nextMonth;
year.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).year());
} else {
year.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).year());
month.value = value.value.map((v: string) => parseToDayjs(v || new Date(), formatRef.value.format).month());
Expand Down
12 changes: 6 additions & 6 deletions src/date-picker/hooks/useSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export default function useSingle(props: TdDatePickerProps) {
!Number.isNaN(newTime) && (time.value = newTime);
},
onEnter: (val: string) => {
if (!val) {
onChange('', { dayjsValue: dayjs(), trigger: 'enter' });
popupVisible.value = false;
return;
}

if (!isValidDate(val, formatRef.value.format) && !isValidDate(value.value, formatRef.value.format)) return;

popupVisible.value = false;
Expand Down Expand Up @@ -113,12 +119,6 @@ export default function useSingle(props: TdDatePickerProps) {
popupVisible.value = true;
return;
}
if (!visible) {
isHoverCell.value = false;
inputValue.value = formatDate(value.value, {
format: formatRef.value.format,
});
}
popupVisible.value = visible;
},
}));
Expand Down