Typeahed: allow search on focus
See original GitHub issueIn certain use-cases one might want to trigger typeahead search when the input field gets focused. You can see a good example of this on https://www.kayak.fr/flights
It should be trivial to implement this on our side since we should simply listen to the focus
event, get whatever value we’ve got in the input and push it down the observable stream. The only tricky part might be taking into account the situation where a given input field has autofocus
attribute (in this case we shouldn’t kick off things).
There should be a flag for this option (I guess false by default).
I’m going to mark this as medium
difficulty and I think that it is a good issue for ambitious community members. As always test are essentials.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:15
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Bootstrap - show all Typeahead items on focus - Stack Overflow
So, what's your question? What doesn't work? · Hi John It works when I start to type, but not only on focus. The...
Read more >jQuery Typeahead Search Configuration - RunningCoder
Configure jQuery Typeahead Search plugin, learn about the options and what they can do to improve your search bar.
Read more >React Bootstrap Typeahead Example
The typeahead allows single-selection by default. Setting the multiple prop turns the component into a tokenizer, allowing multiple selections. Example.
Read more >Place Autocomplete | Maps JavaScript API - Google Developers
Autocomplete is a feature of the Places library in the Maps JavaScript API. You can use autocomplete to give your applications the type-ahead-search...
Read more >Hotwire: Typeahead searching - Thoughtbot
Let's build a collapsible search-as-you-type text box that expands to show its results in-line while searching, supports keyboard navigation ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have a workaround for this for people who want this functionality now.
On the input element that has typeahead add a focus handler:
In the focus handler trigger an input event:
It would be nice to not have to do this, but it works for now.
Hello,
I worked on the issue to try figuring out solutions, ideas, and here they are.
The feature requirements
As seen by the end user:
Additional requirements as seen by the application developer:
An example of a scenario that should be possible with such a feature
The last point illustrates that it is important to know whether the current search request comes from an
input
event or afocus
event.Possible implementations
Nothing
On the application side, it is already possible to add a
focus
event handler on the input. The listener can then send values to an internalSubject
instance which would have been merged at some point with the observable given in the TypeAhead initialization function (ngbTypeahead
).Example usage:
Pros:
Cons:
Subject
, handlingfocus
event)Create ourselves an observable from the focus event and give it to the user
Example usage:
Pros:
Cons: I don’t see any. However it would require more API design, since I don’t think we should extend the arguments list too much for any possible event. Also, we could optimize the implementation by providing an option so that if the feature is not wanted there is no new event handler added and no corresponding observable created.
Merge ourselves the focus observable with the input observable
There are two fashions for this one: backward compatible and non-backward compatible.
Backward compatible
Example usage:
Pros:
Cons:
focus
events frominput
events, so implementing different behaviors is not possibledebounceTime
is probably not wanted in case offocus
distinctUntilChanged
could mess up in case offocus
(depending on how we keep the rest of the implementation)Non backward compatible
Example usage:
Pros:
Cons:
debounceTime
anddistinctUntilChanged
), it requires a good knowledge of observablesConclusion
I personally prefer the second option for these reasons:
I will leave this pending for comments for some days, and if no decision stands out we will make one and implement it.
PS: this whole feature based on focus events requires a very small and simple fix inside the TypeAhead to avoid trying to write an
undefined
value inside the input element. With the methods exposed above, this can happen if no input event has been triggered yet, and the dropdown is open through a focus event and closed afterwards without selecting anything. Therefore using the first exposed implementation (fully on your side) won’t work for that use case without this fix.