Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard cannot be dismissed, if user taps on second TextInput component #17252

Closed
absemeta opened this issue Dec 18, 2017 · 4 comments
Closed
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@absemeta
Copy link

Is this a bug report?

Yes.

Have you read the Contributing Guidelines?

Yes.

Environment

Environment:
OS: macOS Sierra 10.12.6
Node: 8.7.0
Yarn: 1.2.1
npm: 5.4.2
Watchman: 4.9.0
Xcode: Xcode 9.0 Build version 9A235
Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0 => 16.0.0
react-native: 0.51.0 => 0.51.0

Steps to Reproduce

  1. Inside ScrollView component put several TextInput components
  2. Tap on one TextInput, keyboard will appear, tap on blank space, keyboard will disappear.
  3. Tap on one TextInput, then tap on second TextInput, and then tap on blank space.

Expected Behavior

Keyboard should be dismissed when pressed on blank space

Actual Behavior

Keyboard persists if user has several TextInput components inside ScrollView and he taps on first and then second TextInput component. Keyboard persists, and it is correct behavior.

However, now, when user presses on blank space, keyboard is not dismissed. It stays there until user presses any other TextInput, and then presses blank space.
bug

Reproducible Demo

Newly generated react-native app with ScrollView and several TextInput components
https://github.com/magneticz/AwesomeBug

@watanabeyu
Copy link
Contributor

watanabeyu commented Dec 19, 2017

@magneticz I solved this below.

<ScrollView keyboardShouldPersistTaps="never" style={{ flex: 1 }}>
  <TextInput
    ref={ref => this.input1 = ref}
    onFocus={() => this.input1.focus()}
    style={{ borderWidth: 1, borderColor: 'red', height: 50, margin: 10 }}
  />
  <TextInput
    ref={ref => this.input2 = ref}
    onFocus={() => this.input2.focus()}
    clearButtonMode="while-editing"
    style={{ borderWidth: 1, borderColor: 'red', height: 50, margin: 10 }}
  />
  <TextInput
    ref={ref => this.input3 = ref}
    onFocus={() => this.input3.focus()}
    clearButtonMode="while-editing"
    style={{ borderWidth: 1, borderColor: 'red', height: 50, margin: 10 }}
  />
</ScrollView>

Add ref and onFocus, and you have to explicitly call focus() on each onFocus.

https://snack.expo.io/B1Vcm-Lff

@absemeta
Copy link
Author

it turns out, if keyboardShouldPersistTaps="handled" on ScrollView is used, it works just fine, no need for ref and onFocus().
However, it is a strange behavior, not to dismiss keyboard only when second TextInput is pressed

@stale
Copy link

stale bot commented Feb 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 17, 2018
@stale stale bot closed this as completed Feb 24, 2018
@ltankey
Copy link

ltankey commented Apr 12, 2018

it turns out, if keyboardShouldPersistTaps="handled" on ScrollView is used, it works just fine, no need for ref and onFocus().

If keyboardShouldPersistTaps="never", surely attempting to select the second TextInput while focused on the first should result in the keyboard being dismissed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants