mirror of
https://github.com/danog/react-datalist-input.git
synced 2024-12-02 09:27:53 +01:00
logical bug fixing
This commit is contained in:
parent
1f410009bc
commit
0e4e12eb05
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-datalist-input",
|
||||
"version": "1.1.23",
|
||||
"version": "1.1.26",
|
||||
"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",
|
||||
|
@ -10,6 +10,7 @@
|
||||
background-color: #f1f1f1;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
.datalist-items {
|
||||
|
@ -63,16 +63,23 @@ class DataListInput extends React.Component {
|
||||
const { currentInput, visible, lastValidItem } = this.state;
|
||||
const { requiredInputLength, dropDownLength, items, match, clearInputOnSelect } = this.props;
|
||||
const reachedRequiredLength = currentInput.length >= requiredInputLength;
|
||||
|
||||
if ( reachedRequiredLength && !visible ) {
|
||||
|
||||
const matchingItems = items.filter( ( item ) => {
|
||||
if ( typeof ( match ) === typeof ( Function ) ) { return match( currentInput, item ); }
|
||||
return this.match( currentInput, item );
|
||||
} );
|
||||
const displayableItems = matchingItems.length
|
||||
? matchingItems : items.slice( 0, dropDownLength )
|
||||
|
||||
const currentInputIsLastItem =
|
||||
!clearInputOnSelect && lastValidItem && lastValidItem.label === currentInput;
|
||||
const displayableItems = matchingItems.length && !currentInputIsLastItem
|
||||
? matchingItems : items.slice( 0, dropDownLength );
|
||||
|
||||
let index = lastValidItem && !clearInputOnSelect
|
||||
? this.indexOfItem( lastValidItem, displayableItems ) : 0;
|
||||
index = index > 0 ? index : 0;
|
||||
|
||||
this.setState( { visible: true, matchingItems: displayableItems, focusIndex: index, } );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user