tom-select icon indicating copy to clipboard operation
tom-select copied to clipboard

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

Open lovasoa opened this issue 1 year ago • 2 comments
trafficstars

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 https://github.com/lovasoa/SQLpage/issues/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 avatar Apr 29 '24 21:04 lovasoa

This issue has not been active in 120 days and has been marked "stale". Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Aug 28 '24 02:08 github-actions[bot]

still relevant

lovasoa avatar Aug 28 '24 09:08 lovasoa