-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(select): Fix empty option stlying issue. #8907
fix(select): Fix empty option stlying issue. #8907
Conversation
At a glance, it looks good, but in the demo, is there no text for the blank option? Is it possible to do an italicized ’(None)‘ inside? |
Seems like the word None with no special styling would be the "Material" way |
Is there a reason why you decided to use the absence of the ng-value or value attribute to be the trigger for clearing the select model? The common method is to pass an empty or undefined value. My thinking is that the alteration could be made to the inputCheckValue function we were speaking about before. What do you think? |
I am looking at the difference between a One difference is the My suggestion is to check if the value of
If |
This works when replacing https://github.com/angular/material/blob/master/src/components/select/select.js#L481:
|
@clshortfuse If the option has text (i.e. "None"), then I would expect that text to appear in the input and move the floating label up to make room. In it's current state, it would not do that. If you add "None" as text, and then select that option, it would clear the element and drop the floating label back down. That said, I don't think there is anything stopping someone from doing whatever approach they like since you CAN add "None" if you want. @bradrich Aside from "that's the way the HTML version works", is there an advantage to using a blank value attribute instead of simply not providing one? The disadvantage I see of forcing it to be one of (or multiple of) I am certainly open to thoughts/changes to this. I'd like to do it the "right" way 😄 |
Previously, if you used `ng-value` on your `md-option` and attempted to have an empty option without a value (i.e. `<md-option>Select...</md-option>`), the component would still be in a "has selected value" state causing the floating label to appear among other issues. Add a new `md-option-empty` attribute to `<md-option>` which allows the user to specify the empty option. Additionally, automatically add this attribute for the most common use cases. Update demo/docs to show usage. Fixes angular#6851.
11d205e
to
b9eb9d6
Compare
@clshortfuse @bradrich Made some updates to this PR, it is ready for re-review. |
@topherfangio Look good, though I think you should add some tests related for |
@@ -723,6 +749,11 @@ function SelectMenuDirective($parse, $mdUtil, $mdTheming) { | |||
// Map the given element to its innerHTML string. If the element has a child ripple | |||
// container remove it from the HTML string, before returning the string. | |||
mapFn = function(el) { | |||
// If we do not have a `value` or `ng-value`, assume it is an empty option which clears the select |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be left over from old code. Needs updating or removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed; good catch!
@topherfangio LGTM and ditto on the speedy @clshortfuse who beat me to that comment comment! |
@topherfangio i updated your comment accidently Quick edit: I wouldn't abbreviate |
Previously, if you used
ng-value
on yourmd-option
and attempted to have an empty option without a value (i.e.<md-option>Select...</md-option>
), the component would still be in a "has selected value" state causing the floating label to appear among other issues.Add a new
md-option-empty
attribute to<md-option>
which allows the user to specify the empty option. Additionally, automatically add this attribute for the most common use cases.Update demo/docs to show usage.
Fixes #6851.