Skip to content

Trapped focus causes accessibility issues #162

Closed

Description

@3zzy

Looks like this line:

// TAB, ESC, LEFT, RIGHT, ENTER, UP, DOWN
if (e.metaKey || [9, 27, 37, 39, 13, 38, 40].indexOf(e.keyCode) !== -1) return;

https://github.com/mapbox/mapbox-gl-geocoder/blob/master/lib/index.js#L133

... traps focus on the GeoCoder input element and doesn't allow the user to tab through the following elements cause accessibility issues.

Activity

  1. timchambers commented on Aug 17, 2018

    @timchambers

    This seems to be the source of a problem I'm experiencing, too. If I have a map and geocoder inside a form and I hit return in one of the other form fields, the focus is stolen back to the geocoder and the submit event doesn't get fired. Any way to disable this focus stealing?

  2. andrewharvey commented on Aug 17, 2018

    @andrewharvey
    Collaborator

    Does anyone have an minimally reproducing example?

  3. 3zzy commented on Aug 19, 2018

    @3zzy
    ContributorAuthor

    @andrewharvey Here: https://jsfiddle.net/iaezzy/zevaw734/8/

    If you try navigating via keyboard using Tab key, once you reach the geocoder element you can't focus the next button or the previous (using Shift + Tab) because the focus is trapped.

  4. jdaudier commented on Aug 27, 2018

    @jdaudier

    I have the same bug. Does anyone have a workaround for this while we are waiting for a fix?

  5. 3zzy commented on Aug 27, 2018

    @3zzy
    ContributorAuthor

    @jdaudier Here's what I'm doing temporarily (jQuery):

    $(".mapboxgl-ctrl-geocoder input[type='text']").on('focus keydown', function (e) {  
        if (e.shiftKey && e.keyCode == 9) {
            // manually focus prev eg. $('.someElement').focus();
        }
        else if (e.keyCode == 9) {
            // manually focus next element eg. $('.someOtherElement').focus();
        }
    });
    
  6. jdaudier commented on Aug 31, 2018

    @jdaudier

    @3zzy Thanks! It works for me but I didn't need to add the event on focus. Just curious about your reason for that.

  7. added this to the v4.0.0 milestone on Mar 13, 2019
  8. scottsfarley93 commented on Mar 15, 2019

    @scottsfarley93

    It looks like we could tackle this by changing the suggestions library with a relatively minor PR that prevents trapping tab events.

    Specifically, changing https://github.com/tristen/suggestions/blob/gh-pages/src/suggestions.js#L59 and https://github.com/tristen/suggestions/blob/gh-pages/src/suggestions.js#L67 so that keyCode==9 checks are no longer cases in the switch statements.

    I'm not sure if this will cause any other unintended consequences though. I'll have to dig in a little more.

  9. scottsfarley93 commented on Mar 21, 2019

    @scottsfarley93

    This was done in #220 and will be fixed in version 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions