mapbox / mapbox-gl-geocoder

Geocoder control for mapbox-gl-js using Mapbox Geocoding API
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-geocoder/
ISC License
364 stars 180 forks source link

Geocoder input hijacks focus when used in form #402

Open zokioki opened 3 years ago

zokioki commented 3 years ago

Overview

When using the geocoder outside of a map, as part of a form, pressing the Enter key in another field will bring the focus of the form to the geocoder input. This is unexpected behavior which prevents users from submitting forms via Enter and breaks the overall flow of filling out a form.

Library Version

Reproducible Example

Expected Behavior

Current Behavior

Notes

<!-- This order does not produce the focus-on-Enter issue -->
<input type="text" name="example_email" placeholder="Email">
<input type="submit" value="Submit" tabindex="-1">
<div class="geocoder"></div>
rmilesson commented 2 years ago

Bump this issue. This is horrendous.

zokioki commented 2 years ago

I ended up writing my own library a while back to address this, leveraging autocompleter for the suggestions rendering as it's lightweight, dependency-free and plays nicely when used within forms. I've released this library as places-autocomplete for reference in case it's helpful for dealing with this issue.

gmbwa commented 1 year ago

Adding a button tag with css display:none seems to work.

<Button type="submit" style={{ display: 'none' }} />

okolomiets commented 12 months ago

The issue still happens and makes developer find a workaround.

franzwilding commented 1 month ago

I'm facing the same issue. https://github.com/mapbox/mapbox-gl-geocoder/issues/402#issuecomment-1632934098 works for me, but I think it should be fixed.