Skip to content

Commit 035f043

Browse files
committed
refactor: Attach listener for hold if hold is enabled (#855)
1 parent d89ceb2 commit 035f043

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/VueDatePicker/components/TimePicker/TimeInput.vue

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
tabindex="0"
1919
@keydown.enter.prevent="handleTimeValue(timeInput.type, true, { keyboard: true })"
2020
@keydown.space.prevent="handleTimeValue(timeInput.type, true, { keyboard: true })"
21-
@mousedown="handleTimeValue(timeInput.type)"
21+
@click="defaultedConfig.timeArrowHoldThreshold ? undefined : handleTimeValue(timeInput.type, false)"
22+
@mousedown="
23+
defaultedConfig.timeArrowHoldThreshold ? handleTimeValue(timeInput.type, true) : undefined
24+
"
2225
@mouseup="clearHold"
2326
>
2427
<template v-if="!props.timePickerInline">
@@ -71,7 +74,10 @@
7174
tabindex="0"
7275
@keydown.enter.prevent="handleTimeValue(timeInput.type, false, { keyboard: true })"
7376
@keydown.space.prevent="handleTimeValue(timeInput.type, false, { keyboard: true })"
74-
@mousedown="handleTimeValue(timeInput.type, false)"
77+
@click="defaultedConfig.timeArrowHoldThreshold ? undefined : handleTimeValue(timeInput.type, false)"
78+
@mousedown="
79+
defaultedConfig.timeArrowHoldThreshold ? handleTimeValue(timeInput.type, false) : undefined
80+
"
7581
@mouseup="clearHold"
7682
>
7783
<template v-if="!props.timePickerInline">
@@ -199,7 +205,6 @@
199205
const amPm = ref('AM');
200206
const amPmButton = ref<HTMLElement | null>(null);
201207
const elementRefs = ref<HTMLElement[][]>([]);
202-
const isHolding = ref(false);
203208
const holdTimeout = ref();
204209
205210
onMounted(() => {
@@ -375,7 +380,6 @@
375380
if (holdTimeout.value) {
376381
clearTimeout(holdTimeout.value);
377382
}
378-
isHolding.value = false;
379383
};
380384
381385
const handleTimeValue = (type: TimeType, inc = true, opts?: { keyboard?: boolean }): void => {
@@ -390,7 +394,6 @@
390394
}
391395
if (!opts?.keyboard && defaultedConfig.value.timeArrowHoldThreshold) {
392396
holdTimeout.value = setTimeout(() => {
393-
isHolding.value = true;
394397
handleTimeValue(type, inc);
395398
}, defaultedConfig.value.timeArrowHoldThreshold);
396399
}

src/VueDatePicker/utils/defaults.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export const getDefaultConfig = (config?: Partial<Config>): Config => {
169169
tabOutClosesMenu: true,
170170
arrowLeft: undefined,
171171
keepViewOnOffsetClick: false,
172-
timeArrowHoldThreshold: 200,
172+
timeArrowHoldThreshold: 0,
173173
};
174174
return { ...defaultConfig, ...(config ?? {}) };
175175
};

0 commit comments

Comments
 (0)