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

[Modern UI] Fix select2 search autofocus #9533

Merged

Conversation

cconard96
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -

This fixes two issues with the search input focus:

  • The search box is no longer automatically focused when the select2 dropdown is opened. This seems to be a known issue but has not been fixed upstream.
    Search not auto focusing in jQuery 3.6.0 select2/select2#5993
    As a workaround, we need to manually set the focus when the dropdown is opened. The user can still use the arrow keys to select an option when the search is focused.
  • When the dropdown is in a Bootstrap modal, it is impossible to interact with the search box. The modal seems to change the focus to its close button instead. For this, we need to be able to specify the dropdownParent property during the select2 initialization. I added the ability to manually specify the dropdown parent selector or by default it automatically uses the parent modal or document body (select2 default).

inc/html.class.php Outdated Show resolved Hide resolved
Copy link
Member

@cedric-anne cedric-anne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure giving ability to redefine the dropdownParentSelector will be really usefull.

If the auto case, which seems to be the only one used here, is fixing the issue, then I am not in favor to add this amount of code in order to add an option we are not using.

inc/dropdown.class.php Outdated Show resolved Hide resolved
inc/html.class.php Outdated Show resolved Hide resolved
@cedric-anne
Copy link
Member

cedric-anne commented Sep 29, 2021

@cconard96 Do you know any usecase where using a custom parent selector could be useful ?

@cconard96
Copy link
Contributor Author

@cconard96 Do you know any usecase where using a custom parent selector could be useful ?

Not at this point. I'll remove that option and simplify the code.

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

Successfully merging this pull request may close these issues.

3 participants