Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/components/slider/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,13 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
* @param percent 0-1
*/
function setSliderPercent(percent) {
activeTrack.css('width', (percent * 100) + '%');
thumbContainer.css(
'left',
(percent * 100) + '%'
);
element.toggleClass('md-min', percent === 0);
var percentStr = (percent * 100) + '%';

activeTrack.css('width', percentStr);
thumbContainer.css('left',percentStr);

element.toggleClass('md-min', percent === 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

element.toggleClass('md-max', percent === 1);
}


Expand Down
27 changes: 25 additions & 2 deletions src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('md-slider', function() {
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('50');
});

it('should call $log.warn if aria-label isnt provided', function() {
it('should call $log.warn if aria-label isn\'t provided', function() {
spyOn($log, "warn");
setup('min="100" max="104" step="2" ng-model="model"');
expect($log.warn).toHaveBeenCalled();
Expand Down Expand Up @@ -216,7 +216,30 @@ describe('md-slider', function() {
});
expect(slider).not.toHaveClass('md-active');
});


it('should add md-min class only when at min value', function() {
var slider = setup('ng-model="model" min="0" max="30"');
pageScope.$apply('model = 0');
expect(slider).toHaveClass('md-min');

slider.triggerHandler({type: '$md.dragstart', pointer: {x: 0}});
slider.triggerHandler({type: '$md.drag', pointer: {x: 10}});
$timeout.flush();
expect(slider).not.toHaveClass('md-min');
});

it('should add md-max class only when at max value', function() {
var slider = setup('ng-model="model" min="0" max="30"');
pageScope.$apply('model = 30');
expect(slider).toHaveClass('md-max');

slider.triggerHandler({type: '$md.dragstart', pointer: {x: 30}});
slider.triggerHandler({type: '$md.drag', pointer: {x: 10}});
$timeout.flush();
expect(slider).not.toHaveClass('md-max');
});


it('should increment at a predictable step', function() {

buildSlider(0.1, 1).drag({x:70});
Expand Down