@@ -98,6 +98,7 @@ export default mixins<options &
98
98
isFocused : false ,
99
99
isActive : false ,
100
100
noClick : false , // Prevent click event if dragging took place, hack for #7915
101
+ startOffset : 0 ,
101
102
} ) ,
102
103
103
104
computed : {
@@ -448,24 +449,30 @@ export default mixins<options &
448
449
[ direction ] : `${ value } %` ,
449
450
}
450
451
} ,
451
- onSliderMouseDown ( e : MouseEvent ) {
452
+ onSliderMouseDown ( e : MouseEvent | TouchEvent ) {
452
453
e . preventDefault ( )
453
454
454
455
this . oldValue = this . internalValue
455
456
this . isActive = true
456
457
457
- const mouseUpOptions = passiveSupported ? { passive : true , capture : true } : true
458
- const mouseMoveOptions = passiveSupported ? { passive : true } : false
459
-
460
458
if ( ( e . target as Element ) ?. matches ( '.v-slider__thumb-container, .v-slider__thumb-container *' ) ) {
461
459
this . thumbPressed = true
460
+ const domRect = ( e . target as Element ) . getBoundingClientRect ( )
461
+ const touch = 'touches' in e ? e . touches [ 0 ] : e
462
+ this . startOffset = this . vertical
463
+ ? touch . clientY - ( domRect . top + domRect . height / 2 )
464
+ : touch . clientX - ( domRect . left + domRect . width / 2 )
462
465
} else {
466
+ this . startOffset = 0
463
467
window . clearTimeout ( this . mouseTimeout )
464
468
this . mouseTimeout = window . setTimeout ( ( ) => {
465
469
this . thumbPressed = true
466
470
} , 300 )
467
471
}
468
472
473
+ const mouseUpOptions = passiveSupported ? { passive : true , capture : true } : true
474
+ const mouseMoveOptions = passiveSupported ? { passive : true } : false
475
+
469
476
const isTouchEvent = 'touches' in e
470
477
471
478
this . onMouseMove ( e )
@@ -491,7 +498,7 @@ export default mixins<options &
491
498
492
499
this . isActive = false
493
500
} ,
494
- onMouseMove ( e : MouseEvent ) {
501
+ onMouseMove ( e : MouseEvent | TouchEvent ) {
495
502
if ( e . type === 'mousemove' ) {
496
503
this . thumbPressed = true
497
504
}
@@ -532,19 +539,19 @@ export default mixins<options &
532
539
533
540
this . $emit ( 'focus' , e )
534
541
} ,
535
- parseMouseMove ( e : MouseEvent ) {
542
+ parseMouseMove ( e : MouseEvent | TouchEvent ) {
536
543
const start = this . vertical ? 'top' : 'left'
537
544
const length = this . vertical ? 'height' : 'width'
538
545
const click = this . vertical ? 'clientY' : 'clientX'
539
546
540
547
const {
541
548
[ start ] : trackStart ,
542
549
[ length ] : trackLength ,
543
- } = this . $refs . track . getBoundingClientRect ( ) as any
544
- const clickOffset = 'touches' in e ? ( e as any ) . touches [ 0 ] [ click ] : e [ click ] // Can we get rid of any here?
550
+ } = this . $refs . track . getBoundingClientRect ( )
551
+ const clickOffset = 'touches' in e ? e . touches [ 0 ] [ click ] : e [ click ]
545
552
546
553
// It is possible for left to be NaN, force to number
547
- let clickPos = Math . min ( Math . max ( ( clickOffset - trackStart ) / trackLength , 0 ) , 1 ) || 0
554
+ let clickPos = Math . min ( Math . max ( ( clickOffset - trackStart - this . startOffset ) / trackLength , 0 ) , 1 ) || 0
548
555
549
556
if ( this . vertical ) clickPos = 1 - clickPos
550
557
if ( this . $vuetify . rtl ) clickPos = 1 - clickPos
0 commit comments