Skip to content
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

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

Open
lcwalther opened this issue Jan 10, 2020 · 18 comments
Open
Labels

Comments

@lcwalther
Copy link

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

@NitzanShifrin
Copy link

Any progress with that?

@NitzanShifrin
Copy link

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

@hyojin
Copy link
Contributor

hyojin commented Feb 14, 2020

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

@mxgl
Copy link

mxgl commented Mar 6, 2020

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.

@mrsweaters
Copy link
Collaborator

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

@mrsweaters mrsweaters added the bug label Mar 6, 2020
@mxgl
Copy link

mxgl commented Mar 6, 2020

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
Copy link

mxgl commented Mar 6, 2020

Can you make it return

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

In case there's a different trigger.

@mrsweaters
Copy link
Collaborator

Done!

@lcwalther
Copy link
Author

lcwalther commented Mar 10, 2020

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

@mxgl
Copy link

mxgl commented Mar 10, 2020

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

You could try

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

@mrsweaters
Copy link
Collaborator

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

@lcwalther
Copy link
Author

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

@mrsweaters
Copy link
Collaborator

mrsweaters commented Mar 10, 2020

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?

@lcwalther
Copy link
Author

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.

@mrsweaters mrsweaters reopened this Mar 10, 2020
@mrsweaters
Copy link
Collaborator

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

@lcwalther
Copy link
Author

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!

@halloei
Copy link

halloei commented May 14, 2020

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

Looking forward to this, too!

@andersHj
Copy link

andersHj commented Oct 22, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants