@@ -195,6 +195,18 @@ export class SliderComponent
195195 ) ;
196196 }
197197
198+ private cancelUserChangeSubscription : any ;
199+ @Input ( ) set cancelUserChange ( cancelUserChange : EventEmitter < void > ) {
200+ this . unsubscribeCancelUserChange ( ) ;
201+
202+ this . cancelUserChangeSubscription = cancelUserChange . subscribe ( ( ) => {
203+ if ( this . moving ) {
204+ this . positionTrackingHandle ( this . preStartHandleValue ) ;
205+ this . forceEnd ( true ) ;
206+ }
207+ } ) ;
208+ }
209+
198210 // Slider type, true means range slider
199211 public get range ( ) : boolean {
200212 return (
@@ -240,6 +252,8 @@ export class SliderComponent
240252 private touchId : number = null ;
241253 // Values recorded when first dragging the bar
242254 private dragging : Dragging = new Dragging ( ) ;
255+ // Value of hanlde at the beginning of onStart()
256+ private preStartHandleValue : number = null ;
243257
244258 /* Slider DOM elements */
245259
@@ -575,6 +589,13 @@ export class SliderComponent
575589 }
576590 }
577591
592+ private unsubscribeCancelUserChange ( ) : void {
593+ if ( ! ValueHelper . isNullOrUndefined ( this . cancelUserChangeSubscription ) ) {
594+ this . cancelUserChangeSubscription . unsubscribe ( ) ;
595+ this . cancelUserChangeSubscription = null ;
596+ }
597+ }
598+
578599 private getPointerElement ( pointerType : PointerType ) : SliderHandleDirective {
579600 if ( pointerType === PointerType . Min ) {
580601 return this . minHandleElement ;
@@ -2165,6 +2186,10 @@ export class SliderComponent
21652186 this . getPointerElement ( pointerType ) ;
21662187 pointerElement . active = true ;
21672188
2189+ // Store currentTrackingValue as soon as it is available to allow
2190+ // the slide to be canceled. (E.g. on scroll detected.)
2191+ this . preStartHandleValue = this . getCurrentTrackingValue ( ) ;
2192+
21682193 if ( this . viewOptions . keyboardSupport ) {
21692194 pointerElement . focus ( ) ;
21702195 }
@@ -2294,18 +2319,16 @@ export class SliderComponent
22942319 this . positionTrackingHandle ( newValue ) ;
22952320 }
22962321
2297- private onEnd ( event : MouseEvent | TouchEvent ) : void {
2298- if ( CompatibilityHelper . isTouchEvent ( event ) ) {
2299- const changedTouches : TouchList = ( event as TouchEvent ) . changedTouches ;
2300- if ( changedTouches [ 0 ] . identifier !== this . touchId ) {
2301- return ;
2302- }
2303- }
2304-
2322+ private forceEnd ( disableAnimation : boolean = false ) : void {
23052323 this . moving = false ;
23062324 if ( this . viewOptions . animate ) {
23072325 this . sliderElementAnimateClass = true ;
23082326 }
2327+ if ( disableAnimation ) {
2328+ this . sliderElementAnimateClass = false ;
2329+ // make sure the slider animate class is set according to the viewOptions after forceEnd() with disabled animations finishes
2330+ setTimeout ( ( ) => { this . sliderElementAnimateClass = this . viewOptions . animate } ) ;
2331+ }
23092332
23102333 this . touchId = null ;
23112334
@@ -2322,6 +2345,17 @@ export class SliderComponent
23222345 this . userChangeEnd . emit ( this . getChangeContext ( ) ) ;
23232346 }
23242347
2348+ private onEnd ( event : MouseEvent | TouchEvent ) : void {
2349+ if ( CompatibilityHelper . isTouchEvent ( event ) ) {
2350+ const changedTouches : TouchList = ( event as TouchEvent ) . changedTouches ;
2351+ if ( changedTouches [ 0 ] . identifier !== this . touchId ) {
2352+ return ;
2353+ }
2354+ }
2355+
2356+ this . forceEnd ( ) ;
2357+ }
2358+
23252359 private onPointerFocus ( pointerType : PointerType ) : void {
23262360 const pointerElement : SliderHandleDirective =
23272361 this . getPointerElement ( pointerType ) ;
0 commit comments