Description
Using the 'templates' option in tandem with 'defaultValue' results in an empty (or undefined) suggestion when you've give focus to the input.
I've created a codepen to show the scenario and detailed repro steps are below.
In this example, the suggestion is 'undefined':
because I'm returning undefined from the suggestion
function, but if you return empty string then you still get an 'empty' suggestion:
This is somewhat related to #240 (I think), in that my issue is only manifesting itself, because of the behavior from #240.
Repro steps
- Set the
defaultValue
property - Set the
templates.inputValue
to a function - Set the
templates.suggestion
to a function - Click on the input to give it focus
Expected result
Nothing happens
Actual result
A sugestion of undefined appears
Suggested fix
I think this is because inside autocomplete.js the initial options
state doesn't use the isQueryAnOption
function, which in turn uses templateInputValue
. So line 65 could be:
-options: props.defaultValue ? [props.defaultValue] : [],
+options: this.isQueryAnOption(props.defaultValue, [props.defaultValue]) ? [props.defaultValue] : [],
OR we change the options.map call within the render, to only render options where the result of this.templateSuggestion(option)
is not falsey.
I think the second option is better, but would appreciate any comments!