svelte-material-ui icon indicating copy to clipboard operation
svelte-material-ui copied to clipboard

Using select with boolean values causes the label to overlap the selected value

Open jadhindieh opened this issue 2 years ago • 6 comments

Describe the bug When using the select component with options as boolean true or false, the label will initially be correctly displayed. But once I change the selected value and lose focus from the component, the label will go back to the place it would be at when no data is selected.

To Reproduce Consider the following code:

<Select bind:value={bindedValue} label="will not float after select" style="width:100%">
    {#each [true, false] as option}
        <Option value={option}>{option == true ? 'Yes' : 'No'}</Option>
    {/each}
</Select>
  1. Click on the select component
  2. Choose an option
  3. Lose focus from component
  4. See error as screenshot

Expected behavior The label should be floating

Screenshots C53E3D9E-7727-4542-B31A-8220CFB3EA4D_4_5005_c

Desktop (please complete the following information):

  • OS: MacOs
  • Browser Chromium
  • Version 101.0.4932.0

Additional context Debugging the issue further by inspecting the element I saw that when we have a list of strings the class "mdc-floating-label--float-above" is added to the label, but when the option is a boolean, this class is not appended to the label which is causing the text overlap.

jadhindieh avatar Mar 22 '22 15:03 jadhindieh

I'm also getting this issue without using boolean options. Did anyone find a solution?

WillPoulson avatar May 18 '22 13:05 WillPoulson

Seeing this too in v6 beta 16. Two drop downs with the same list, one selected & the other focused.

image

agmcleod avatar Jun 22 '22 14:06 agmcleod

I have also noticed this happening when using objects as the value. Has there been a fix to this issue?

loganwyas avatar Aug 11 '22 19:08 loganwyas

I am noticing the same behavior!

mell0kat avatar Aug 15 '22 18:08 mell0kat

Same with integers too

ctrlsam avatar Sep 05 '22 05:09 ctrlsam

Try pass key in Select

<Select ... key={v => `${v}`}>...</Select>

vettich avatar Sep 05 '22 05:09 vettich

Try pass key in Select

<Select ... key={v => `${v}`}>...</Select>

this solved issue for me

felbsn avatar Oct 19 '22 14:10 felbsn

Yes, the key always needs to be a string, so you can pass a function to the key prop to turn whatever your value is into a string. @loganwyas, same solution as above ^ just return a string that uniquely identifies the object. The last demo on the Select Demos page has an example of that.

hperrin avatar Oct 19 '22 14:10 hperrin

I think I should move that example to be the second one, so it's easier to find.

hperrin avatar Oct 19 '22 14:10 hperrin