set initalValue with every clean update

This commit is contained in:
Andre Landgraf 2019-06-20 12:41:04 +02:00
parent aad04be942
commit c7579022c2
2 changed files with 12 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "react-datalist-input", "name": "react-datalist-input",
"version": "1.1.35", "version": "1.1.36",
"description": "This package provides a react component as follows: an input field with a drop down menu to pick a possible option based on the current input.", "description": "This package provides a react component as follows: an input field with a drop down menu to pick a possible option based on the current input.",
"main": "./lib/DataListInput.js", "main": "./lib/DataListInput.js",
"license": "MIT", "license": "MIT",

View File

@ -27,6 +27,17 @@ class DataListInput extends React.Component {
window.addEventListener( 'click', this.onClickCloseMenu, false ); window.addEventListener( 'click', this.onClickCloseMenu, false );
} }
componentDidUpdate = () => {
const { currentInput, visible } = this.state;
const { initialValue } = this.props;
// if we have an initialValue, we want to reset it everytime we update and are empty
// also setting a new initialValue will trigger this
if ( !currentInput && initialValue && !visible ) {
this.setState( { currentInput: initialValue } );
}
}
componentWillUnmount = () => { componentWillUnmount = () => {
window.removeEventListener( 'click', this.onClickCloseMenu ); window.removeEventListener( 'click', this.onClickCloseMenu );
} }