select2 / select2

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.
https://select2.org/
MIT License
25.9k stars 6.26k forks source link

Typing Doesn't Trigger Search #3279

Open philipstratford opened 9 years ago

philipstratford commented 9 years ago

On the examples page for 3.5.2, if you use the tab key to give a select box focus and start typing, a search of the options begins, as desired.

On the examples page for 4.0, if you do the same thing, nothing happens. You are required to actually click the dropdown in order for searching to begin.

This is no good - I want my users to be able to tab through a form and, when they reach a dropdown, to be able to just start typing to begin searching, and use the enter key to make a selection. In other words, I don't want to users to have to use the mouse at all if they don't want to, which with 3.5.2 is possible, but with 4.0 is not.

eobeda commented 9 years ago

I agree, this appears to be a breaking Ux change in 4.0. I would also include the change in behavior to the clear button (x) as a breaking Ux change in 4.0. It now displays the drop down automatically when clearing the selection. Any suggestions on work-around(s) for these issues ?

kevin-brown commented 9 years ago

This was an intentional change, and in order to understand why we changed it you need to understand how it was done before.

We started off doing this by listening to key events when the <div> was focused, and then repeating the character into the text box. This had two unfortunate side effects:

  1. Not all browsers (cough Internet Explorer) handled key events the same way, and it was difficult to consistently get the typed in character.
  2. Moving that typed character over to the search box meant moving the keyboard focus over and ensuring that the character wasn't highlighted. This proved to be more difficult than it should have, and both IE and Firefox had a tendency to lose the first character.

So we decided to make the focusing element an <input /> box, and have it be hidden out of sight. This fixed the IE issues, and we could consistently get the character typed (just get the .value). Eventually we were able to alleviate the second issue, but we ended up adding in a few new side effects:

  1. Because were were automatically focusing the keyboard, any interaction with Select2 on a mobile device would trigger the on-screen keyboard.
  2. We created an accessibility problem because there was no indication of what the focusing <input /> was actually for. And some screen readers actually ignored it, so it was impossible to navigate Select2 through a keyboard.

And that's why we added a shouldFocusInput option in Select2 3.x that disables the automatic focusing of the input if the user is on a mobile device and there isn't a visible search box. While that worked in a way, it was never considered anything more than a hack.

And that's why we no longer try to handle that case magically in Select2 4.0.

If we took the easy route and automatically opened the dropdown when we detected a keypress, that would work some of the time. But we would run into exactly the same issue that we originally hit. It would also block any possibility of us getting the searching to work when the dropdown is not open (so you can quickly select things), which is far out on our roadmap.

So we made the decision to not support it in Select2 4.0. You can still open the dropdown by hitting [space] or [enter], which is how it works in a normal <select>.

eobeda commented 9 years ago

Thanks for the details. Ed

On Sun, Apr 26, 2015 at 5:01 PM, Kevin Brown notifications@github.com wrote:

This was an intentional change, and in order to understand why we changed it you need to understand how it was done before.

We started off doing this by listening to key events when the

was focused, and then repeating the character into the text box. This had two unfortunate side effects:

  1. Not all browsers (cough Internet Explorer) handled key events the same way, and it was difficult to consistently get the typed in character.
  2. Moving that typed character over to the search box meant moving the keyboard focus over and ensuring that the character wasn't highlighted. This proved to be more difficult than it should have, and both IE and Firefox had a tendency to lose the first character.

So we decided to make the focusing element an box, and have it be hidden out of sight. This fixed the IE issues, and we could consistently get the character typed (just get the .value). Eventually we were able to alleviate the second issue, but we ended up adding in a few new side effects:

  1. Because were were automatically focusing the keyboard, any interaction with Select2 on a mobile device would trigger the on-screen keyboard.
  2. We created an accessibility problem because there was no indication of what the focusing was actually for. And some screen readers actually ignored it, so it was impossible to navigate Select2 through a keyboard.

And that's why we added a shouldFocusInput option in Select2 3.x that disables the automatic focusing of the input if the user is on a mobile device and there isn't a visible search box. While that worked in a way, it was never considered anything more than a hack.

And that's why we no longer try to handle that case magically in Select2 4.0.

If we took the easy route and automatically opened the dropdown when we detected a keypress, that would work some of the time. But we would run into exactly the same issue that we originally hit. It would also block any possibility of us getting the searching to work when the dropdown is not open (so you can quickly select things), which is far out on our roadmap.

So we made the decision to not support it in Select2 4.0. You can still open the dropdown by hitting [space] or [enter], which is how it works in a normal