tribute
tribute copied to clipboard
Tribute container does not reopen after searching for a non-existing value
How can we reproduce this bug?
- Step one Trigger the tribute component, e.g. by pressing "@"
- Step two Type in a letter combination that exists in the values array, e.g. "Jor". "Jordan Hemphrey" is shown.
- Step three Add an "f" so that you typed in "Jorf" which is a combination that does not exist in the values array. The tribute container disappears.
- Step four Press backspace to delete the "f", so that only "Jor" is displayed.
What did you expect to happen? The tribute container should reappear, showing "Jordan Hemphrey", basically showing all available options starting with "Jor".
What happened instead? The tribute container does not reopen. The user has to delete the whole value "@Jor", even including the "@" symbol, and type it in again to retrigger the tribute container and search for another value.
Link (jsfiddle/plunkr/codepen) or Screenshot:
Any progress with that?
@hyojin, are you planning to work on it soon?
@NitzanShifrin Hi, I did quickly go through the code and it seems it's intended behavior (at least with the current code). Unfortunately, I don't know the background of this 🤔
I got around this with this code
selectTemplate: function (item) {
if(item) {
return '@' + item.original.name;
} else {
// required to prevent lockup and console error when pressing enter/tab on no match found
return '@' + this.current.mentionText;
}
},
noMatchTemplate: function() {
return '<li>No Match Found!</li>';
},
change selectTemplate's first return to whatever you were returning before.
@mxgl Should we update the default selectTemplate
to return the current mentionText on no match?
That's what I do
It creates a scenario where typing @abc<space>
leaves the @abc
in the textarea rather than erasing the mention entirely.
Edit: it seems this doesn't erase the mention, but rather prevents the console error saying that the item doesn't exist if you press Enter
or Tab
(I should read my own comments)
Also, having the noMatchTemplate defined by default keeps the menu open the entire time, allowing backspacing back to a search with results to function more smoothly!
Can you make it return
return this.current.collection.trigger + this.current.mentionText;
In case there's a different trigger.
Done!
@mrsweaters Sorry, I really appreciate the effort you put on this library but this did not fix the main bug. The problem is that the current behaviour is inconsistent when the noMatchTemplate returns an empty string (which is a requirement in my case, not to show the noMatchTemplate). When you type something that exists and you delete a character, the list of results is still shown but as soon you type a word that does not exist, the whole list is removed, even if it was the same word that returned results before. Is that inconsistency expected?
@lcwalther is there a reason an empty noMatchTemplate is required?
You could try
noMatchTemplate: function () {
return '<span style:"visibility: hidden;"></span>;
}
@mxgl's workaround seems to work. I'll add that to the docs.
@mxgl @mrsweaters I tried it, but with this an empty list is shown instead of nothing at all, which is what I need in my case.
Could you explain your use case a little bit more? Why do you need nothing rendering? You could add a class to it and set pointer-events: none
if you are worried about someone interacting with it. Hmm, but that does leave the empty ul
. That's what you want removed?
Yes, exactly, I want the ul
removed because it looks like this, when using <span style:"visibility: hidden;"></span>
:
Basically, I want the same behaviour as when e.g. mentioning users here in this comment window on Github.
What if we add a class to the ul
, like tribute-no-match
so you can hide it?
Sorry for getting back to you so late @mrsweaters
Would this class be only added to the ul
when there is no match? Then this solution would be perfect!
What if we add a class to the
ul
, liketribute-no-match
so you can hide it?
Looking forward to this, too!
Hi, I still have some issues with this.
- I need to
allowSpaces
. - I need the backspace to re-open the suggestions, but not until it has a match.
- I would like the
noMatchTemplate
to return null, but then backspace won't re-open suggestions. - I use it in a
textarea
so I need enter click to create a newline. With the solution above editing theselectTemplate
it would make it not break, but I would have to hit enter twice if there is a trigger anywhere in the textarea (before my newline), even if it is on a separate line.
codepen: https://codepen.io/andershj/pen/PoKGxYj?editors=1010
Any other way to get this to work?