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

[TextField] New line added when value prop is set (multiline is true) and enter is pressed #6990

Closed
sajal50 opened this issue May 29, 2017 · 4 comments
Labels
bug 🐛 Something doesn't work component: TextareaAutosize The React component.

Comments

@sajal50
Copy link
Contributor

sajal50 commented May 29, 2017

Problem description

A new line is added when the value prop is set in TextField (with multiline true), and enter is pressed.

Link to minimal working code that reproduces the issue

https://www.webpackbin.com/bins/-KlGfX7Kl4Q4uqZ7MITB

Go to the textfield and press enter.

Versions

  • Material-UI: 0.18.1
  • React: 15.2
  • Browser: Chrome
@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! labels May 29, 2017
@lindenquan
Copy link

lindenquan commented Jan 2, 2019

This bug still exists in the latest version V3.8.1, when use onKeyDown
here is demo link
https://codesandbox.io/embed/nrryxqw5wm

symptom:
First enter adds a new line. The following enters work fine.

work round:
use onKeyUp instead of onKeyDown

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 2, 2019

@lindenquan Your bug report is incomplete (browser version, I can't reproduce). If you believe it's an issue, please open a new one following our template. Alternatively, could it be a duplicate of #12172?

@joshwooding
Copy link
Member

@oliviertassinari I think I know what they mean
multiline

this is solved by adding event.preventDefault();

keyPress= (event)=>{
    if (event.keyCode === 13) {
      console.log(event.target.value);
      this.setState({
        multiline: '',
      });
+     event.preventDefault();
    }
  }

@lindenquan
Copy link

lindenquan commented Jan 2, 2019

Thanks @joshwooding
You solved my problem, I couldn't figure it out yesterday

@oliviertassinari oliviertassinari added component: TextareaAutosize The React component. and removed component: text field This is the name of the generic UI component, not the React module! labels Apr 5, 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 component: TextareaAutosize The React component.
Projects
None yet
Development

No branches or pull requests

4 participants