mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

Geocoder input hijacks focus when used in form

Open zokioki opened this issue 4 years ago • 5 comments

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

  • Visit https://codepen.io/zoran/pen/RwRXxKj
  • Click into any of the non-geocoder fields
  • Press the Enter key

Expected Behavior

  • The Enter button should behave as it normally would in a form (i.e. submitting form when appropriate).

Current Behavior

  • The form changes focus to the geocoder input.

Notes

  • This issue doesn't seem to happen when the geocoder input is placed after the submit button, e.g.:
<!-- 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>

zokioki avatar Nov 24 '20 02:11 zokioki

Bump this issue. This is horrendous.

rmilesson avatar Aug 10 '22 11:08 rmilesson

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.

zokioki avatar Sep 19 '22 06:09 zokioki

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

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

gmbwa avatar Jul 12 '23 17:07 gmbwa

The issue still happens and makes developer find a workaround.

okolomiets avatar Oct 21 '23 09:10 okolomiets