-
Notifications
You must be signed in to change notification settings - Fork 6.8k
bug(MatButtonToggle): Button with undefined or null value not selected by default #25472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@crisbeto hello, is this actual issue? if yes, can you please assign this to me if possible! |
It seems like this line could be (at least part of) the problem:
|
@kush-savani yep this is an actual issue, and note that this behaviour is inconsistent with mat-radio-button - there is no null check on the value of the radio buttons for selection. |
When button-toggle have init value as null, it's not get selected. This fix remove condition which stopping null button to select. Fixes angular#25472
It's not obvious to me why |
Hello @andrewseguin, |
Hello @andrewseguin, I need your input on this issue. |
Why would it not be a supported value? The paragraph style from the original post is a perfect example of why it would be valid. I just stumbled upon this problem, too, in my case with a nullable boolean (yes / no / n.a.). A select did not feel like the right control to use, but now I will have to convert the value to a string and back. |
It seems the following workaround (set "checked" explicitly) works fine:
|
When button-toggle have init value as null, it's not get selected. This fix remove condition which stopping null button to select. Fixes #25472
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
The previous version in which this bug was not present was
No response
Description
If one of the buttons in a button toggle group has an unknown or null value in a template-driven page, that button is not selected at page load. Any other default value works fine.
Reproduction
https://stackblitz.com/edit/angular-1hthwq-eq6mud?file=src%2Fapp%2Fbutton-toggle-forms-example.ts,src%2Fapp%2Fbutton-toggle-forms-example.html
This stackblitz example is a fork of the MatButtonToggle example. It adds a "null" value to the set of options and sets that as the default for the model, but the corresponding button is selected only if explicitly chosen.
Expected Behavior
Button corresponding to null value should be selected on page load.
Actual Behavior
No button is chosen on page load.
Environment
The text was updated successfully, but these errors were encountered: