-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dropdown closes and reopens on keypress with remote dataset #176
Comments
Whenever the query changes, the suggestions are cleared, thus closing (well, hiding) the dropdown menu. New suggestions are then requested and when they become available, they are rendered causing the dropdown menu to appear again. What behavior are you expecting here? |
To me it seems like it might be better for the dropdown to stay open, and have the results replaced. Then if there are 0/fewer results, close/resize. This way the dropdown wouldnt flash/flicker. So if you continue typing a word it would appear more natural, only eliminating other results as you specify the query |
But let's say your typeahead is backed by a dataset that only draws suggestions from a remote endpoint and let's say it takes a few seconds for this endpoint to respond. If you type I do agree that the flickering of the menu is less than ideal, I'm just not sure how to go about addressing it. Right now I think the best way to prevent flickering is to take advantage of prefetching. |
Prefetched is great solution, but struggles a bit with large datasets. For my purposes it works better for say, a weekly generated list of most popular terms, etc. What about updating a localstorage key with most recent dataset and comparing new query against localstorage values. Then, leave matches, until dataset updated with server data? That way if someone switches from bro to bas, terms wouldn't match, and dropdown could be hidden. But if they do continue with broa, terms would hit and keep dropdown open. |
Hey any chance you guys figured out how to implement this? Even if not included in supported code, would like to include myself. I just want it to stay open until ajax request completes, since I'm only using remote. |
I currently don't have a lot of time to work on typeahead.js so there's no way this is going to be resolved within the next week. Your best bet would be to fork typeahead.js and hack together your own solution for the time being. |
you can do something like comment out !cacheHit && cb && cb(suggestions) since remote only. this will stop the empty suggestion that calls clear_suggestions i then added a new trigger for "queryMinLength" rather than just "queryChanged" (if using minlength. so that we can run clear suggestions at certain point.) and then for typeahead view i changed .on("queryChanged", this._clear... to on("queryMinLength and on("queryChanged whiteSpaceChanged", this._updateHint not ideal, but it works. hope it helps |
I need this feature too. |
Hi, I am also using a Remote Source only and this feature would be great. Has there be any Decission or Discussion around there recently? Thanks |
Hi Ndreckshage I facing same problem..................from last 3 days try to solve this problem Please send me changes code I dont clearly understand this line : on("queryChanged", this.clear... to on("queryMinLength and on("queryChanged whiteSpaceChanged", this.updateHint |
Are you willing to share your code for the fix? |
Here's a quick hack for my use case (data populated from remote only) to remove flickering. Use with caution. // old
_compareQueryToInputValue: function() {
var inputValue = this.getInputValue(), isSameQuery = compareQueries(this.query, inputValue), isSameQueryExceptWhitespace = isSameQuery ? this.query.length !== inputValue.length : false;
if (isSameQueryExceptWhitespace) {
this.trigger("whitespaceChanged", {
value: this.query
});
} else if (!isSameQuery) {
this.trigger("queryChanged", {
value: this.query = inputValue
});
}
},
// new
_compareQueryToInputValue: function() {
var inputValue = this.getInputValue(), isSameQuery = compareQueries(this.query, inputValue), isSameQueryExceptWhitespace = isSameQuery ? this.query.length !== inputValue.length : false;
if (isSameQueryExceptWhitespace) {
this.trigger("whitespaceChanged", {
value: this.query
});
} else if (!isSameQuery) {
this.trigger("queryChanged", {
value: this.query = inputValue
});
if (this.query.length == 0 || inputValue.length == 0) { // added
this.trigger("queryZeroLength", {
value: this.query
});
}
}
},
// old
}).on("focused", this._openDropdown).on("blured", this._closeDropdown).on("blured", this._setInputValueToQuery).on("enterKeyed tabKeyed", this._handleSelection).on("queryChanged", this._clearHint).on("queryChanged", this._clearSuggestions).on("queryChanged", this._getSuggestions).on("whitespaceChanged", this._updateHint).on("queryChanged whitespaceChanged", this._openDropdown).on("queryChanged whitespaceChanged", this._setLanguageDirection).on("escKeyed", this._closeDropdown).on("escKeyed", this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed", this._managePreventDefault).on("upKeyed downKeyed", this._moveDropdownCursor).on("upKeyed downKeyed", this._openDropdown).on("tabKeyed leftKeyed rightKeyed", this._autocomplete);
// new
}).on("focused", this._openDropdown).on("blured", this._closeDropdown).on("blured", this._setInputValueToQuery).on("enterKeyed tabKeyed", this._handleSelection)
.on("queryChanged", this._clearHint)
//.on("queryChanged", this._clearSuggestions) // removed
.on("queryZeroLength", this._clearSuggestions) // added
.on("queryChanged", this._getSuggestions)
.on("whitespaceChanged", this._updateHint)
.on("queryChanged whitespaceChanged", this._openDropdown)
.on("queryChanged whitespaceChanged", this._setLanguageDirection)
.on("escKeyed", this._closeDropdown).on("escKeyed", this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed", this._managePreventDefault).on("upKeyed downKeyed", this._moveDropdownCursor).on("upKeyed downKeyed", this._openDropdown).on("tabKeyed leftKeyed rightKeyed", this._autocomplete); |
This feature would be great. |
@andy3rdworld Thanks for that bit of code. That was the easiest fix without any problems. |
I need this feature too. The flickering is annoying. Too me it is more of a problem than the |
Same issue here. Does anyone know how to make @andy3rdworld changes work in the most recent release? I'm somewhat knew to js. |
FYI, this is something I want to fix. It's the next non-trivial issue I plan on looking addressing. |
Forgive my lack of understanding about the internals, but it seems to me that the most recently fetched list from remote should act like the prefetched list. Each time a call is made, that new list is the new "prefetched" list and gets updated accordingly. If I type "Mich" and ["Michael", "Michelle"] are in the list, I shouldn't need to wait for a new fetch when I type "a" to get "Michael". |
When typeahead.js gets remote suggestions back, they don't get added to the local data ( |
I see. The reason why I am not the expert. :) I think we can solve our problem with a combo (load ~1000 recent ones and then have remote for "backup"). |
Assuming your hit rate on prefetched suggestions isn't horrible, that should be a decent workaround. The dropdown will still become invisible after each keystroke, but unless you're using an older browser, the naked eye probably won't be able to notice. |
This provides a fix for [twitter#176](/../..twitter/issues/176). The behaviour of Bloodhound has been changed such that the #get callback is only run if matches in the search index (i.e. local or prefetched) have been found, or if we're not making a network request. The behaviour of Typeahead has been changed such that the dropdown is only cleared by the query changing if the query becomes an empty string.
This provides a fix for [twitter#176](/../..twitter/issues/176). The behaviour of Bloodhound has been changed such that the #get callback is only run if matches in the search index (i.e. local or prefetched) have been found, or if we're not making a network request. The behaviour of Typeahead has been changed such that the dropdown is only cleared by the query changing if the query becomes an empty string.
The behaviour of Bloodhound has been changed such that the #get callback is only run if matches in the search index (i.e. local or prefetched) have been found, or if we're not making a network request. The behaviour of Typeahead has been changed such that the dropdown is only cleared by the query changing if the query becomes an empty string.
The fix for this appears to have been lost in v 0.11. Can anyone confirm one way or the other? |
I'm experiencing the same issue and would like an option to fix it very much. It looks bad when the dropdown is flickering between each keystroke. |
@iMoses check out my fork here if you're in need of a quick fix: reverbdotcom@79b4f08 I was hoping to get an answer here and get another pull merged in (one of #1224, #1233, or #1212) before opening a pull for this. |
@joekur, Thanks! I was just starting to debug it, you saved me quite a lot of time 👍 Please update the official code ASAP, it's the only true problematic behavior I came across of an otherwise excellent library which I really want to keep using :) |
I'm having the same problem. Any hope for a fix? |
I'm facing the same problem. Anyone found the solution yet? |
Same issue here. |
Any update on this? I tried a few of the unofficial fixes (which did not help), but would like an official fix\response, as this issue makes the control unusable in my opinion. |
This project has apparently been abandoned. See https://github.com/corejavascript/typeahead.js where I believe many of these issues have already been resolved. |
Thanks. I was unaware. |
You can see this with the best pictures example here
Start typing 'broadway' (pre 1960 example that is not prefetched). At 'bro' it will be isolated from prefetched data. then each additional letter ('a', 'd', ...) will close + reopen dropdown with same value.
The text was updated successfully, but these errors were encountered: