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

[v2] Mobile support

Open AlessandroAnnini opened this issue 8 years ago • 16 comments

Hi, I am using v 2.0.0-beta.6 but I noticed that it doesn't work on any chrome mobile. Why is that? Is it something you plan to fix?

Thanks!

AlessandroAnnini avatar Jun 08 '18 09:06 AlessandroAnnini

Hi @sun2rise Do you happen to use Redux Form? I'm asking because I had issues in mobile devices when using Redux Form while the library was working just fine when used alone.

georapbox avatar Jun 08 '18 10:06 georapbox

yes @georapbox i am using it with redux-form... did you solve this problem somehow?

AlessandroAnnini avatar Jun 08 '18 11:06 AlessandroAnnini

My main issue on mobile was that the options were not selectable at all while it was working properly on desktop. In my component I had these 2 properties that were mentionned in redux-form related issues:

onChange={input.onChange}
onBlur={input.onBlur(input.value)}

But even having added these props, the issue still existed. I finally found that the issue was due to this property blurInputOnSelect which is true by default in mobile devices. So, when the user selects an option the library triggers a blur event. So far the only solution I found working is to replace onBlur={input.onBlur(input.value)} with onBlur={event => event.preventDefault()}.

Here a full example of how my component looks like:

// SelectSingle

const SelectSingle = field => {
  const { input, options } = field;

  return (
    <Select
      {...input}
      value={options.filter(item => item.value === input.value)[0]}
      options={options}
      onChange={input.onChange}
      onBlur={event => event.preventDefault()}
    />
  );
};


// Field component

<Field  
  name="language"
  component={SelectSingle}
  options={optionsArray}
/> 

PS Another partial solution is to set blurInputOnSelect to false. But then the virtual keyboard is not dismissed when user selects an option.

Hope this helps; let me know if that worked for you!

georapbox avatar Jun 08 '18 12:06 georapbox

Thanks @georapbox your solution is working great!!

AlessandroAnnini avatar Jun 08 '18 17:06 AlessandroAnnini

I want help developers who work with reduxForm onBlur={event => event.preventDefault()} doesn't work because reduxForm onBlur triggered errors for this field It's my solution:

  constructor() {
    this.fixReactSelectBlurMobile
  }

  handleChange = (value) => {
    this.fixReactSelectBlurMobile = value
    this.props.onChange && this.props.onChange(value, { ...this.props })
  }

  handleBlur = () => {
    this.props.onBlur && this.props.onBlur(this.fixReactSelectBlurMobile, { ...this.props })
  }

  render() {
    return (
          <Select
            onBlur={this.handleBlur}
            onChange={this.handleChange}
          />
    )
  }
}

DimaRomaniuk avatar Nov 27 '18 08:11 DimaRomaniuk

@DimaRomaniuk what kind of errors does reduxForm throw? I just tested my implementation using react-select v2.0.0 and v2.1.1 and I don't see any errors thrown. Actually after v2.0.0 was released I stopped having issues with selecting options in mobile (Android) even if I don't use onBlur={event => event.preventDefault()}.

georapbox avatar Nov 28 '18 11:11 georapbox

@georapbox reduxForm throw own errors for validation form

DimaRomaniuk avatar Nov 30 '18 09:11 DimaRomaniuk

My main issue on mobile was that the options were not selectable at all while it was working properly on desktop. In my component I had these 2 properties that were mentionned in redux-form related issues:

onChange={input.onChange}
onBlur={input.onBlur(input.value)}

But even having added these props, the issue still existed. I finally found that the issue was due to this property blurInputOnSelect which is true by default in mobile devices. So, when the user selects an option the library triggers a blur event. So far the only solution I found working is to replace onBlur={input.onBlur(input.value)} with onBlur={event => event.preventDefault()}.

Here a full example of how my component looks like:

// SelectSingle

const SelectSingle = field => {
  const { input, options } = field;

  return (
    <Select
      {...input}
      value={options.filter(item => item.value === input.value)[0]}
      options={options}
      onChange={input.onChange}
      onBlur={event => event.preventDefault()}
    />
  );
};


// Field component

<Field  
  name="language"
  component={SelectSingle}
  options={optionsArray}
/> 

PS Another partial solution is to set blurInputOnSelect to false. But then the virtual keyboard is not dismissed when user selects an option.

Hope this helps; let me know if that worked for you!

saved my day

DarkKnight1992 avatar Jan 01 '19 13:01 DarkKnight1992

I just updated the library and is not working for me with redux form

acollazomayer avatar Mar 21 '19 20:03 acollazomayer

I have same issue in Mobile (redux form) onClick drop down appears and disappears.

sandeepsk2020 avatar Mar 27 '19 10:03 sandeepsk2020

I needed the redux-form meta fields (specifically touched) to be properly updated with react-select and ran into the same issue. Calling event.preventDefault() causes the redux-form blur action not to get dispatched:

A callback that will be called whenever an onBlur event is fired from the underlying input. If you call event.preventDefault(), the BLUR action will NOT be dispatched, and the value and focus state will not be updated in the Redux store.

I was able to build on top of @georapbox's solution to solve it by calling redux-form's onBlur function with no arguments. This will allow redux-form to dispatch a blur action without changing the value back to blank on mobile.

const ReduxFormSelect = ({ input, options }) => (
  <Select
    onBlur={() => {
      input.onBlur();
    }}
    onChange={(option) => {
      onChange(option.value);
    }}
    onFocus={() => {
      input.onFocus();
    }}
    options={options}
    value={options.find(option => option.value === input.value)}
  />
);

heshammourad avatar May 02 '19 03:05 heshammourad

Hi, I am using v 2.3.0 but I found that the select option can't be selected on chrome dev tool with mobile version. I try to use onBlur={event => event.preventDefault()} and update my react-select package to version 3.0.0, but it doesn't work either. Why is that? It's there any workaround to fix it?Thanks!

Alizwell avatar May 29 '19 05:05 Alizwell

In your redux-form Field component prevent default onBlur from happening. This has resolved my mobile issue when using this library with redux-forms on mobile

                    <Field
                        ...
                        onBlur={(e: any) => e.preventDefault()}
                    />

phil-andrews avatar Aug 15 '19 14:08 phil-andrews

My main issue on mobile was that the options were not selectable at all while it was working properly on desktop. In my component I had these 2 properties that were mentionned in redux-form related issues:

onChange={input.onChange}
onBlur={input.onBlur(input.value)}

But even having added these props, the issue still existed. I finally found that the issue was due to this property blurInputOnSelect which is true by default in mobile devices. So, when the user selects an option the library triggers a blur event. So far the only solution I found working is to replace onBlur={input.onBlur(input.value)} with onBlur={event => event.preventDefault()}.

Here a full example of how my component looks like:

// SelectSingle

const SelectSingle = field => {
  const { input, options } = field;

  return (
    <Select
      {...input}
      value={options.filter(item => item.value === input.value)[0]}
      options={options}
      onChange={input.onChange}
      onBlur={event => event.preventDefault()}
    />
  );
};


// Field component

<Field  
  name="language"
  component={SelectSingle}
  options={optionsArray}
/> 

PS Another partial solution is to set blurInputOnSelect to false. But then the virtual keyboard is not dismissed when user selects an option.

Hope this helps; let me know if that worked for you!

Thank you so much. I was stuck for this for weeks

mapajohnedel avatar Nov 14 '19 09:11 mapajohnedel

Hello -

In an effort to sustain the react-select project going forward, we're closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our efforts towards the current major version.

If you aren't using the latest version of react-select please consider upgrading to see if it resolves any issues you're having.

However, if you feel this issue is still relevant and you'd like us to review it - please leave a comment and we'll do our best to get back to you!

bladey avatar May 28 '20 04:05 bladey

Thanks @georapbox your solution is working great!!

jayashree-navsoft avatar Oct 13 '20 14:10 jayashree-navsoft