orchidjs / tom-select

Tom Select is a lightweight (~16kb gzipped) hybrid of a textbox and select box. Forked from selectize.js to provide a framework agnostic autocomplete widget with native-feeling keyboard navigation. Useful for tagging, contact lists, etc.
https://tom-select.js.org
Apache License 2.0
1.66k stars 124 forks source link

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

Open lovasoa opened 6 months ago

lovasoa commented 6 months ago

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:

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.

github-actions[bot] commented 2 months ago

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

lovasoa commented 2 months ago

still relevant