Skip to content

Commit cc87f0a

Browse files
committed
fix(radio): ng-touched incorrectly being set on click
* The `ControlValueAccessor` `onTouched` should be just called if a radio-button blurred. Right now, the `ng-touched` state will be immediately set if someone presses SPACE or clicks on a radio-button.
1 parent 1e1751f commit cc87f0a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib/radio/radio.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ describe('MatRadio', () => {
450450
radioLabelElements[2].click();
451451
fixture.detectChanges();
452452

453+
expect(groupNgModel.valid).toBe(true);
454+
expect(groupNgModel.pristine).toBe(false);
455+
expect(groupNgModel.touched).toBe(false);
456+
457+
// Blur the input element in order to verify that the ng-touched state has been set to true.
458+
// The touched state should be only set to true after the form control has been blurred.
459+
dispatchFakeEvent(innerRadios[2].nativeElement, 'blur');
460+
453461
expect(groupNgModel.valid).toBe(true);
454462
expect(groupNgModel.pristine).toBe(false);
455463
expect(groupNgModel.touched).toBe(true);

src/lib/radio/radio.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,6 @@ export class MatRadioButton extends _MatRadioButtonMixinBase
563563

564564
if (this.radioGroup) {
565565
this.radioGroup._controlValueAccessorChangeFn(this.value);
566-
this.radioGroup._touch();
567566
if (groupValueChanged) {
568567
this.radioGroup._emitChangeEvent();
569568
}

0 commit comments

Comments
 (0)