@@ -10,7 +10,13 @@ import {
10
10
RIGHT_ARROW ,
11
11
UP_ARROW ,
12
12
} from '@angular/cdk/keycodes' ;
13
- import { dispatchFakeEvent , dispatchKeyboardEvent , dispatchMouseEvent } from '@angular/cdk/testing' ;
13
+ import {
14
+ dispatchFakeEvent ,
15
+ dispatchKeyboardEvent ,
16
+ dispatchMouseEvent ,
17
+ createMouseEvent ,
18
+ dispatchEvent ,
19
+ } from '@angular/cdk/testing' ;
14
20
import { Component , DebugElement , ViewChild , Type } from '@angular/core' ;
15
21
import { ComponentFixture , TestBed , fakeAsync , flush } from '@angular/core/testing' ;
16
22
import { FormControl , FormsModule , ReactiveFormsModule } from '@angular/forms' ;
@@ -68,6 +74,14 @@ describe('MatSlider', () => {
68
74
expect ( sliderInstance . value ) . toBe ( 19 ) ;
69
75
} ) ;
70
76
77
+ it ( 'should not update when pressing the right mouse button' , ( ) => {
78
+ expect ( sliderInstance . value ) . toBe ( 0 ) ;
79
+
80
+ dispatchMousedownEventSequence ( sliderNativeElement , 0.19 , 1 ) ;
81
+
82
+ expect ( sliderInstance . value ) . toBe ( 0 ) ;
83
+ } ) ;
84
+
71
85
it ( 'should update the value on a slide' , ( ) => {
72
86
expect ( sliderInstance . value ) . toBe ( 0 ) ;
73
87
@@ -1599,15 +1613,17 @@ class SliderWithTwoWayBinding {
1599
1613
* @param sliderElement The mat-slider element from which the event will be dispatched.
1600
1614
* @param percentage The percentage of the slider where the event should occur. Used to find the
1601
1615
* physical location of the pointer.
1616
+ * @param button Button that should be held down when starting to drag the slider.
1602
1617
*/
1603
- function dispatchMousedownEventSequence ( sliderElement : HTMLElement , percentage : number ) : void {
1604
- let trackElement = sliderElement . querySelector ( '.mat-slider-wrapper' ) ! ;
1605
- let dimensions = trackElement . getBoundingClientRect ( ) ;
1606
- let x = dimensions . left + ( dimensions . width * percentage ) ;
1607
- let y = dimensions . top + ( dimensions . height * percentage ) ;
1618
+ function dispatchMousedownEventSequence ( sliderElement : HTMLElement , percentage : number ,
1619
+ button = 0 ) : void {
1620
+ const trackElement = sliderElement . querySelector ( '.mat-slider-wrapper' ) ! ;
1621
+ const dimensions = trackElement . getBoundingClientRect ( ) ;
1622
+ const x = dimensions . left + ( dimensions . width * percentage ) ;
1623
+ const y = dimensions . top + ( dimensions . height * percentage ) ;
1608
1624
1609
1625
dispatchMouseenterEvent ( sliderElement ) ;
1610
- dispatchMouseEvent ( sliderElement , 'mousedown' , x , y ) ;
1626
+ dispatchEvent ( sliderElement , createMouseEvent ( 'mousedown' , x , y , button ) ) ;
1611
1627
}
1612
1628
1613
1629
/**
0 commit comments