Skip to content

Commit

Permalink
fix(slider): unable to reset tickInterval after it has been set (#3488)
Browse files Browse the repository at this point in the history
Fixes user not being allowed to reset the `tickInterval` after it has been set to a valid value.

Fixes #3452.
  • Loading branch information
crisbeto authored and mmalerba committed Mar 13, 2017
1 parent cdb3763 commit b9b014a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/lib/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ describe('MdSlider', () => {
expect(ticksElement.style.transform).toContain('translateX(9%)');
expect(ticksContainerElement.style.transform).toBe('translateX(-9%)');
});

it('should be able to reset the tick interval after it has been set', () => {
expect(sliderNativeElement.classList)
.toContain('mat-slider-has-ticks', 'Expected element to have ticks initially.');

fixture.componentInstance.tickInterval = null;
fixture.detectChanges();

expect(sliderNativeElement.classList)
.not.toContain('mat-slider-has-ticks', 'Expected element not to have ticks after reset.');
});
});

describe('slider with thumb label', () => {
Expand Down Expand Up @@ -1248,10 +1259,12 @@ class SliderWithStep {
class SliderWithAutoTickInterval { }

@Component({
template: `<md-slider step="3" tickInterval="6"></md-slider>`,
template: `<md-slider step="3" [tickInterval]="tickInterval"></md-slider>`,
styles: [styles],
})
class SliderWithSetTickInterval { }
class SliderWithSetTickInterval {
tickInterval = 6;
}

@Component({
template: `<md-slider thumbLabel></md-slider>`,
Expand Down
10 changes: 8 additions & 2 deletions src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ export class MdSlider implements ControlValueAccessor {
*/
@Input()
get tickInterval() { return this._tickInterval; }
set tickInterval(v) {
this._tickInterval = (v == 'auto') ? v : coerceNumberProperty(v, <number>this._tickInterval);
set tickInterval(value) {
if (value === 'auto') {
this._tickInterval = 'auto';
} else if (typeof value === 'number' || typeof value === 'string') {
this._tickInterval = coerceNumberProperty(value, this._tickInterval as number);
} else {
this._tickInterval = 0;
}
}
private _tickInterval: 'auto' | number = 0;

Expand Down

0 comments on commit b9b014a

Please sign in to comment.