I am trying to prevent a popup from being dismissed when the user taps outside of the popup. I have seem other questions/answers about this, and they all seem to suggest using the modalInPopover for the view. I have done this in the viewDidAppear as I have seen suggested. I have text fields along with buttons that fill in a label according to a selection from a dropdown menu. Before any information is entered, it works fine, and the popup is not dismissed when tapping outside. It also works fine for when text is entered in the text fields. However, as soon as I make a selection from a dropdown after tapping one of the buttons, the popup will dismiss after touching outside of it.
Are there any other suggestions as to why this could be? Could it have something to do with calling resignFirstResponder on the text fields?
Let's look at the two simplest ways of dismissing the popover. You can pass the additional prop rootClose to your OverlayTrigger component to dismiss the popover when on an outside click. 1 ... 2 <OverlayTrigger trigger="click" rootClose placement="right" overlay={popover}> 3 ...
The default dismissing action of React Bootstrap popover is the same button that triggers it. The button that opens the popover on click acts like a toggle. The user, however, expects the popover to close when they click anywhere outside the page, just like modals, due to their similar interfaces.
In iOS, the keyboard doesn’t dismiss automatically if the user taps anywhere outside of the keyboard view. So, we need to handle it manually. To achieve this, we can simply add one UITapGestureRecognizer to the parent view and dismiss the keyboard if any tap detected.
Popovers can be used in several ways, such as calculating the price of an inventory item in an e-commerce web app, displaying details of a new car model, etc. However, when using a UI component, be sure it is conveniently handled on the user's end.
In swift 3, ios 10
After implementing UIPopoverPresentationControllerDelegate the following function seems to do the trick.
func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}
I hope this helps if anyone is still looking for a solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With