Skip to content

Commit d775351

Browse files
committed
Use the slide gesture on slider
1 parent 35a6a64 commit d775351

File tree

4 files changed

+77
-77
lines changed

4 files changed

+77
-77
lines changed

src/components/slider/slider.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="md-slider-wrapper">
22
<div class="md-slider-container"
3-
[class.md-slider-dragging]="isDragging"
3+
[class.md-slider-sliding]="isSliding"
44
[class.md-slider-active]="isActive">
55
<div class="md-slider-track-container">
66
<div class="md-slider-track"></div>

src/components/slider/slider.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ md-slider *::after {
6666
}
6767

6868
/**
69-
* Holds the isActive and isDragging classes as well as helps with positioning the children.
69+
* Holds the isActive and isSliding classes as well as helps with positioning the children.
7070
* Cannot be merged with .md-slider-wrapper.
7171
*/
7272
.md-slider-container {
@@ -130,8 +130,8 @@ md-slider *::after {
130130
border-color: md-color($md-accent);
131131
}
132132

133-
.md-slider-dragging .md-slider-thumb-position,
134-
.md-slider-dragging .md-slider-track-fill {
133+
.md-slider-sliding .md-slider-thumb-position,
134+
.md-slider-sliding .md-slider-track-fill {
135135
transition: none;
136136
cursor: default;
137137
}

src/components/slider/slider.spec.ts

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ describe('MdSlider', () => {
7171
expect(sliderInstance.value).toBe(19);
7272
});
7373

74-
it('should update the value on a drag', () => {
74+
it('should update the value on a slide', () => {
7575
expect(sliderInstance.value).toBe(0);
76-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.89, gestureConfig);
76+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.89, gestureConfig);
7777
// The expected value is 89 from: percentage * difference of max and min.
7878
expect(sliderInstance.value).toBe(89);
7979
});
8080

81-
it('should set the value as min when dragging before the track', () => {
81+
it('should set the value as min when sliding before the track', () => {
8282
expect(sliderInstance.value).toBe(0);
83-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, -1.33, gestureConfig);
83+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, -1.33, gestureConfig);
8484
expect(sliderInstance.value).toBe(0);
8585
});
8686

87-
it('should set the value as max when dragging past the track', () => {
87+
it('should set the value as max when sliding past the track', () => {
8888
expect(sliderInstance.value).toBe(0);
89-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 1.75, gestureConfig);
89+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 1.75, gestureConfig);
9090
expect(sliderInstance.value).toBe(100);
9191
});
9292

@@ -116,9 +116,9 @@ describe('MdSlider', () => {
116116
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.5 + sliderDimensions.left);
117117
});
118118

119-
it('should update the track fill on drag', () => {
119+
it('should update the track fill on slide', () => {
120120
expect(trackFillDimensions.width).toBe(0);
121-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.86, gestureConfig);
121+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.86, gestureConfig);
122122

123123
trackFillDimensions = trackFillElement.getBoundingClientRect();
124124
thumbDimensions = thumbElement.getBoundingClientRect();
@@ -130,11 +130,11 @@ describe('MdSlider', () => {
130130
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition));
131131
});
132132

133-
it('should update the thumb position on drag', () => {
133+
it('should update the thumb position on slide', () => {
134134
expect(thumbDimensions.left).toBe(sliderDimensions.left);
135-
// The drag event also truncates the position passed in, so 50% is used here as well to
135+
// The slide event also truncates the position passed in, so 50% is used here as well to
136136
// ensure the ability to calculate the expected position.
137-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.5, gestureConfig);
137+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.5, gestureConfig);
138138

139139
thumbDimensions = thumbElement.getBoundingClientRect();
140140
expect(thumbDimensions.left).toBe(sliderDimensions.width * 0.5 + sliderDimensions.left);
@@ -165,19 +165,19 @@ describe('MdSlider', () => {
165165
expect(containerElement.classList).not.toContain('md-slider-active');
166166
});
167167

168-
it('should add and remove the md-slider-dragging class when dragging', () => {
168+
it('should add and remove the md-slider-sliding class when sliding', () => {
169169
let containerElement = sliderNativeElement.querySelector('.md-slider-container');
170-
expect(containerElement.classList).not.toContain('md-slider-dragging');
170+
expect(containerElement.classList).not.toContain('md-slider-sliding');
171171

172-
dispatchDragStartEvent(sliderNativeElement, 0, gestureConfig);
172+
dispatchSlideStartEvent(sliderNativeElement, 0, gestureConfig);
173173
fixture.detectChanges();
174174

175-
expect(containerElement.classList).toContain('md-slider-dragging');
175+
expect(containerElement.classList).toContain('md-slider-sliding');
176176

177-
dispatchDragEndEvent(sliderNativeElement, 0.34, gestureConfig);
177+
dispatchSlideEndEvent(sliderNativeElement, 0.34, gestureConfig);
178178
fixture.detectChanges();
179179

180-
expect(containerElement.classList).not.toContain('md-slider-dragging');
180+
expect(containerElement.classList).not.toContain('md-slider-sliding');
181181
});
182182
});
183183

@@ -208,9 +208,9 @@ describe('MdSlider', () => {
208208
expect(sliderInstance.value).toBe(0);
209209
});
210210

211-
it('should not change the value on drag when disabled', () => {
211+
it('should not change the value on slide when disabled', () => {
212212
expect(sliderInstance.value).toBe(0);
213-
dispatchDragEvent(sliderNativeElement, sliderNativeElement, 0, 0.5, gestureConfig);
213+
dispatchSlideEvent(sliderNativeElement, sliderNativeElement, 0, 0.5, gestureConfig);
214214
expect(sliderInstance.value).toBe(0);
215215
});
216216

@@ -224,14 +224,14 @@ describe('MdSlider', () => {
224224
expect(containerElement.classList).not.toContain('md-slider-active');
225225
});
226226

227-
it('should not add the md-slider-dragging class on drag when disabled', () => {
227+
it('should not add the md-slider-sliding class on slide when disabled', () => {
228228
let containerElement = sliderNativeElement.querySelector('.md-slider-container');
229-
expect(containerElement.classList).not.toContain('md-slider-dragging');
229+
expect(containerElement.classList).not.toContain('md-slider-sliding');
230230

231-
dispatchDragStartEvent(sliderNativeElement, 0.46, gestureConfig);
231+
dispatchSlideStartEvent(sliderNativeElement, 0.46, gestureConfig);
232232
fixture.detectChanges();
233233

234-
expect(containerElement.classList).not.toContain('md-slider-dragging');
234+
expect(containerElement.classList).not.toContain('md-slider-sliding');
235235
});
236236
});
237237

@@ -274,8 +274,8 @@ describe('MdSlider', () => {
274274
expect(sliderInstance.value).toBe(value);
275275
});
276276

277-
it('should set the correct value on drag', () => {
278-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.62, gestureConfig);
277+
it('should set the correct value on slide', () => {
278+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.62, gestureConfig);
279279
// Computed by multiplying the difference between the min and the max by the percentage from
280280
// the click and adding that to the minimum.
281281
let value = Math.round(4 + (0.62 * (6 - 4)));
@@ -295,11 +295,11 @@ describe('MdSlider', () => {
295295
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition));
296296
});
297297

298-
it('should snap the thumb and fill to the nearest value on drag', () => {
299-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.74, gestureConfig);
298+
it('should snap the thumb and fill to the nearest value on slide', () => {
299+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.74, gestureConfig);
300300
fixture.detectChanges();
301301

302-
dispatchDragEndEvent(sliderNativeElement, 0.74, gestureConfig);
302+
dispatchSlideEndEvent(sliderNativeElement, 0.74, gestureConfig);
303303
fixture.detectChanges();
304304

305305
let trackFillDimensions = trackFillElement.getBoundingClientRect();
@@ -343,8 +343,8 @@ describe('MdSlider', () => {
343343
expect(sliderInstance.value).toBe(92);
344344
});
345345

346-
it('should set the correct value on drag', () => {
347-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.32, gestureConfig);
346+
it('should set the correct value on slide', () => {
347+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.32, gestureConfig);
348348
expect(sliderInstance.value).toBe(32);
349349
});
350350
});
@@ -396,18 +396,18 @@ describe('MdSlider', () => {
396396
expect(Math.round(trackFillDimensions.width)).toBe(Math.round(thumbPosition));
397397
});
398398

399-
it('should set the correct step value on drag', () => {
400-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.07, gestureConfig);
399+
it('should set the correct step value on slide', () => {
400+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.07, gestureConfig);
401401
fixture.detectChanges();
402402

403403
expect(sliderInstance.value).toBe(0);
404404
});
405405

406-
it('should snap the thumb and fill to a step on drag', () => {
407-
dispatchDragEvent(sliderTrackElement, sliderNativeElement, 0, 0.88, gestureConfig);
406+
it('should snap the thumb and fill to a step on slide', () => {
407+
dispatchSlideEvent(sliderTrackElement, sliderNativeElement, 0, 0.88, gestureConfig);
408408
fixture.detectChanges();
409409

410-
dispatchDragEndEvent(sliderNativeElement, 0.88, gestureConfig);
410+
dispatchSlideEndEvent(sliderNativeElement, 0.88, gestureConfig);
411411
fixture.detectChanges();
412412

413413
let trackFillDimensions = trackFillElement.getBoundingClientRect();
@@ -489,62 +489,62 @@ function dispatchClickEvent(element: HTMLElement, percentage: number): void {
489489
}
490490

491491
/**
492-
* Dispatches a drag event from an element.
492+
* Dispatches a slide event from an element.
493493
* @param trackElement The track element from which the event location will be calculated.
494494
* @param containerElement The container element from which the event will be dispatched.
495-
* @param startPercent The percentage of the slider where the drag will begin.
496-
* @param endPercent The percentage of the slider where the drag will end.
497-
* @param gestureConfig The gesture config for the test to handle emitting the drag events.
495+
* @param startPercent The percentage of the slider where the slide will begin.
496+
* @param endPercent The percentage of the slider where the slide will end.
497+
* @param gestureConfig The gesture config for the test to handle emitting the slide events.
498498
*/
499-
function dispatchDragEvent(trackElement: HTMLElement, containerElement: HTMLElement,
500-
startPercent: number, endPercent: number,
501-
gestureConfig: TestGestureConfig): void {
499+
function dispatchSlideEvent(trackElement: HTMLElement, containerElement: HTMLElement,
500+
startPercent: number, endPercent: number,
501+
gestureConfig: TestGestureConfig): void {
502502
let dimensions = trackElement.getBoundingClientRect();
503503
let startX = dimensions.left + (dimensions.width * startPercent);
504504
let endX = dimensions.left + (dimensions.width * endPercent);
505505

506-
gestureConfig.emitEventForElement('dragstart', containerElement, {
507-
// The actual event has a center with an x value that the drag listener is looking for.
506+
gestureConfig.emitEventForElement('slidestart', containerElement, {
507+
// The actual event has a center with an x value that the slide listener is looking for.
508508
center: { x: startX },
509509
// The event needs a source event with a prevent default so we fake one.
510510
srcEvent: { preventDefault: jasmine.createSpy('preventDefault') }
511511
});
512512

513-
gestureConfig.emitEventForElement('drag', containerElement, {
513+
gestureConfig.emitEventForElement('slide', containerElement, {
514514
center: { x: endX },
515515
srcEvent: { preventDefault: jasmine.createSpy('preventDefault') }
516516
});
517517
}
518518

519519
/**
520-
* Dispatches a dragstart event from an element.
520+
* Dispatches a slidestart event from an element.
521521
* @param element The element from which the event will be dispatched.
522-
* @param startPercent The percentage of the slider where the drag will begin.
523-
* @param gestureConfig The gesture config for the test to handle emitting the drag events.
522+
* @param startPercent The percentage of the slider where the slide will begin.
523+
* @param gestureConfig The gesture config for the test to handle emitting the slide events.
524524
*/
525-
function dispatchDragStartEvent(element: HTMLElement, startPercent: number,
526-
gestureConfig: TestGestureConfig): void {
525+
function dispatchSlideStartEvent(element: HTMLElement, startPercent: number,
526+
gestureConfig: TestGestureConfig): void {
527527
let dimensions = element.getBoundingClientRect();
528528
let x = dimensions.left + (dimensions.width * startPercent);
529529

530-
gestureConfig.emitEventForElement('dragstart', element, {
530+
gestureConfig.emitEventForElement('slidestart', element, {
531531
center: { x: x },
532532
srcEvent: { preventDefault: jasmine.createSpy('preventDefault') }
533533
});
534534
}
535535

536536
/**
537-
* Dispatches a dragend event from an element.
537+
* Dispatches a slideend event from an element.
538538
* @param element The element from which the event will be dispatched.
539-
* @param endPercent The percentage of the slider where the drag will end.
540-
* @param gestureConfig The gesture config for the test to handle emitting the drag events.
539+
* @param endPercent The percentage of the slider where the slide will end.
540+
* @param gestureConfig The gesture config for the test to handle emitting the slide events.
541541
*/
542-
function dispatchDragEndEvent(element: HTMLElement, endPercent: number,
543-
gestureConfig: TestGestureConfig): void {
542+
function dispatchSlideEndEvent(element: HTMLElement, endPercent: number,
543+
gestureConfig: TestGestureConfig): void {
544544
let dimensions = element.getBoundingClientRect();
545545
let x = dimensions.left + (dimensions.width * endPercent);
546546

547-
gestureConfig.emitEventForElement('dragend', element, {
547+
gestureConfig.emitEventForElement('slideend', element, {
548548
center: { x: x },
549549
srcEvent: { preventDefault: jasmine.createSpy('preventDefault') }
550550
});

src/components/slider/slider.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {applyCssTransform} from '@angular2-material/core/style/apply-transform';
1515
host: {
1616
'tabindex': '0',
1717
'(click)': 'onClick($event)',
18-
'(drag)': 'onDrag($event)',
19-
'(dragstart)': 'onDragStart($event)',
20-
'(dragend)': 'onDragEnd()',
18+
'(slide)': 'onSlide($event)',
19+
'(slidestart)': 'onSlideStart($event)',
20+
'(slideend)': 'onSlideEnd()',
2121
'(window:resize)': 'onResize()',
2222
'(blur)': 'onBlur()',
2323
},
@@ -51,14 +51,14 @@ export class MdSlider implements AfterContentInit {
5151
@Input() step: number = 1;
5252

5353
/**
54-
* Whether or not the thumb is currently being dragged.
54+
* Whether or not the thumb is sliding.
5555
* Used to determine if there should be a transition for the thumb and fill track.
5656
* TODO: internal
5757
*/
58-
isDragging: boolean = false;
58+
isSliding: boolean = false;
5959

6060
/**
61-
* Whether or not the slider is active (clicked or is being dragged).
61+
* Whether or not the slider is active (clicked or sliding).
6262
* Used to shrink and grow the thumb as according to the Material Design spec.
6363
* TODO: internal
6464
*/
@@ -128,45 +128,45 @@ export class MdSlider implements AfterContentInit {
128128
}
129129

130130
this.isActive = true;
131-
this.isDragging = false;
131+
this.isSliding = false;
132132
this._renderer.addFocus();
133133
this.updateValueFromPosition(event.clientX);
134134
this.snapToValue();
135135
}
136136

137137
/** TODO: internal */
138-
onDrag(event: HammerInput) {
138+
onSlide(event: HammerInput) {
139139
if (this.disabled) {
140140
return;
141141
}
142142

143-
// Prevent the drag from selecting anything else.
143+
// Prevent the slide from selecting anything else.
144144
event.preventDefault();
145145
this.updateValueFromPosition(event.center.x);
146146
}
147147

148148
/** TODO: internal */
149-
onDragStart(event: HammerInput) {
149+
onSlideStart(event: HammerInput) {
150150
if (this.disabled) {
151151
return;
152152
}
153153

154154
event.preventDefault();
155-
this.isDragging = true;
155+
this.isSliding = true;
156156
this.isActive = true;
157157
this._renderer.addFocus();
158158
this.updateValueFromPosition(event.center.x);
159159
}
160160

161161
/** TODO: internal */
162-
onDragEnd() {
163-
this.isDragging = false;
164-
this.snapToValue();
162+
onSlideEnd() {
163+
this.isSliding = false;
164+
this.snapToValue();
165165
}
166166

167167
/** TODO: internal */
168168
onResize() {
169-
this.isDragging = true;
169+
this.isSliding = true;
170170
this._sliderDimensions = this._renderer.getSliderDimensions();
171171
// Skip updating the value and position as there is no new placement.
172172
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
@@ -180,7 +180,7 @@ export class MdSlider implements AfterContentInit {
180180
/**
181181
* When the value changes without a physical position, the percentage needs to be recalculated
182182
* independent of the physical location.
183-
* This is also used to move the thumb to a snapped value once dragging is done.
183+
* This is also used to move the thumb to a snapped value once sliding is done.
184184
*/
185185
updatePercentFromValue() {
186186
this._percent = (this.value - this.min) / (this.max - this.min);

0 commit comments

Comments
 (0)