Skip to content

Commit 35a6a64

Browse files
committed
Create snap to value function
1 parent d369056 commit 35a6a64

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/components/slider/slider.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class MdSlider implements AfterContentInit {
4747
/** The percentage of the slider that coincides with the value. */
4848
private _percent: number = 0;
4949

50-
/** The values at which the thumb will snap to. */
50+
/** The values at which the thumb will snap. */
5151
@Input() step: number = 1;
5252

5353
/**
@@ -118,8 +118,7 @@ export class MdSlider implements AfterContentInit {
118118
*/
119119
ngAfterContentInit() {
120120
this._sliderDimensions = this._renderer.getSliderDimensions();
121-
this.updatePercentFromValue();
122-
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
121+
this.snapToValue();
123122
}
124123

125124
/** TODO: internal */
@@ -132,10 +131,7 @@ export class MdSlider implements AfterContentInit {
132131
this.isDragging = false;
133132
this._renderer.addFocus();
134133
this.updateValueFromPosition(event.clientX);
135-
136-
// Once the click is over the thumb has to snap to its new physical location.
137-
this.updatePercentFromValue();
138-
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
134+
this.snapToValue();
139135
}
140136

141137
/** TODO: internal */
@@ -165,9 +161,7 @@ export class MdSlider implements AfterContentInit {
165161
/** TODO: internal */
166162
onDragEnd() {
167163
this.isDragging = false;
168-
// Once the drag is over the thumb has to snap to its new physical location.
169-
this.updatePercentFromValue();
170-
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
164+
this.snapToValue();
171165
}
172166

173167
/** TODO: internal */
@@ -211,6 +205,15 @@ export class MdSlider implements AfterContentInit {
211205
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
212206
}
213207

208+
/**
209+
* Snaps the thumb to the current value.
210+
* Called after a click or drag event is over.
211+
*/
212+
snapToValue() {
213+
this.updatePercentFromValue();
214+
this._renderer.updateThumbAndFillPosition(this._percent, this._sliderDimensions.width);
215+
}
216+
214217
/**
215218
* Return a number between two numbers.
216219
*/

0 commit comments

Comments
 (0)