diff --git a/lib/DataListInput.js b/lib/DataListInput.js index fde411a..af53bdf 100644 --- a/lib/DataListInput.js +++ b/lib/DataListInput.js @@ -112,8 +112,14 @@ class DataListInput extends React.Component { * @param selectedItem */ onSelect = (selectedItem) => { - if (selectedItem.key === this.state.lastValidItem.key) { - // do nothing onClick if key has not change since the last selection + if (this.state.lastValidItem !== undefined && selectedItem.key === this.state.lastValidItem.key){ + // do not trigger the callback function + // but still change state to fit new selection + this.setState({ + currentInput: selectedItem.label, + visible: false, + focusIndex: -1, + }); return; } // change state to fit new selection diff --git a/package.json b/package.json index 15c3788..d90a87d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-datalist-input", - "version": "1.0.2", + "version": "1.0.3", "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": "build/index.js", "repository": { diff --git a/src/index.js b/src/index.js index 21f698a..3dd0f3f 100644 --- a/src/index.js +++ b/src/index.js @@ -119,8 +119,14 @@ class DataListInput extends React.Component { * @param selectedItem */ onSelect(selectedItem) { - if (selectedItem.key === this.state.lastValidItem.key) { - // do nothing onClick if key has not change since the last selection + if (this.state.lastValidItem !== undefined && selectedItem.key === this.state.lastValidItem.key){ + // do not trigger the callback function + // but still change state to fit new selection + this.setState({ + currentInput: selectedItem.label, + visible: false, + focusIndex: -1, + }); return; } // change state to fit new selection