react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

AutocompleteInput suggestions list is displayed after request even when user pick an option or leave the input

Open kamil-borecki opened this issue 8 years ago • 8 comments

What you were expecting: After autocompleteInput blur or after user pick an option the list of suggestions should not appear. It should be displayed only when user change textinput manually What happened instead: After autocompleteInput blur or after user pick an option the list of suggestions appears.

it looks like after new option is picked there is send a new request to the backend for a list of suggestions and after this request suggestions list is displayed to the user no meter if user exit the input or just picked one of the suggestions image

Steps to reproduce: I am using api-platform/admin with HydraClient

Related code:

const getNameText = object => {
  return object.name || '';
};


<ReferenceInput className={classes.inputBlock} {...rest} label="Account" source="account" reference="accounts"
                              filterToQuery={searchText => ({ name: searchText })} validate={required()}>
                <AutocompleteInput optionText={getNameText} inputValueMatcher={() => null}/>
              </ReferenceInput>

Environment

  • React-admin version: 2.3.0
  • Last version that did not exhibit the issue (if applicable):
  • React version: 16.5.0
  • Browser: Google Chrome 69.0.3497.100
  • Stack trace (in case of a JS error): no error

kamil-borecki avatar Oct 09 '18 10:10 kamil-borecki

I can't reproduce the issue on the simple example. Can you provide a CodeSandbox showing the issue?

fzaninotto avatar Oct 11 '18 15:10 fzaninotto

Maybe duplicated of : https://github.com/marmelab/react-admin/issues/2428

Oupsla avatar Oct 29 '18 08:10 Oupsla

Bump, can you please provide a way to reproduce the issue?

fzaninotto avatar Oct 30 '18 23:10 fzaninotto

Here : https://codesandbox.io/s/lrro0q4wnm

Go to the custom page, then write something (like omnis) in the autocomplete input and then select something (and the selection container will open again)

Oupsla avatar Oct 31 '18 08:10 Oupsla

Looks like a duplicated of #2428 indeed.

Setting focusInputOnSuggestionClick={false} on the AutoSuggest component like @FACOLOMBANI suggested here fixed the issue in my case (after creating a custom AutocompleteInput component).

ArnaudD avatar Nov 12 '18 12:11 ArnaudD

quick-and-dirty fix (instead of creating a custom AutocompleteInput component) :

import Autosuggest from 'react-autosuggest';
Autosuggest.defaultProps.focusInputOnSuggestionClick = false;

ArnaudD avatar Nov 12 '18 13:11 ArnaudD

@ArnaudD

This works on my form fields but not within my arrayInput fields. On edit, it breaks the onChange completely. Seems a viable temp fix if you aren't using arrayInput, however.

fancyaction avatar Nov 12 '18 16:11 fancyaction

Closed as duplicate of #2428, which I just reopened.

fzaninotto avatar Nov 13 '18 08:11 fzaninotto