components icon indicating copy to clipboard operation
components copied to clipboard

Can't reset Mat Radio Button

Open izmaylovdev opened this issue 7 years ago • 3 comments

What is the expected behavior?

Button must be unchecked after click on it twice (look at stackblitz).

What is the current behavior?

Model set to 'null' but button is still display as checked.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-mx7uc8?file=app/radio-ng-model-example.ts

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

"@angular/cdk": "7.3.1", "@angular/core": "7.2.4", "@angular/http": "7.2.4", "@angular/forms": "7.2.4", "@angular/common": "7.2.4", "@angular/router": "7.2.4", "@angular/compiler": "7.2.4", "@angular/material": "7.3.1", "web-animations-js": "2.3.1", "@angular/animations": "7.2.4", "@angular/platform-browser": "7.2.4", "angular-in-memory-web-api": "0.5.4", "@angular/material-moment-adapter": "7.3.1", "@angular/platform-browser-dynamic": "7.2.4"

izmaylovdev avatar Feb 13 '19 18:02 izmaylovdev

@izmaylovdev radio button is working as expected. However if you need to reset the radio button. You can use either of the following functions to achieve the same.

  1. setValue(event, season) { event.preventDefault() if (this.favoriteSeason === season) { this.favoriteSeason = null; this.favoriteSeason = null; } else { this.favoriteSeason = season; } }
  2. setValue(season) { if (this.favoriteSeason === season) { this.favoriteSeason = null; setTimeout(() => this.favoriteSeason = null, 0) } else { this.favoriteSeason = season; } }

you can check the updated code here updated stackblitz code

Iamakr avatar Feb 18 '19 21:02 Iamakr

This is working as intended. The behavior matches the native <input type="radio">

(because it is a native radio button under the hood)

jelbourn avatar Feb 20 '19 01:02 jelbourn

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.