react-native-modal: Text input submit button not working on first click
Environment
react: 16.8.3 => 16.8.3 react-native: 0.59.8 => 0.59.8
Platforms
Both in Android and iOS
Versions
- Android: 9
- iOS: 13.3
- react-native-modal: 11.4.0
- react-native: 0.59.8
- react: 16.8.3
Description
Have a text input and submit and close button in the modal. The keyboard is autofocus and with the keyboard is opened and try to close or submit the inputs, the buttons are not working on the first click.
On first click the keyboard is closed and need to click on the button second time to submit.

Reproducible Demo
Step to reproduce:
- A text input, close and submit button in modal.
- The keyboard is auto-focused when the modal appears.
- Try to close the modal, by clicking the close button with the keyboard opened.
- On the first click the keyboard closed and need to tap again the close button to close the modal.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 19
- Comments: 37 (1 by maintainers)
Is your content wrapped in a
<ScrollView />? If so, trykeyboardShouldPersistTaps={'handled'}in<ScrollView>props.I had this issue and where trying to add Scroll View with
keyboardShouldPersistTaps="always"with no result. Later I’ve found that there was a ScrollView at the page where the modal located which wrapped a whole page. So all what I did: I addedkeyboardShouldPersistTaps="handled"to this ScrollView and it helped me.So the main idea is to walk up through the component tree and find for ScrollView and add
keyboardShouldPersistTaps="handled"to it if exists. Otherwise just add it at place where you need it.keyboardShouldPersistTaps={'handled'}works for me, but in my case, I need to put these props into both theScrollViewandKeyboardAwareScrollView.My code more or less looks like this:
@akhilsanker can you try change your
keyboardShouldPersistTaps={'handled'}tokeyboardShouldPersistTaps={'always'}and let me know if this works?@mo-patel thankyou very much for " keyboardShouldPersistTaps={‘handled’}. It worked for me. thanks
I use TextInput and TouchableOpacity in KeyboardAvaidingView component. I can not click TouchableOpacity when Keyboard is opened. When I press the TouchableOpacity, just Keyboard disappear. I want TouchableOpacity to work while Keyboard is active. Does anyone have an idea?
I have fixed that by using in parent component=> in scrollView and if flatlist.
keyboardDismissMode=“interactive” keyboardShouldPersistTaps={ Platform.OS === ‘ios’ ? ‘handled’ : ‘always’ }
I am also encountering the same issue. None of those options that could potentially fix the problem have worked.
Thanks. it’s works for me.
This is the most underrated reply in the world. For everyone who suffered with figuring out why you cannot press a button when the keyboard is up. READ THIS COMMENT xP
Just find the first ScrollView or Flatlist that’s above your TextInput. Most of the time you’re component will be an item in a Flatlist or ScrollView. Just add keyboardShouldPersistTaps=“handled” to it.
IF YOU HAVE MULTIPLE SCROLLVIEWS, Like one flatlist in another, add it on the flatlist all the way up. (the parent/ first flatlist or scrollview)
I googled for hours before I read this comment and realised that my TextInput is in a component that’s being rendered in a Flatlist! Sometimes we’re so focused on the small picture, we forget to take a step back and see the big picture.
I made a question here too https://stackoverflow.com/questions/63103717/prevent-keyboard-dismiss-react-native-inside-modal
any solution?
Thanks. this works
What if it is not wrapped in a scrollview?
I got it working with native Modal component
Towards the root of my app, I have a
<Swiper />element which is basically a ScrollView. Adding keyboardShouldPersistTaps=“always” keyboardDismissMode=“on-drag” to the Swiper as props solved my issueHi @mo-patel, I have tried that too. But didn’t succeed.
Hi @mo-patel
</ScrollView>