Fixed tags input autofocus

This commit is contained in:
Alejandro Celaya
2018-08-31 21:19:58 +02:00
parent b0bce7498a
commit fd57d70a0b
2 changed files with 8 additions and 20 deletions

View File

@@ -39,33 +39,24 @@ export class TagsSelectorComponent extends React.Component {
</span>
);
const renderAutocompleteInput = (data) => {
const { addTag, ...rest } = data;
const { addTag, ...otherProps } = data;
const handleOnChange = (e, { method }) => {
if (method === 'enter') {
e.preventDefault();
} else {
rest.onChange(e);
}
method === 'enter' ? e.preventDefault() : otherProps.onChange(e);
};
// eslint-disable-next-line no-extra-parens
const inputValue = (rest.value && rest.value.trim().toLowerCase()) || '';
const inputValue = (otherProps.value && otherProps.value.trim().toLowerCase()) || '';
const inputLength = inputValue.length;
const suggestions = tagsList.tags.filter((state) => state.toLowerCase().slice(0, inputLength) === inputValue);
return (
<Autosuggest
ref={rest.ref}
ref={otherProps.ref}
suggestions={suggestions}
inputProps={{ ...rest, onChange: handleOnChange }}
inputProps={{ ...otherProps, onChange: handleOnChange }}
highlightFirstSuggestion
shouldRenderSuggestions={(value) => value && value.trim().length > 0}
getSuggestionValue={(suggestion) => {
console.log(suggestion);
return suggestion;
}}
getSuggestionValue={(suggestion) => suggestion}
renderSuggestion={(suggestion) => (
<React.Fragment>
<TagBullet tag={suggestion} />