Skip to content

Commit c9136ea

Browse files
feat(slider): add md-max class when at max value
add md-max class when at max value. This is to keep things consistent with the fact that md-min is added when at min value fixes angular#3513
1 parent de32e5b commit c9136ea

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/components/slider/slider.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,13 @@ function SliderDirective($$rAF, $window, $mdAria, $mdUtil, $mdConstant, $mdThemi
291291
* @param percent 0-1
292292
*/
293293
function setSliderPercent(percent) {
294-
activeTrack.css('width', (percent * 100) + '%');
295-
thumbContainer.css(
296-
'left',
297-
(percent * 100) + '%'
298-
);
299-
element.toggleClass('md-min', percent === 0);
294+
var percentStr = (percent * 100) + '%';
295+
296+
activeTrack.css('width', percentStr);
297+
thumbContainer.css('left',percentStr);
298+
299+
element.toggleClass('md-min', percent === 0);
300+
element.toggleClass('md-max', percent === 1);
300301
}
301302

302303

src/components/slider/slider.spec.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ describe('md-slider', function() {
137137
expect(slider[0].querySelector('.md-thumb-text').textContent).toBe('50');
138138
});
139139

140-
it('should call $log.warn if aria-label isnt provided', function() {
140+
it('should call $log.warn if aria-label isn\'t provided', function() {
141141
spyOn($log, "warn");
142142
setup('min="100" max="104" step="2" ng-model="model"');
143143
expect($log.warn).toHaveBeenCalled();
@@ -216,7 +216,30 @@ describe('md-slider', function() {
216216
});
217217
expect(slider).not.toHaveClass('md-active');
218218
});
219-
219+
220+
it('should add md-min class only when at min value', function() {
221+
var slider = setup('ng-model="model" min="0" max="30"');
222+
pageScope.$apply('model = 0');
223+
expect(slider).toHaveClass('md-min');
224+
225+
slider.triggerHandler({type: '$md.dragstart', pointer: {x: 0}});
226+
slider.triggerHandler({type: '$md.drag', pointer: {x: 10}});
227+
$timeout.flush();
228+
expect(slider).not.toHaveClass('md-min');
229+
});
230+
231+
it('should add md-max class only when at max value', function() {
232+
var slider = setup('ng-model="model" min="0" max="30"');
233+
pageScope.$apply('model = 30');
234+
expect(slider).toHaveClass('md-max');
235+
236+
slider.triggerHandler({type: '$md.dragstart', pointer: {x: 30}});
237+
slider.triggerHandler({type: '$md.drag', pointer: {x: 10}});
238+
$timeout.flush();
239+
expect(slider).not.toHaveClass('md-max');
240+
});
241+
242+
220243
it('should increment at a predictable step', function() {
221244

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

0 commit comments

Comments
 (0)