Skip to content

Commit 5b04ec3

Browse files
devversionjosephperrott
authored andcommitted
fix(radio): ng-touched incorrectly being set on click (#12560)
* 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 e157740 commit 5b04ec3

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
@@ -456,6 +456,14 @@ describe('MatRadio', () => {
456456
radioLabelElements[2].click();
457457
fixture.detectChanges();
458458

459+
expect(groupNgModel.valid).toBe(true);
460+
expect(groupNgModel.pristine).toBe(false);
461+
expect(groupNgModel.touched).toBe(false);
462+
463+
// Blur the input element in order to verify that the ng-touched state has been set to true.
464+
// The touched state should be only set to true after the form control has been blurred.
465+
dispatchFakeEvent(innerRadios[2].nativeElement, 'blur');
466+
459467
expect(groupNgModel.valid).toBe(true);
460468
expect(groupNgModel.pristine).toBe(false);
461469
expect(groupNgModel.touched).toBe(true);

src/lib/radio/radio.ts

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

554554
if (this.radioGroup) {
555555
this.radioGroup._controlValueAccessorChangeFn(this.value);
556-
this.radioGroup._touch();
557556
if (groupValueChanged) {
558557
this.radioGroup._emitChangeEvent();
559558
}

0 commit comments

Comments
 (0)