fixed bugs

This commit is contained in:
andrelandgraf 2018-07-21 20:31:46 +02:00
parent a66f5cd596
commit 0f725f862e
3 changed files with 17 additions and 5 deletions

View File

@ -112,8 +112,14 @@ class DataListInput extends React.Component {
* @param selectedItem * @param selectedItem
*/ */
onSelect = (selectedItem) => { onSelect = (selectedItem) => {
if (selectedItem.key === this.state.lastValidItem.key) { if (this.state.lastValidItem !== undefined && selectedItem.key === this.state.lastValidItem.key){
// do nothing onClick if key has not change since the last selection // do not trigger the callback function
// but still change state to fit new selection
this.setState({
currentInput: selectedItem.label,
visible: false,
focusIndex: -1,
});
return; return;
} }
// change state to fit new selection // change state to fit new selection

View File

@ -1,6 +1,6 @@
{ {
"name": "react-datalist-input", "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.", "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", "main": "build/index.js",
"repository": { "repository": {

View File

@ -119,8 +119,14 @@ class DataListInput extends React.Component {
* @param selectedItem * @param selectedItem
*/ */
onSelect(selectedItem) { onSelect(selectedItem) {
if (selectedItem.key === this.state.lastValidItem.key) { if (this.state.lastValidItem !== undefined && selectedItem.key === this.state.lastValidItem.key){
// do nothing onClick if key has not change since the last selection // do not trigger the callback function
// but still change state to fit new selection
this.setState({
currentInput: selectedItem.label,
visible: false,
focusIndex: -1,
});
return; return;
} }
// change state to fit new selection // change state to fit new selection