tribute icon indicating copy to clipboard operation
tribute copied to clipboard

Tribute container does not reopen after searching for a non-existing value

Open lcwalther opened this issue 5 years ago • 18 comments

How can we reproduce this bug?

  1. Step one Trigger the tribute component, e.g. by pressing "@"
  2. Step two Type in a letter combination that exists in the values array, e.g. "Jor". "Jordan Hemphrey" is shown.
  3. 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.
  4. 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: image

lcwalther avatar Jan 10 '20 16:01 lcwalther

Any progress with that?

NitzanShifrin avatar Feb 10 '20 14:02 NitzanShifrin

@hyojin, are you planning to work on it soon?

NitzanShifrin avatar Feb 11 '20 12:02 NitzanShifrin

@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 🤔

hyojin avatar Feb 14 '20 00:02 hyojin

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 avatar Mar 06 '20 15:03 mxgl

@mxgl Should we update the default selectTemplate to return the current mentionText on no match?

mrsweaters avatar Mar 06 '20 22:03 mrsweaters

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!

mxgl avatar Mar 06 '20 22:03 mxgl

Can you make it return

return this.current.collection.trigger + this.current.mentionText;

In case there's a different trigger.

mxgl avatar Mar 06 '20 22:03 mxgl

Done!

mrsweaters avatar Mar 06 '20 22:03 mrsweaters

@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 avatar Mar 10 '20 10:03 lcwalther

@lcwalther is there a reason an empty noMatchTemplate is required?

You could try

noMatchTemplate: function () {
    return '<span style:"visibility: hidden;"></span>;
}

mxgl avatar Mar 10 '20 14:03 mxgl

@mxgl's workaround seems to work. I'll add that to the docs.

mrsweaters avatar Mar 10 '20 16:03 mrsweaters

@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.

lcwalther avatar Mar 10 '20 17:03 lcwalther

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?

mrsweaters avatar Mar 10 '20 17:03 mrsweaters

Yes, exactly, I want the ul removed because it looks like this, when using <span style:"visibility: hidden;"></span>: image

Basically, I want the same behaviour as when e.g. mentioning users here in this comment window on Github.

lcwalther avatar Mar 10 '20 19:03 lcwalther

What if we add a class to the ul, like tribute-no-match so you can hide it?

mrsweaters avatar Mar 10 '20 19:03 mrsweaters

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!

lcwalther avatar Mar 17 '20 15:03 lcwalther

What if we add a class to the ul, like tribute-no-match so you can hide it?

Looking forward to this, too!

halloei avatar May 14 '20 10:05 halloei

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 the selectTemplate 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.

tribute-bug-4

codepen: https://codepen.io/andershj/pen/PoKGxYj?editors=1010

Any other way to get this to work?

andersHj avatar Oct 22 '21 13:10 andersHj