Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 2ca21f8

Browse files
PaulMougelajoslin
authored andcommitted
fix(slider): update the thumb text when the model is updated
Closes #791. Closes #817. Closes #820.
1 parent bd82a48 commit 2ca21f8

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/components/slider/slider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ function SliderController($scope, $element, $attrs, $$rAF, $window, $mdAria, $md
257257
$scope.modelValue = ngModelCtrl.$viewValue;
258258
$element.attr('aria-valuenow', ngModelCtrl.$viewValue);
259259
setSliderPercent(percent);
260+
thumbText.text( ngModelCtrl.$viewValue );
260261
}
261262

262263
function minMaxValidator(value) {

src/components/slider/slider.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,54 @@ describe('md-slider', function() {
119119
expect($rootScope.model).toBe(100);
120120
}));
121121

122+
it('should update the thumb text', inject(function($compile, $rootScope, $timeout, $mdConstant) {
123+
var slider = $compile('<md-slider ng-model="value" min="0" max="100">')($rootScope);
124+
var sliderCtrl = slider.controller('mdSlider');
125+
126+
spyOn(slider[0].querySelector('.md-track-container'), 'getBoundingClientRect').andReturn({
127+
width: 100,
128+
left: 0,
129+
right: 0
130+
});
131+
132+
sliderCtrl._onInput( simulateEventAt( 30, Hammer.INPUT_START ));
133+
$timeout.flush();
134+
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('30');
135+
136+
slider.triggerHandler({
137+
type: 'keydown',
138+
keyCode: $mdConstant.KEY_CODE.LEFT_ARROW
139+
});
140+
$timeout.flush();
141+
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('29');
142+
143+
sliderCtrl._onPan( simulateEventAt( 30 ));
144+
$timeout.flush();
145+
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('30');
146+
}));
147+
148+
it('should update the thumb text with the model value when using ng-change', inject(function($compile, $rootScope, $timeout) {
149+
$scope = $rootScope.$new();
150+
151+
$scope.stayAt50 = function () {
152+
$scope.value = 50;
153+
};
154+
155+
var slider = $compile('<md-slider ng-model="value" min="0" max="100" ng-change="stayAt50()">')($scope);
156+
var sliderCtrl = slider.controller('mdSlider');
157+
158+
spyOn(slider[0].querySelector('.md-track-container'), 'getBoundingClientRect').andReturn({
159+
width: 100,
160+
left: 0,
161+
right: 0
162+
});
163+
164+
sliderCtrl._onInput( simulateEventAt( 30, Hammer.INPUT_START ));
165+
$timeout.flush();
166+
expect($scope.value).toBe(50);
167+
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('50');
168+
}));
169+
122170
it('should call $log.warn if aria-label isnt provided', inject(function($compile, $rootScope, $timeout, $log) {
123171
spyOn($log, "warn");
124172
var element = $compile(

0 commit comments

Comments
 (0)