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 text-field does not move when value prop changes. #895

Closed
bsswartz opened this issue May 27, 2019 · 5 comments
Closed
Assignees

Comments

@bsswartz
Copy link

bsswartz commented May 27, 2019

image

@moog16
Copy link

moog16 commented May 28, 2019

Can you please provide a stackblitz or code example? It is difficult to diagnose without such.

@bsswartz
Copy link
Author

bsswartz commented Jun 6, 2019

@moog16

Here is a stackblitz: https://stackblitz.com/edit/react-3q3vjk

import React, { Component } from 'react';
import { render } from 'react-dom';
import TextField, {HelperText, Input} from '@material/react-text-field';
import './style.css';
import '@material/react-text-field/dist/text-field.css';

class App extends Component {
  constructor() {
    super();
    this.state = {
      text: ''
    };
    this.onTextChange = this.onTextChange.bind(this);
  }

  onTextChange(evt) {
    this.setState({text:evt.target.value});
  }

  render() {
    return (
      <div>
      <div>
        <TextField
          label='Type here'
          helperText={<HelperText>Help Me!</HelperText>}
        ><Input
           value={this.state.text}
           onChange={this.onTextChange}/>
        </TextField>
      </div>

      <div>
        <TextField
          label='This label should move'
          helperText={<HelperText>Help Me!</HelperText>}
        ><Input
           value={this.state.text}
           onChange={this.onTextChange} />
        </TextField>
      </div>
      </div>
    );
  }
}

render(<App />, document.getElementById('root'));

@bsswartz
Copy link
Author

bsswartz commented Jun 6, 2019

I observe the error using Chrome 74, iOS Safari 12, and Edge 18; it does not seem to be a browser bug.

@Fa-So
Copy link

Fa-So commented Jun 7, 2019

Here it is simulated differently again:
Textfield floating Input problem

import * as React from "react";
import { render } from "react-dom";
import TextField, { Input } from "@material/react-text-field";

import "@material/react-text-field/dist/text-field.css";

const App = (): JSX.Element => {
  const [val, setVal] = React.useState("");
  React.useEffect(() => {
    setVal("Material Components for React");
  }, []);
  return (
    <TextField label="MDC React" outlined={true}>
      <Input value={val} />
    </TextField>
  );
};

const rootElement = document.getElementById("root");
render(<App />, rootElement);

If Textfield is previously initialized with a space, then it works

const [val, setVal] = React.useState("_");

Also in the above case of bsswartz

this.state = {
  text: '  ' <-- space
};

Of course it is not right

@moog16
Copy link

moog16 commented Jun 10, 2019

Gotcha - this is definitely a bug. I'll investigate.

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

4 participants