1

Is there a way to only turn the autocomplete on after typing lets say three keystrokes? I am currently using the react library react-select.

Ben Bieler
  • 1,518
  • 1
  • 14
  • 22

1 Answers1

1

I would implement to execute asynchronous event after (around) 300ms rather than counting each keystrokes. You can have a look at debounce and persist in here

An Nguyen
  • 1,487
  • 10
  • 21
  • Thanks - Well I would like to count the keystrokes. But how can you call the function to trigger the dropdown? Or how can you prevent the dropdown from showing? – Ben Bieler Aug 10 '17 at 12:30
  • 1
    You can try `filterOption`: https://github.com/JedWatson/react-select#filtering-options. I think counting the `filter.length` and `return false` should works. – An Nguyen Aug 10 '17 at 14:34
  • Thank you for your help! Now the dropdown appears after the third keystroke - prior to that it is disabled. But now the search is not working. Do you know why this could be the case? – Ben Bieler Aug 11 '17 at 10:13
  • 1
    Does this (or similar) : `filterOption(option, filter) { return (filter.length % 3) === 0 ? true : false }` solve your issue ? – An Nguyen Aug 11 '17 at 10:34