material icon indicating copy to clipboard operation
material copied to clipboard

mdSelect clear selection (unselect)

Open brettstack opened this issue 11 years ago • 16 comments

mdAutocomplete has a cross you can click to clear the value. Something like this would be awesome for mdSelect. Currently it looks like the only way is to add a blank mdOption. If possible, would it make sense to only show this if the mdSelect is not required?

brettstack avatar Mar 13 '15 17:03 brettstack

@ThomasBurleson could we coordinate with the UX team on this and get their thoughts?

rschmukler avatar May 03 '15 18:05 rschmukler

This seems like a good suggestion but I don't think we can get to it before our 1.0 release.

naomiblack avatar Jul 31 '15 01:07 naomiblack

or, selecting the same option again will clear the value and display the placeholder/label

Charlie-Ng avatar Aug 04 '15 22:08 Charlie-Ng

That seems like poor UX

On Tue, 4 Aug 2015 3:35 pm Charlie-Ng [email protected] wrote:

or, selecting the same option again will clear the value and display the placeholder/label

— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/1901#issuecomment-127780777.

brettstack avatar Aug 04 '15 22:08 brettstack

I just feel like this is another way to cancel selection, isn't it?

Charlie-Ng avatar Aug 05 '15 17:08 Charlie-Ng

The standard way to clear a HTML Select field is to add a blank option.

ThomasBurleson avatar Aug 10 '15 17:08 ThomasBurleson

I am facing the same kind of issue with floating label, so I think it might be reopened. My use case :

<md-input-container>
  <label>My Label</label>
  <md-select ng-model="myModel">
    <md-option value=""></md-option>
    <md-option ng-repeat="value in [...]" ng-value="value">{{value}}</md-option>
  </md-select>
 </md-input-container>

Floating label is correct at initialization but when clicking on the empty element the floating label is still up. I also tried with ng-value="undefined" or null and it does not solve it... It seems that the md-select is in a "selected empty value" state which is semantically different from the "back to untouched" state

jpolo avatar Jan 15 '16 10:01 jpolo

I'm facing the same issue that @jpolo said. Floating label does not work correctly with this solution.

cleever avatar Jan 15 '16 11:01 cleever

@jpolo I think what @ThomasBurleson mentioned is you need to have a dropdown option with blank value and value (in controller) should be set to blank instead of setting to null or undefined as HTML treats a blank value dropdown as required and won't allow user to submit form until value is selected.

jayeshanandani avatar Jan 15 '16 12:01 jayeshanandani

Are you suggesting my issue should go in a new issue or what should I do concerning this issue?

jpolo avatar Jan 19 '16 10:01 jpolo

I'm facing the same issue and I use as a fix :

<md-input-container ng-class="{ 'md-undefined-select': !myModel }">
  <label>My Label</label>
  <md-select ng-model="myModel">
    <md-option value="undefined"></md-option>
    <md-option ng-repeat="(key, value) in values" ng-value="key">{{ value }}</md-option>
  </md-select>
 </md-input-container>

And CSS:

.md-undefined-select {
    label {
        transform: translate3d(0, 28px, 0) scale(1) !important;
                color: rgba(0,0,0,0.26) !important;
    }
}

It's unorthodox , but this helps me.

raduburcuta avatar Jan 21 '16 17:01 raduburcuta

Not sure why this isn't supported yet, but here is a hack

HTML

<md-input-container flex="30">
    <label>Account</label>
    <md-select ng-model="product.account">
        <md-option class="empty-value"></md-option>
        <md-option>Cash</md-option>
        <md-option>Bank</md-option>
    </select>
</md-input-container>

CSS (Sass):

md-option
    &.empty-value
        .md-text:after
            content: '- SELECT -'

sheaujye avatar Feb 05 '16 08:02 sheaujye

@raduburcuta @sheaujye your approaches won't if you use placeholder.

Vayvala avatar Feb 11 '16 20:02 Vayvala

bump -ish

New to md and am experiencing this issue also. Is there a solution? The ad-hoc solution is awesome but doesn't address the issue.

@jayeshanandani suggests

you need to have a dropdown option with blank value and value (in controller)

Can someone explain like I'm 5 what he means?

        <label>Status <small>Note: <b style="color:red;">Highlighted content</b></small></label>
        <md-select ng-value="{{marital_status}}" ng-model="marital_status" name="marital_status" id="marital_status">
            <md-option value=""></md-option> <!-- hack see css -->
            <md-option>SINGLE</md-option>
            <md-option>MARRIED</md-option>
            <md-option>DIVORCED</md-option>
            <md-option>WIDOWED</md-option>
            <md-option>SEPARATED</md-option>
        </md-select>

dreaddymck avatar Feb 29 '16 16:02 dreaddymck

@dreaddy : Thomas states that standard HTML way to clear select is to add blank option. That is the same thing I suggested that if you are repeating a md-option loop you just need to add:

<md-option value="">Please Select</md-option>

This option ensures and also helps the user to revert back to a blank value.

jayeshanandani avatar Feb 29 '16 17:02 jayeshanandani

@jayeshanandani Thank you much.

dreaddymck avatar Feb 29 '16 19:02 dreaddymck