-
Notifications
You must be signed in to change notification settings - Fork 6.8k
mat-select does not display default (null) option text in mat-option #25120
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 Given this was a deliberate decision, is this considered working as intended? Or would you like to revisit this eventually? |
Yes, this is working as expected. The idea was to mimic the behavior of the native |
@wagnermaciel @crisbeto Sorry, but that is not an answer. You haven't answered any of the questions that I've asked:
I honestly don't get your reasoning. This is a needless limitation that is making a super common use case (optional filters, "ALL" options etc) nearly impossible to implement (at least without a totally dirty workaround, that needs to be repeated for every single You could at least make it optional. Instead of forcing a opinionated, weird, behaviour like this, for no good reason. So no... this issues isn't "completed"... you are just refusing to address it... again, for no good reason. Read the original thread... there are millions of use cases where this behaviour doesn't make any sense. So far I haven't seen a single one where it would be desirable. To me this looks like a case of a bruised ego. Instead of making it right, you refuse to acknowledge the fact that you made a poor design choice |
You still have the ability to control what the trigger looks like using the |
@crisbeto No you don't. I tried that already. Here is a stackblitz example: The custom trigger is not shown either if These lines are the problem: components/src/material/select/select.html Lines 16 to 22 in 8ca012f
Others have reported this already in the original thread. There doesn't seem to be a clean workaround for this, not even close. |
Alright, I'll reopen the issue but it's worth noting that there are other use cases that need to be considered. E.g. if we were to match the reset option to its label, the user won't have a way to put the select back into its initial state after selecting something. |
Thanks. As others have suggested in the original thread. And please don't treat This isn't ideal either, since that would still require us to define union types all over the place (e.g. In my opinion, the cleanest solution is to make this behaviour optional with a boolean input binding. Let the users choose the behaviour they want. Everything else is opinionated and limiting, in one direction or another. |
Users may find that weird though since the form field around the select changes if a value is shown. For example you could have an empty form with a few |
FormControls change undefined values to null. |
True. But the current behaviour is even more weird. You select something (with an "empty" value) and it just disappears. This is a functionality issue, compared to the opposite which is a UX issue, at best. Although I don't think this decision should be affected by your touched state argument. The floating label doesn't represent if something has been touched or not. It represents if the value is empty or not. e.g. take a normal Making this optional is the cleanest way to go. Let the devs decide what is less weird for their use case.
Yeah, true, I think this is weird as well. Angular.Components.-.Select.with.custom.trigger.text.-.StackBlitz.-.Google.Chrome.2022-06-29.11-51-13.mp4 |
Hey @zolakt, I wanted to thank you for the engagement in this issue and all the helpful information. Going up the thread:
I want to ensure that we're all focused on improving Angular, and I'd recommend assuming good intentions. Such statements and personal attacks are not welcome in our communication channels. Let's stick to a constructive tone and collaborative environment. |
@mgechev I apologise for the harshness, it was impulsively written. There was no bad intention. In my defence, it can be frustrating to try to get you guys into an argumented discussion. So again, I'm sorry if I offended anyone. |
Any movement on this? it would be really nice to have mat select respect null value display text. |
Any news here ? |
5 years and we still don't have a solution or a workaround. Very frustrating. |
@mgechev @zolakt Please, we need this. Mapping to |
While I do think the tone of this issue is far too harsh (bad decisions happen, and it's not always easy to undo the consequences), I also want to advocate for the ability to map to |
@GabrielBB Why are you asking me :) I'm in the same boat as everyone else here, waiting for someone to finally fix this after 5+ years. The only workaround I have is to use 0 instead, which is incredibly stupid and tedious to maintain, but I found no better workaround |
My vote here as well, why do we need to think every time about what value to use for the "All" option, why to choose from nonlogical values ('', '-', '-1', '0' etc.) while "null" would be ideal... |
I agree that mapping to
The downsides to this workaround:
|
This gif is basically the crux of the entire issue. My client just told me he wanted to see 'All' as the displayed value for empty field in one of the dropdowns inside his form. That grey-out by default behavior is awkward for sure. EDIT: I think (Jwess' idea of making the text for the empty-valued mat-option to be the same as the placeholder) + (styling the placeholder to not be greyed-out) is the only way to work around this for now |
Just wanted to chime in, the suggested workaround with <mat-select-trigger>
{{ foodCtrl.value ? foodCtrl.value : 'I am null' }}
</mat-select-trigger> And it still displays the placeholder text, even though the value is This stackblitz exhibits the problem with and without the mat-select-trigger, alongside a native select that works as intended: https://stackblitz.com/edit/4mzrpg?file=src%2Fexample%2Fselect-overview-example.html |
Best workaround I have found is to set the placeholder text to whatever you want to display for null and set floatLabel="always" on the mat-form-field |
I need that allows me to "clear" (with 'X' button on the control) and set default key/value where value is some string like "Make your selection" or "-- None --" which will be persisted as the absence of a selection ("null") in my model. My attempt that uses default option item and ngStyle to hide: https://stackblitz.com/edit/4mzrpg-8rgyyg |
Any updates? |
Please, make this change, guys. |
Not sure where you have seen a workaround suggestion with Although, I highly doubt anyone will ever fix that code, even after pointing out the exact problematic line. Personally, I've given up on waiting for this. The stupid workaround will have to do. If you wait for these guys to fix anything, you will never finish a single project. Now I'll probably get downvoted for pointing out the obvious, but sadly, that is reality... The issue has been reported 7 years ago... |
Given that the fix on the surface levels seems to be changing components/src/material/select/select.ts Line 1110 in 5398170
|
How can this be bugged? Seriously. |
For me the default value dose not get displayed at all. <mat-form-field appearance="outline">
<mat-label>{{ 'FIELD' | translate }}</mat-label>
<mat-select
[disabled]="isReadOnly$ | async"
placeholder="{{ 'FIELD_PLACEHOLDER' | translate }}"
(valueChange)="item.field.next($event)"
[value]="item.field | async"
>
@for (item of OTHER.FIELD_TYPES_ARRAY; track item) {
<mat-option [value]="item">{{ item }}</mat-option>
}
</mat-select>
</mat-form-field> |
Any news on this one? We need to support null for mat-select as @zolakt mentioned > "It is an explicit value" of none. still doesn't show/override if the control value is null. (link is here #7758) Should we use workarounds or tricks or can we just add support for null to make the mat-select more flexible? |
Totally need this fix as well. |
Please, it is necesary... |
…ble options By default `mat-select` treats options with nullable values as "reset options", meaning that they can't be selected, but rather they clear the select's value. This behavior is based on how the native `select` works, however in some cases it's not desirable. These changes add an input that users can use to opt out of the default behavior. Fixes angular#25120.
…ble options By default `mat-select` treats options with nullable values as "reset options", meaning that they can't be selected, but rather they clear the select's value. This behavior is based on how the native `select` works, however in some cases it's not desirable. These changes add an input that users can use to opt out of the default behavior. Fixes angular#25120.
…ble options (#30142) By default `mat-select` treats options with nullable values as "reset options", meaning that they can't be selected, but rather they clear the select's value. This behavior is based on how the native `select` works, however in some cases it's not desirable. These changes add an input that users can use to opt out of the default behavior. Fixes #25120. (cherry picked from commit 0296713)
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
I'm reposting this issue again: #6466
since you closed it without providing any reasonable workaround or an explanation why you chose to implement this super weird, opinionated, behaviour. What is the reason to implement it like this? What problems does you implementation solve or prevent? From what I can see, it's just limiting a very common use-case, without any reasonable benefits. If you really insist on this, at least make it optional with an input binding, so we can opt-out of it when we don't need it.
The only workaround for this is to use some other value, e.g. '' and then map it back and forth all over the place, for each mat-select. Honestly this is ridiculous. Totally messy, bug prone etc. and still a very poor workaround.
I haven't found a single workaround that would enable the desired behaviour in the use-case when you have your own component, implementing control value accessor, which wraps a mat-select.
Reproduction
http://plnkr.co/edit/i919jzNOoXhlPeN4hxxE?p=preview
Expected Behavior
Select should display text associated with null/undefined value when provided
Actual Behavior
Select displays nothing
Environment
The text was updated successfully, but these errors were encountered: