typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Option for Automatic selection of the first item in the typeahead resultset

Open RoyLee opened this issue 13 years ago • 51 comments

Would it be possible for there to be an option for the first item to be automatically selected in the typeahead on search so a press of the enter key will go to that specific item's url? This would save the user needing to press the downarrow key to get to that first item and then pressing the enter key. Thanks!

RoyLee avatar Feb 22 '13 19:02 RoyLee

I don't know if we'll ever add anything like this as I think this behavior would be potentially confusing to the end-user. You may be able to implement this behavior after v0.9 is released, but it'd be based on custom events and not a configurable option.

jharding avatar Feb 23 '13 08:02 jharding

Thanks for responding on this! Some of the bigger websites (eg facebook) use this, and jQuery UI autocomplete has this as an option as well. Looks like i'll have to play around with typeface v.9+.

RoyLee avatar Feb 24 '13 21:02 RoyLee

I agree with jharding, but in some case it could be great to have the option. ie: when the user typed his query and there is only one item left in the list. The user still have to select the line (most basic user don't really use tab)

bodinsamuel avatar Feb 25 '13 13:02 bodinsamuel

A use case I need to support is to have a generic "Search for < typed input >" entry as the first item. It would make sense that this item is selected by default.

scott-laursen avatar Feb 27 '13 18:02 scott-laursen

I outlined a workaround in #142. Also, see #141 for adding the generic "Search for" entry.

ustun avatar Mar 26 '13 16:03 ustun

+1

stayce avatar Apr 16 '13 21:04 stayce

If you're interested, I implemented this in a fork.

https://github.com/nagiek/typeahead.js

nagiek avatar Apr 18 '13 17:04 nagiek

:+1: for an option

staabm avatar Apr 19 '13 07:04 staabm

:+1:

tbaddade avatar Apr 19 '13 07:04 tbaddade

+1

sjlu avatar Apr 30 '13 18:04 sjlu

+1

Jellyfishboy avatar May 22 '13 20:05 Jellyfishboy

@nagiek Hi, please where exactly is it implemented?

jelen07 avatar Jun 26 '13 07:06 jelen07

No ETA, this isn't very high priority for me. I would consider accepting a pull request for this issue though.

jharding avatar Jun 26 '13 07:06 jharding

We added functionality to typeahead on our own. https://github.com/UrbanCompass/typeahead.js

We use it like:

    searchBox.typeahead({
      name: 'neighborhoods',
      local: neighborhoods,
      minLength: 0,
      limit: Infinity
   })

But our version is no where near pull-request quality.

sjlu avatar Jun 26 '13 12:06 sjlu

What would be a good name for this option?

jharding avatar Jul 11 '13 05:07 jharding

autoselect: 'first'

staabm avatar Jul 11 '13 06:07 staabm

Sjlu,

Both your auto-selecting the first option and the allowing minLength of 0 look really useful.

I would love to see a pull request for both.

nathanjones avatar Jul 15 '13 23:07 nathanjones

It's very hacky, we'll make it a little more beautiful then submit a pull request.

Just need time to do so ;)

sjlu avatar Jul 15 '13 23:07 sjlu

You may not have to submit a pull request as an autoselect option has been added to v0.10 and I also added the ability to render default suggestions, although not by using minLength: 0.

jharding avatar Jul 15 '13 23:07 jharding

+1

Nitrodist avatar Jul 31 '13 20:07 Nitrodist