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

Keyboard dissmiss when scrolling suggestions

Open AndradeB91 opened this issue 6 years ago • 6 comments

Hello, I'm using this lib in a React project and i'm trying to make the mobile native keyboard to dismiss when the user is scrolling through the suggestion container. Not sure how to do it :(

Thanks in advance,

Lucas.

AndradeB91 avatar Jan 28 '19 21:01 AndradeB91

I have the exact same question. Thought of blurring when suggestions are presented, but that forces user to refocus to continue typing. That's not a smooth user experience.

Any thoughts on how to do it so user doesn't lose a third of the screen space?

theconnectionist avatar Feb 04 '19 04:02 theconnectionist

I had to fork the lib to make some adjustments.

onSuggestionTouchMove = () => {	  
    this.justSelectedSuggestion = false;	    
    this.pressedSuggestion = null;	    
    this.input.focus();	  //remove this line
};

onSuggestionTouchStart = () => {
    this.justSelectedSuggestion = true;
    this.input.blur();  //add this line
    // todo: event.preventDefault when https://github.com/facebook/react/issues/2043
    // todo: gets released so onSuggestionMouseDown won't fire in chrome
  }

Here is the link, if you wanna try: https://github.com/AndradeB91/react-autosuggest

It was the only way i managed it to work.

AndradeB91 avatar Feb 04 '19 13:02 AndradeB91

Also have the same question, short of using alwaysRenderSuggestions and conditionally rendering the whole component, I cannot find a way.

tonycassara avatar Feb 27 '19 19:02 tonycassara

Figured it out!

You can set alwaysRenderSuggestions to be variable true/false. So something like this for only showing on mobile when blurred:

alwaysRenderSuggestions={this.props.isMobileDevice && this.props.shouldOpenMobileSuggestions}

And then use a button or other method of firing an action to set shouldOpenMobileSuggestions

By setting it to false it defaults to only showing suggestions on input.focus()

tonycassara avatar Feb 27 '19 22:02 tonycassara

here's a monkeypatch (in case you got here through google and don't want to fork the library):

/* eslint-disable @typescript-eslint/no-explicit-any */

import Autosuggest from 'react-autosuggest';

/**
 * This class is a monkeypatch for the problems listed here:
 *
 *  https://github.com/moroshko/react-autosuggest/issues/609
 *
 * about all the problems the current onSuggestionTouchMove() has with
 * keyboards on MobileSafari.
 */
export class AutosuggestPatch extends Autosuggest {
  constructor(props: any) {
    super(props);
    const self = this as any;
    self.onSuggestionTouchMove = () => {
      self.justSelectedSuggestion = false;
      self.pressedSuggestion = null;
    };
  }

  /* monkeypatch the other method here, if you want. see @AndradeB91's comment */
}

hlian avatar Feb 13 '20 18:02 hlian

@hlian This absolutely solved it for me. Thank you!

mackan92 avatar Mar 30 '23 15:03 mackan92