Skip to content
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

select-field incorrectly displays floatingLabelText #1427

Closed
martinhoefling opened this issue Aug 16, 2015 · 12 comments
Closed

select-field incorrectly displays floatingLabelText #1427

martinhoefling opened this issue Aug 16, 2015 · 12 comments
Labels
bug 🐛 Something doesn't work

Comments

@martinhoefling
Copy link

Rendering sth. like:

            <SelectField
                floatingLabelText='Client'
                style={{ width: '100px' }}
                menuItems={clientMenuItems}
                selectedIndex={this.props.clients.indexOf(this.props.currentClient)}
                onChange={this.onClientChange}/>

client menu items is an array of objects with text and payload.

The floatingLabelText is only correctly placed when another item is selected and the select is focused. As soon as I focus another element. The floatingLabelText is fullsizeGray overlapping with the selected element in black / same fontsize.

material-ui version: 0.10.4

@cbioley
Copy link

cbioley commented Aug 17, 2015

For what it's worth, I've got the same problem.

Edit: Doh, I lied. Now that I restarted Meteor, I only have the overlapping issue when the field is initially shown. When I choose any items and focus out of the field, the label stays in right position.

@martinhoefling
Copy link
Author

@cbioley, in my case after focus is lost, the label goes back to the wrong position.

@martinhoefling
Copy link
Author

I "fixed" it in my case by adding
floatingLabelStyle={ { transform: 'perspective(1px) scale(0.75) translate3d(2px, -28px, 0)' } }
to my SelectField. What would be the proper solution in upstream? Setting this transform? Setting a value?

@manuelmazzuola
Copy link

The same for me, @martinhoefling's fix works 👍

@neverfox
Copy link
Contributor

I was running into this until I set the value of the selected element explicitly through the value prop. An item will appear to be selected if you leave that out, but it's not as far as the component is concerned (i.e. triggering the rising label of the underlying text field works the same way, by making room for the value; no value, no room is made).

@cgwyllie
Copy link
Contributor

cgwyllie commented Nov 9, 2015

+1 I am seeing this issue, and setting a value prop fixes the initial render as @neverfox describes. (material-ui 0.13.1, react 0.14.2)

@alitaheri alitaheri added the bug 🐛 Something doesn't work label Dec 8, 2015
@bendiy
Copy link

bendiy commented Dec 16, 2015

I've ran into this issue and it is only happening when onChange is set to a function, but a value isn't set. If I leave onChange off, the floatingLabelText floats to the top like it should when selecting an option. If I have an onChange function that also updates the state property value is using, it works correctly. Note, the floatingLabelText floats to the top initially, but when the SelectField looses focus, it drops back down.

const myMenuItemsArray = [
  {"payload": "0", "text": ""}, // Makes default empty.
  {"payload": "1", "text": "Red"},
  {"payload": "2", "text": "Green"}, 
  {"payload": "3", "text": "Blue"}
];
handelSelectFieldChange =(name, event) {
  const {dispatch, myState} = this.props;
  const fieldId = event;
  dispatch(setFieldId(fieldId, myState)); // Actiont that sets `myState.fieldId = fieldId`;
};

This works correctly, but isn't very useful:

<SelectField
  floatingLabelText="Color"
  menuItems={ myMenuItemsArray } />

color-1

This doesn't work. floatingLabelText doesn't float above the field when a color is selected. Note, no value set:

<SelectField
  floatingLabelText="Color"
  onChange={ this.handelSelectFieldChange }
  menuItems={ myMenuItemsArray } />

color-2

This does works correctly:

<SelectField
  floatingLabelText="Color"
  value={ myState.fieldId ? myState.fieldId : null} // Using `null` means it's not set, so "Color" is on the SelectField line initially. If this was set to `"0"`, instead of `null`, the floatingLabelText "Color" floats above.
  onChange={ this.handelSelectFieldChange }
  menuItems={ myMenuItemsArray } />

color-1

So this could just be a documentation issue. Make sure when onChange is set, value is also set.

@newoga
Copy link
Contributor

newoga commented Dec 18, 2015

@bendiy Thanks for writing that up. I agree with your observations. I'm actually in the middle of refactoring some of the TextField code that controls this logic at the moment. And you are correct.

The SelectField uses a TextField internally to control floating labels. The conditions in which the floating label is displayed as floating text vs as hint text is not intuitive. Unfortunately I don't think my refactoring will be able to fix this until we do #2416. I'll update this if anything changes.

@aahan96
Copy link
Contributor

aahan96 commented Jun 10, 2016

@newoga @martinhoefling There seems to be no new movement regarding this issue. Can we close this issue?

@martinhoefling
Copy link
Author

martinhoefling commented Jun 12, 2016

@aahan96 So for me the problem is "solved" by adding value. What about #2416?

@aahan96
Copy link
Contributor

aahan96 commented Jun 24, 2016

@martinhoefling Closing this issue. I think work is still going on #2416

@aahan96 aahan96 closed this as completed Jun 24, 2016
@michielreyers
Copy link

This can also be 'solved' by setting floatingLabelFixed to true

mnajdova pushed a commit to mnajdova/material-ui that referenced this issue Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work
Projects
None yet
Development

No branches or pull requests

10 participants