better ux

This commit is contained in:
Andre Landgraf 2019-06-19 23:56:06 +02:00
parent 9f677a631e
commit bfaf980d4a
2 changed files with 8 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "react-datalist-input",
"version": "1.1.33",
"version": "1.1.34",
"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",

View File

@ -63,9 +63,15 @@ class DataListInput extends React.Component {
onClickInput = () => {
const { currentInput, visible, lastValidItem } = this.state;
const { requiredInputLength, dropDownLength, items, match, clearInputOnSelect } = this.props;
const { requiredInputLength, dropDownLength, items, match, clearInputOnSelect, initialValue } = this.props;
const reachedRequiredLength = currentInput.length >= requiredInputLength;
// if user clicks on input field with initialValue,
// the user most likely wants to clear the input field
if ( initialValue && currentInput === initialValue ) {
this.setState( { currentInput: '' } );
}
if ( reachedRequiredLength && !visible ) {
const matchingItems = items.filter( ( item ) => {