Skip to content

Commit 939a51c

Browse files
Haviles04KaelWD
andauthored
fix(VNumberInput): fix endless increment (#21610)
fixes #21581 Co-authored-by: Kael <[email protected]>
1 parent 525b0fd commit 939a51c

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

packages/vuetify/src/components/VNumberInput/VNumberInput.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
148148
onClick: onControlClick,
149149
onPointerup: onControlMouseup,
150150
onPointerdown: onUpControlMousedown,
151-
onPointercancel: onControlPointerCancel,
151+
onPointercancel: onControlMouseup,
152152
},
153153
}
154154
const decrementSlotProps = {
155155
props: {
156156
onClick: onControlClick,
157157
onPointerup: onControlMouseup,
158158
onPointerdown: onDownControlMousedown,
159-
onPointercancel: onControlPointerCancel,
159+
onPointercancel: onControlMouseup,
160160
},
161161
}
162162

@@ -250,7 +250,6 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
250250
const el = e.currentTarget as HTMLElement
251251
el?.releasePointerCapture(e.pointerId)
252252
e.preventDefault()
253-
e.stopPropagation()
254253
holdStop()
255254
}
256255

@@ -270,12 +269,6 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
270269
holdStart('down')
271270
}
272271

273-
function onControlPointerCancel (e: PointerEvent) {
274-
const el = e.currentTarget as HTMLElement
275-
el?.releasePointerCapture(e.pointerId)
276-
holdStop()
277-
}
278-
279272
function clampModel () {
280273
if (controlsDisabled.value) return
281274
if (!vTextFieldRef.value) return
@@ -331,7 +324,7 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
331324
onClick={ onControlClick }
332325
onPointerdown={ onUpControlMousedown }
333326
onPointerup={ onControlMouseup }
334-
onPointercancel={ onControlPointerCancel }
327+
onPointercancel={ onControlMouseup }
335328
size={ controlNodeSize.value }
336329
tabindex="-1"
337330
/>
@@ -366,7 +359,7 @@ export const VNumberInput = genericComponent<VNumberInputSlots>()({
366359
onClick={ onControlClick }
367360
onPointerdown={ onDownControlMousedown }
368361
onPointerup={ onControlMouseup }
369-
onPointercancel={ onControlPointerCancel }
362+
onPointercancel={ onControlMouseup }
370363
size={ controlNodeSize.value }
371364
tabindex="-1"
372365
/>

packages/vuetify/src/components/VNumberInput/hold.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export function useHold ({ toggleUpDown }: { toggleUpDown: (increment: boolean)
1313
function holdStart (value: 'up' | 'down') {
1414
holdStop()
1515
tick(value)
16+
window.addEventListener('pointerup', holdStop)
17+
document.addEventListener('blur', holdStop)
1618
timeout = window.setTimeout(() => {
1719
interval = window.setInterval(() => tick(value), HOLD_REPEAT)
1820
}, HOLD_DELAY)
@@ -21,6 +23,8 @@ export function useHold ({ toggleUpDown }: { toggleUpDown: (increment: boolean)
2123
function holdStop () {
2224
window.clearTimeout(timeout)
2325
window.clearInterval(interval)
26+
window.removeEventListener('pointerup', holdStop)
27+
document.removeEventListener('blur', holdStop)
2428
}
2529

2630
function tick (value: 'up' | 'down') {

0 commit comments

Comments
 (0)