-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
md-select does not display default (null) option text in mat-select-value #6466
Comments
#3341 allows you to define the trigger value |
Thanks for the quick response. I can see how that would help work around the issue but... Are we saying that the If there will be some default behavior and it is to display the text between the selected |
It'll only be required if you want to customize the display value. I can't answer your question, but to put it another way:
cc @crisbeto |
|
If providing a It just seems unexpected when |
Closing as working as intended. As noted above, this was a deliberate choice made in the |
@willshowell |
@dynameis open a new issue about it. It seems like a reasonable request and is different from the one here. |
So what's the recommendation when an item in your list has a 'value' that truly is null and you want it selected? For example I have a list of dates for a search filter : 'Today', 'Yesterday', 'Last 7 days', 'All' The type of (a) The alternative would be DateTime.MinValue or 9999999 But I run into this issue. I just don't understand why IF an item with an explicit value of null exists (and the developer clearly added one with a null value) that they shouldn't expect it to be auto selected. You said "If we went back to the old behavior it would mean that we'd have to show the empty option's label for untouched selects" - but so what! - this would ONLY be a problem if someone had added an option with a null value that wasn't intended to be the default - and if that were really the case what were they expecting it to do - just give that item a non null value. I really don't see how the 'old behavior' leads to undesirable behavior because if you really don't like it you can just give everything a value? Perhaps more to the point is I feel the 'old' way is a much more common situation (filtering being the prime example) - and also the expected behavior. Maybe I have to make the type Edit: For me the solution that worked was to use
|
This is a major disappointment for us. We're migrating material1 to material2 and relied heavily on null options in selects to represent 'Any' for filtering. The problem is that now an 'Any' selection with an already bound null value will trigger an unnecessary change event. The best solution I see is from @simeyla which is to set the value to '', but of course now our typing is hacky, e.g. boolean|string etc. so this hopefully something that will be addressed. For reference:
|
I also think this is a poor design choice. I'm having the same issue in that the selection of the value 'null' actually is a valid option in itself and presented to the user as "Inactive" instead of just a blank field. Right now, I'm working around this by having the "placeholder" attribute being "Inactive". But semantically that doesn't feel right, more like a workaround than a deliberate choice. Also this doesn't allow me to force the user to actively pick "Inactive" as an option, it's always the default when nothing else is selected. |
I have to do all kind of hacks to work around this issue. |
I also find this extremely frustrating and a prime example of when an opinionated framework takes things too far. NULL IS A VALID OPTION and an option with that exact value should absolutely appear rendered in the control and not just silently discarded. For that matter any exact equality should work, why impose this falsey / discard approach? It's absurd. I've lost half a day trying to get this working and my solution has been hacky at best, since EVEN IF you use a |
Definitely frustrating and a lots of extra-work needed for a completely weird behaviour. As the others here said, we're also facing a situation when we WANT to have null to be selected as our default value, instead of that now we are using a constant that we need to convert to null everywhere we need it. This is ridiculous. |
I wonder if it couldn't work like it currently does UNLESS there is a mat-option with null value specified. Is it not possible to do? |
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. |
Bug, feature request, or proposal:
Bug
What is the expected behavior?
Select should display text associated with null/undefined value when provided
What is the current behavior?
Select displays nothing
What are the steps to reproduce?
http://plnkr.co/edit/i919jzNOoXhlPeN4hxxE?p=preview
What is the use-case or motivation for changing an existing behavior?
Adding a default option with text for a null value should result in displaying the text when the current model value is null.
For example, adding a default option with text "None"
<md-option>None<md-option>
should show "None" when the select list is closed.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular: 4.3.4
Material: Beta 8
The text was updated successfully, but these errors were encountered: