Skip to content

mat-select-trigger is invisible if value is undefined or null #7758

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

Closed
hsinyu-chen opened this issue Oct 13, 2017 · 17 comments
Closed

mat-select-trigger is invisible if value is undefined or null #7758

hsinyu-chen opened this issue Oct 13, 2017 · 17 comments
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@hsinyu-chen
Copy link

hsinyu-chen commented Oct 13, 2017

Bug, feature request, or proposal:

md-select-trigger is invisible if value is undefined or null
when MD_PLACEHOLDER_GLOBAL_OPTIONS set to { float: 'always' }(use to show field name)
i cant show 'All' or 'Please Select ... ' on the md-select

What is the expected behavior?

need a way to show hint text / empty option alternative text

What is the current behavior?

mat-select-trigger is invisible if value is undefined or null

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-vyqfqf

What is the use-case or motivation for changing an existing behavior?

use select as a list filter, or form control with a hint text

@hsinyu-chen hsinyu-chen changed the title mat-select-trigger is invisible if FormControl value is undefined or null mat-select-trigger is invisible if value is undefined or null Oct 13, 2017
@andrewseguin andrewseguin assigned mmalerba and kara and unassigned mmalerba Oct 13, 2017
@mmalerba mmalerba self-assigned this Oct 13, 2017
@mmalerba mmalerba added the P2 The issue is important to a large percentage of users, with a workaround label Oct 13, 2017
@crisbeto
Copy link
Member

This is the intended behavior. Options with a value of undefined or null act as blank options which reset the value.

@willshowell
Copy link
Contributor

@crisbeto while this is currently intended behavior, is there any wisdom in always rendering the trigger value if mat-select-trigger is defined?

@mmalerba
Copy link
Contributor

@crisbeto But you should be able to put your own display value for when nothing is selected like "-- Please select --" or something.

@crisbeto
Copy link
Member

crisbeto commented Oct 15, 2017

@mmalerba the problem is knowing when to show it. We probably don't want to show it and float the label on a blank select that the user hasn't interacted with, because it makes it stand out next to other blank fields and we can't know whether a value of undefined came from the consumer passing in undefined or the control not having a value at all. I see a couple of solutions:

  1. Making it so only the undefined options act as resets, while the null ones could be used as the -- Please select -- placeholder. I can see this approach being a little confusing for users.
  2. Instead of floating the label for undefined and null, we replace it with the option's label. This could be a little confusing API-wise, because it makes the options act as placeholder text, but it seems like it might be what we want.

@mmalerba
Copy link
Contributor

I see. I have an issue filed for input to separate the concept of label vs placeholder (#6194) to make it match the latest mocks. Maybe a similar sort of thing could work for the select, when the label floats we reveal the null/undefined display value.

@hsinyu-chen
Copy link
Author

hsinyu-chen commented Oct 16, 2017

Why don't we show the trigger whenever the label floats?
Would it be better if nothing is selected, the text colors are lighter.

@jandsu
Copy link

jandsu commented Oct 23, 2017

I believe that there is similar issue when the select is multiple and no value is selected: the value is then an empty array, evaluating to a falsy value just as null or undefined....

Please let me know if this deserves another issue or not. I wanted to remain on the less-noisy option by default.

@mmalerba
Copy link
Contributor

mmalerba commented Nov 8, 2017

@crisbeto assigning to you since its related to the label / placeholder split

@jelbourn jelbourn added this to the 5.0 milestone Nov 19, 2017
@mmalerba mmalerba removed this from the 5.0 milestone Nov 28, 2017
@PhilHuot
Copy link

PhilHuot commented Dec 1, 2017

ETA on this please?

@ggranum
Copy link

ggranum commented Jan 11, 2018

@crisbeto, regarding when to show it: I would strongly argue that if the value for 'trigger' is not empty, it should always be displayed. The developer has full control over the value provided to the trigger, and with a simple 'Placeholder will not display unless the triggerValue is empty' in the docs, it's clear enough what needs to be done.

If that is not an option, then it should be one, via a flag.

For a use case, I present a multi-select where 'No Selection' is allowed. I would like to display 'All', 'Partial ({{count}})' or 'None'. I cannot display None, because the selection is empty thus the (empty) placeholder is displayed instead.

@k-krupka
Copy link

k-krupka commented Mar 20, 2018

Is there any workaround which is not including extra option for this one?

@kakins
Copy link

kakins commented May 16, 2018

I also have a list of 'All', 'Open', 'Vacant', where the model is a nullable boolean. Choosing 'All' will set the model to null or undefined. If resetting the displayed option to the placeholder value is the 'expected behavior', what then are we supposed to do in situations like I just described?

@hsinyu-chen
Copy link
Author

hsinyu-chen commented Jun 8, 2018

now we have mat-label for this

<mat-form-field>
    <mat-label>Status</mat-label>
    <mat-select placeholder="Please Select">...</mat-select>
</mat-form-field>

@crisbeto I think you can close this issue

@akvaliya
Copy link

akvaliya commented Jul 8, 2019

I have used placeholder & label both. I am still facing the issue. There is a no way for user to know that list is empty. It's just looks like click is not working on select.

I don't understand why this issue is closed.

@hsinyu-chen
Copy link
Author

@akvaliya
https://stackblitz.com/edit/angular-kzuy4y
did you set floatLabel to always ?

@akvaliya
Copy link

akvaliya commented Jul 9, 2019

That's not my requirements. It float on click. User should be able to know that list is empty.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests