diff --git a/package.json b/package.json index 14902d6..ce721f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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.", "main": "./lib/DataListInput.js", "license": "MIT", diff --git a/src/DataListInput.jsx b/src/DataListInput.jsx index e3e6985..f7fd376 100644 --- a/src/DataListInput.jsx +++ b/src/DataListInput.jsx @@ -27,6 +27,17 @@ class DataListInput extends React.Component { 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 = () => { window.removeEventListener( 'click', this.onClickCloseMenu ); }