tleunen / react-mdl

React Components for Material Design Lite
https://tleunen.github.io/react-mdl/
MIT License
1.76k stars 255 forks source link

TextField `value` prop does not update #446

Open zhenyanghua opened 7 years ago

zhenyanghua commented 7 years ago

The following code discovers the value prop of the Textfield does not get updated programmatically. The clear() function should reset the value of the Textfiled to empty string.

<IconButton name="clear" className="blue" onClick={() => this.clear()}/>
<Textfield
            onKeyUp={(e) => this.onKeyUp(e)}
            label="Search Address, city, zip"
            expandable
            expandableIcon="search"
            floatingLabel
            value={this.state.searchText} />

onKeyUp(e) {
    const term = e.target.value
    this.setState({
      searchText: term
    })
    if (e.keyCode === 13) {
     // do stuff
    }
  }

clear() {
    this.setState({
      searchText: ''
    })
  }
knuterik91 commented 7 years ago

Answered your stackoverflow question here : http://stackoverflow.com/questions/41125726/how-to-programmatically-set-textfield-value/41126246#41126246