Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loses focus on close. #4971

Closed
7 of 16 tasks
ajcastro opened this issue Jun 27, 2017 · 12 comments
Closed
7 of 16 tasks

Loses focus on close. #4971

ajcastro opened this issue Jun 27, 2017 · 12 comments

Comments

@ajcastro
Copy link

ajcastro commented Jun 27, 2017

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate
  • The issue still exists against the latest master branch of Select2
  • This is not a usage question (Those should be directed to the community)
  • I have attempted to find the simplest possible steps to reproduce the issue
  • I have included a failing test as a pull request (Optional)

Steps to reproduce the issue

  1. Go https://select2.github.io/examples.html.
  2. Try to navigate a select2 element by using tab.
  3. Then select an option. After closed, the focus is gone.

Expected behavior and actual behavior

When I follow those steps, I see... that the focus is not on the current select2 element.

I was expecting... the focus should still be on the select2 element, and then when I press tab, it should go to the next select2 element. The latest version is not keyboard friendly. I would love the keyboard behaviour in v3.5.3.

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version:
  • Select2 version:

Isolating the problem

  • This bug happens on the examples page
  • The bug happens consistently across all tested browsers
  • This bug happens when using Select2 without other plugins
  • I can reproduce this bug in a jsbin
@ptheofan
Copy link

Same issue. Using tab, arriving on select2 elem. Hit enter, it opens, I select the entry - focus is lost. Results, next tab go top of page according to tab-indexes

@jamesSampica
Copy link

jamesSampica commented Aug 4, 2017

Same issue in 4.0.3. This seems to work as a workaround edit to select2.js

this.on('close', function () {
    self.$container.removeClass('select2-container--open');

    self.$selection.focus();  //added fix for focus on close
});

@oh-ren
Copy link

oh-ren commented Sep 1, 2017

Workaround in userland (not thoroughly tested):

$('select').select2().on('select2:close', function(e) {
    let select2 = $(this).data('select2');
    select2.$selection.focus();
});

@alexweissman
Copy link
Contributor

Is this related to the problem addressed in #4860?

@oh-ren
Copy link

oh-ren commented Sep 1, 2017

It seems so. I'm only just looking into Select2, so not really familiar with the code base (nor it's general issues).
I added the base.js timeout hack to the dist file, seems to fix this focus issue in FF56. Not sure what the effect is of the change in search.js

@alexweissman
Copy link
Contributor

Hmm. Seems like creating a Github Project might be a good way to aggregate these related issues for now.

@alexweissman
Copy link
Contributor

Ok, created this project: https://github.com/select2/select2/projects/2

@alexweissman
Copy link
Contributor

There's also the issue reported in #4419, fixed by #4427. Is this the same issue?

@jpic
Copy link
Contributor

jpic commented Sep 22, 2017

@alexweissman this seems like a different issue: after selecting an issue with the keyboard -> the focus is lost -> pressing tab again starts over from the beginning of the page -> you have to go over the sidebar links to get back at the autocomplete.

@alexweissman
Copy link
Contributor

No, @jpic I am fairly sure that this is the same issue. After merging in @nino-s 's fix (#4427) and releasing 4.0.4, you can see that this problem no longer occurs on the demo page: https://select2.org/getting-started/basic-usage

@PieterjanDeClippel
Copy link

Apparently the issue is back. See demo-page.
Can this problem be fixed once again?

@Dannymx
Copy link

Dannymx commented May 3, 2019

This issue is still present in latest 4.0.6 and 4.0.7 rc.0

For me when I click one select and then click another select, the focus stays with the previous select.

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

No branches or pull requests

8 participants