Skip to content

Commit 8ee8c87

Browse files
committed
fix(checkbox, input, radio, slide-toggle): implement setDisabledState from ControlValueAccessor
Implements the `setDisabledState` method from the `ControlValueAccessor` interface in all of the input-related components, in order to support disabling via reactive forms. Note that the `select` component is missing the implementation, however there's a pending PR for it already (#1667). Fixes #1171.
1 parent a0d85d8 commit 8ee8c87

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/lib/checkbox/checkbox.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ export class MdCheckbox implements ControlValueAccessor {
241241
this.onTouched = fn;
242242
}
243243

244+
/**
245+
* Implemented as a part of ControlValueAccessor.
246+
*/
247+
setDisabledState(isDisabled: boolean) {
248+
this.disabled = isDisabled;
249+
}
250+
244251
private _transitionCheckState(newState: TransitionCheckState) {
245252
let oldState = this._currentCheckState;
246253
let renderer = this._renderer;

src/lib/input/input.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
292292
this._onTouchedCallback = fn;
293293
}
294294

295+
/**
296+
* Implemented as a part of ControlValueAccessor.
297+
*/
298+
setDisabledState(isDisabled: boolean) {
299+
this.disabled = isDisabled;
300+
}
301+
295302
/** TODO: internal */
296303
ngAfterContentInit() {
297304
this._validateConstraints();

src/lib/radio/radio.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ export class MdRadioGroup implements AfterContentInit, ControlValueAccessor {
224224
registerOnTouched(fn: any) {
225225
this.onTouched = fn;
226226
}
227+
228+
/**
229+
* Implemented as a part of ControlValueAccessor.
230+
*/
231+
setDisabledState(isDisabled: boolean) {
232+
this.disabled = isDisabled;
233+
}
227234
}
228235

229236

src/lib/slide-toggle/slide-toggle.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ export class MdSlideToggle implements AfterContentInit, ControlValueAccessor {
174174
this.onTouched = fn;
175175
}
176176

177+
/**
178+
* Implemented as a part of ControlValueAccessor.
179+
*/
180+
setDisabledState(isDisabled: boolean): void {
181+
this.disabled = isDisabled;
182+
}
183+
177184
@Input()
178185
get checked() {
179186
return !!this._checked;

0 commit comments

Comments
 (0)