Skip to content

Commit

Permalink
feat(slider): implement ControlValueAccessor setDisabledState (#1603)
Browse files Browse the repository at this point in the history
This enables controlling the disabled state of a slider using a custom form control's
`enable()` and `disable()` methods.
  • Loading branch information
MikeRyanDev authored and jelbourn committed Oct 26, 2016
1 parent ff84842 commit 437ec8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/slider/slider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,24 @@ describe('MdSlider', () => {
expect(sliderInstance.value).toBe(7);
});

it('should update the disabled state when control is disabled', () => {
expect(sliderInstance.disabled).toBe(false);

testComponent.control.disable();
fixture.detectChanges();

expect(sliderInstance.disabled).toBe(true);
});

it('should update the disabled state when the control is enabled', () => {
sliderInstance.disabled = true;

testComponent.control.enable();
fixture.detectChanges();

expect(sliderInstance.disabled).toBe(false);
});

// TODO: Add tests for ng-pristine, ng-touched, ng-invalid.
});

Expand Down
7 changes: 7 additions & 0 deletions src/lib/slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,13 @@ export class MdSlider implements AfterContentInit, ControlValueAccessor {
registerOnTouched(fn: any) {
this.onTouched = fn;
}

/**
* Implemented as part of ControlValueAccessor
*/
setDisabledState(isDisabled: boolean) {
this.disabled = isDisabled;
}
}

/**
Expand Down

0 comments on commit 437ec8e

Please sign in to comment.