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

Commit

Permalink
fix(slider): update the thumb text when the model is updated
Browse files Browse the repository at this point in the history
Closes #791. Closes #817. Closes #820.
  • Loading branch information
PaulMougel authored and ajoslin committed Dec 8, 2014
1 parent bd82a48 commit 2ca21f8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ function SliderController($scope, $element, $attrs, $$rAF, $window, $mdAria, $md
$scope.modelValue = ngModelCtrl.$viewValue;
$element.attr('aria-valuenow', ngModelCtrl.$viewValue);
setSliderPercent(percent);
thumbText.text( ngModelCtrl.$viewValue );
}

function minMaxValidator(value) {
Expand Down
48 changes: 48 additions & 0 deletions src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,54 @@ describe('md-slider', function() {
expect($rootScope.model).toBe(100);
}));

it('should update the thumb text', inject(function($compile, $rootScope, $timeout, $mdConstant) {
var slider = $compile('<md-slider ng-model="value" min="0" max="100">')($rootScope);
var sliderCtrl = slider.controller('mdSlider');

spyOn(slider[0].querySelector('.md-track-container'), 'getBoundingClientRect').andReturn({
width: 100,
left: 0,
right: 0
});

sliderCtrl._onInput( simulateEventAt( 30, Hammer.INPUT_START ));
$timeout.flush();
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('30');

slider.triggerHandler({
type: 'keydown',
keyCode: $mdConstant.KEY_CODE.LEFT_ARROW
});
$timeout.flush();
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('29');

sliderCtrl._onPan( simulateEventAt( 30 ));
$timeout.flush();
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('30');
}));

it('should update the thumb text with the model value when using ng-change', inject(function($compile, $rootScope, $timeout) {
$scope = $rootScope.$new();

$scope.stayAt50 = function () {
$scope.value = 50;
};

var slider = $compile('<md-slider ng-model="value" min="0" max="100" ng-change="stayAt50()">')($scope);
var sliderCtrl = slider.controller('mdSlider');

spyOn(slider[0].querySelector('.md-track-container'), 'getBoundingClientRect').andReturn({
width: 100,
left: 0,
right: 0
});

sliderCtrl._onInput( simulateEventAt( 30, Hammer.INPUT_START ));
$timeout.flush();
expect($scope.value).toBe(50);
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('50');
}));

it('should call $log.warn if aria-label isnt provided', inject(function($compile, $rootScope, $timeout, $log) {
spyOn($log, "warn");
var element = $compile(
Expand Down

0 comments on commit 2ca21f8

Please sign in to comment.