Skip to content

Commit 49eea2b

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 ba31c72 commit 49eea2b

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
@@ -442,6 +442,14 @@ describe('MatRadio', () => {
442442
radioLabelElements[2].click();
443443
fixture.detectChanges();
444444

445+
expect(groupNgModel.valid).toBe(true);
446+
expect(groupNgModel.pristine).toBe(false);
447+
expect(groupNgModel.touched).toBe(false);
448+
449+
// Blur the input element in order to verify that the ng-touched state has been set to true.
450+
// The touched state should be only set to true after the form control has been blurred.
451+
dispatchFakeEvent(innerRadios[2].nativeElement, 'blur');
452+
445453
expect(groupNgModel.valid).toBe(true);
446454
expect(groupNgModel.pristine).toBe(false);
447455
expect(groupNgModel.touched).toBe(true);

src/lib/radio/radio.ts

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

567567
if (this.radioGroup) {
568568
this.radioGroup._controlValueAccessorChangeFn(this.value);
569-
this.radioGroup._touch();
570569
if (groupValueChanged) {
571570
this.radioGroup._emitChangeEvent();
572571
}

0 commit comments

Comments
 (0)