Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tinayuangao committed May 23, 2017
1 parent e1a3618 commit 0e4dfdc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lib/radio/radio.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('MdRadio', () => {
});

it('should not show ripples on disabled radio buttons', () => {
radioInstances[0].disabled = true;
testComponent.isFirstDisabled = true;
fixture.detectChanges();

dispatchFakeEvent(radioLabelElements[0], 'mousedown');
Expand All @@ -238,7 +238,7 @@ describe('MdRadio', () => {
expect(radioNativeElements[0].querySelectorAll('.mat-ripple-element').length)
.toBe(0, 'Expected a disabled radio button to not show ripples');

radioInstances[0].disabled = false;
testComponent.isFirstDisabled = false;
fixture.detectChanges();

dispatchFakeEvent(radioLabelElements[0], 'mousedown');
Expand Down
21 changes: 14 additions & 7 deletions src/lib/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,7 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase

set labelPosition(v) {
this._labelPosition = (v == 'before') ? 'before' : 'after';
if (this._radios) {
this._radios.forEach(radio => radio._groupValueChanged());
}
this._markRadiosForCheck();
}

/** Value of the radio button. */
Expand Down Expand Up @@ -186,7 +184,7 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
this._disabled = value;
if (this._radios) {
// Update radios disabled state
this._radios.forEach((r) => r._groupValueChanged());
this._radios.forEach((r) => r._markForCheck());
}
}

Expand Down Expand Up @@ -249,6 +247,12 @@ export class MdRadioGroup extends _MdRadioGroupMixinBase
}
}

_markRadiosForCheck() {
if (this._radios) {
this._radios.forEach(radio => radio._markForCheck());
}
}

/**
* Sets the model value. Implemented as part of ControlValueAccessor.
* @param value
Expand Down Expand Up @@ -403,8 +407,6 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
}
set disabled(value: boolean) {
this._disabled = coerceBooleanProperty(value);
// Update rippleDisabled
this._changeDetector.markForCheck();
}

/**
Expand Down Expand Up @@ -466,7 +468,12 @@ export class MdRadioButton implements OnInit, AfterViewInit, OnDestroy {
this._focusOriginMonitor.focusVia(this._inputElement.nativeElement, this._renderer, 'keyboard');
}

_groupValueChanged() {
/**
* Marks the radio button as needing checking for change detection.
* This method is exposed because the parent radio group will directly
* update bound properties of the radio button.
*/
_markForCheck() {
// When group value changes, the button will not be notified. Use `markForCheck` to explicit
// update radio button's status
this._changeDetector.markForCheck();
Expand Down

0 comments on commit 0e4dfdc

Please sign in to comment.