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

[Bug]: adding tom select to a focused form field makes it lose focus #716

Open
lovasoa opened this issue Apr 29, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@lovasoa
Copy link

lovasoa commented Apr 29, 2024

Bug description

Description:
When Tom Select is initialized on a form field that is set to be autofocused, the field loses its focus immediately upon page load. This issue occurs regardless of whether the autofocus attribute is set directly in the HTML or programmatically via JavaScript. This behavior disrupts user experience, especially in forms where immediate input is expected upon loading the page.

initially reported in lovasoa/SQLpage#297

Steps to Reproduce:

  1. Create a basic HTML file with a form input.
  2. Set the autofocus attribute on this input.
  3. Initialize Tom Select on this input using the standard initialization code.
  4. Load the page in a browser and observe that the input does not retain focus.

Expected Behavior:
The input field should retain its focus when the page loads, allowing users to start typing immediately without having to click on the field.

Actual Behavior:
The input field loses focus as soon as Tom Select is initialized, requiring users to manually click on the field to start typing.

Additional Information:

  • This issue does not appear to be browser-specific as it replicates across multiple major browsers.
  • A potential workaround could involve programmatically setting focus back to the input after initializing Tom Select, but this is not ideal for all use cases.

Suggested Fix:
The initialization of Tom Select might benefit from a check to retain focus if the target element has the autofocus attribute or if it is already focused before initialization. Adjusting the library to check and restore focus could resolve this issue.

@lovasoa lovasoa added the bug Something isn't working label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant