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(TimePicker): fix TimePicker change of time-item-click not working #4923

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions src/time-picker/panel/single-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineComponent({
const bodyRef = ref();
const maskRef = ref(null);
// 每个滚动列的ref 顺序不定 所以只要有5列标识即可
const colsRef = reactive({ 0: null, 1: null, 2: null, 3: null, 4: null, 5: null });
const colsRef = reactive<Record<string, any>>({ 0: null, 1: null, 2: null, 3: null, 4: null, 5: null });

const dayjsValue = computed(() => {
const isStepsSet = !!steps.value.filter((step) => Number(step) > 1).length;
Expand Down Expand Up @@ -191,7 +191,7 @@ export default defineComponent({
return;

if (timeArr.includes(col)) {
if (timeItemCanUsed(col, val)) formattedVal = dayjsValue.value[col]?.(val).format(format.value);
if (timeItemCanUsed(col, val)) formattedVal = (dayjsValue.value as any)[col]?.(val).format(format.value);
else formattedVal = dayjsValue.value.format(format.value);
} else {
const currentHour = dayjsValue.value.hour();
Expand Down Expand Up @@ -245,6 +245,10 @@ export default defineComponent({
el = Number(el) + 12;
}
scrollToTime(col, el, idx, 'smooth');

setTimeout(() => {
props.onChange?.((dayjsValue.value as any)[col]?.(el).format(format.value), e);
}, 100);
} else {
const currentHour = dayjsValue.value.hour();
if (el === AM && currentHour >= 12) {
Expand All @@ -265,7 +269,7 @@ export default defineComponent({
// 如果没有设置大于1的steps或设置了大于1的step 正常处理滚动
scrollToTime(
col,
timeArr.includes(col) ? dayjsValue.value[col]?.() : dayjsValue.value.format('a'),
timeArr.includes(col) ? (dayjsValue.value as any)[col]?.() : dayjsValue.value.format('a'),
idx,
behavior,
);
Expand Down
Loading