allen kim allen kim - 1 month ago 10x
iOS Question

Prevent blur event on keyboard close

This is for mobile web apps, not native.

I have an autocomplete drop-down that closes on the blur event. But I want to prevent this from happening when the user closes the keyboard on mobile (ie the autocomplete dropdown should stay visible). Is there a way to distinguish a blur event caused by the keyboard closing, and other kinds of blur events? Can I prevent a blur event specifically caused by closing the keyboard in mobile?


Ok, first I would recommend checking your libraries' documentation because they might provide something in their API, although there's nothing I'm aware of. That's the disadvantage of Web Apps: you can't access native functionality.

If you still really want to do it, here's a possible solution. It's ugly, but it might work.

Container on tap function (event)

If !autocomplete return // if you cant see the popup do nothing and blur normally

If ( != inputID) AND ( != autocID)

Essentially, instead of closing the autocomplete on blur, close it whenever the user taps on your parent container, but not on the input itself or the autocomplete. Depending on how it works, you could extend it to check any tap on screen.