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

Floating label on textfield overlaps with input value #165

Closed
Ranguna opened this issue Jul 23, 2018 · 5 comments
Closed

Floating label on textfield overlaps with input value #165

Ranguna opened this issue Jul 23, 2018 · 5 comments

Comments

@Ranguna
Copy link
Contributor

Ranguna commented Jul 23, 2018

The floating lable in a text field overlaps with the input text when it's removed and reset with onblur:

peek 2018-07-23 12-03

Steps to reproduce

Create a text field with an onblur method that resets the value to something else:

import React, { Component } from 'react';
import TextField, {Input} from '@material/react-text-field';
import './App.css';

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {value:"hello"};
  }

  render() {
    return (
      <div className="App">

        <TextField outlined label='Label'>
          <Input
            value={this.state.value}
            onBlur={()=>this.setState({value:"Noooo"})}
            onChange={(e)=>this.setState({value:e.target.value})}
          />
        </TextField>
      </div>
    );
  }
}

export default App;
  1. Delete all content in the input field
  2. Press anywhere outside the text field
  3. Let the bug happen

Maybe a fix could be to reuse the code that checks if there's text in the input when the text field is mounted (this is done to prevent the lable from overlaping the input text when it's mounted in case a value is set from the beginning) to check every time it blurs or every time the class changed to --float-above ?

@moog16 moog16 changed the title Floating lable on textfield overlaps with input value Floating label on textfield overlaps with input value Jul 23, 2018
@moog16
Copy link

moog16 commented Jul 24, 2018

Thanks for filing the issue. I'm able to reproduce and actually get the same effect if i swap out
onBlur={()=>this.setState({value:"Noooo"})} --> onBlur={()=>this.setState({value:"Noooo"})}.

The issue is the react component only updates the value in the textField component onChange. This breaks when anything else updates value (ie. blur, focus). SO I think the solution is moving when the handleValueChange() method is called to componentDidUpdate.

@Ranguna
Copy link
Contributor Author

Ranguna commented Jul 24, 2018

Oh yeah nice and quick fix, great work 👍
Should this be closed now or after the PR merge ?

@moog16
Copy link

moog16 commented Jul 24, 2018

This seemed important and quick :)

We'll leave it open until it is merged into master - Thanks again

@derektumulak
Copy link

I've just run this this issue with some of the fields that I'm using. I'm a bit of a newbie and wondering what the best way is for me to resolve this. Are there any recent best practices?

Thanks in advance!
-Derek

@moog16
Copy link

moog16 commented May 6, 2019

@derektumulak are you still running into this? A codepen/stackblitz will help in helping you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants