webscopeio / react-textarea-autocomplete

📝 React component implements configurable GitHub's like textarea autocomplete.
MIT License
451 stars 80 forks source link

When using caretPosition: "end", the autocomplete box doesn't disappear when pressing Enter/Tab. #101

Closed jukben closed 5 years ago

jukben commented 5 years ago

100

@guidogast

Also, when using caretPosition: "end", the autocomplete box doesn't disappear when pressing Enter/Tab.

jukben commented 5 years ago

@guidogast

I dug more into it and, actually, I'm not sure how to solve it. It's not a bug but more like feature. Your trigger is [ and you are returning [something that means that the trigger is still active thus the autocomplete is shown. Not sure how easily distinguish that you are satisfied with the selection and you don't wanna show the autocomplete anymore.

Fist thought I had was that I can track "dirtiness" of the input. e.g once you select the item I can hide the autocomplete unless you start typing (without space) more, or unless you start with deleting the current text. Both of this would lead autocomplete to open because the trigger char would be still the [. Does it make a sense? I'm not sure if this solves the issue for you.

guido-visser commented 5 years ago

@jukben Thanks for checking the issue. Logic that makes sense to me would be something similar to Visual Studio (Code):

Once you press a trigger key, it should show the autocomplete. When you press "Enter/Return" or "Tab", the selected value will be inserted and the autocomplete should disappear. Don't search for triggers after it's been inserted (Unless you retrigger it via another default autocomplete trigger (Ctrl + Space would be awesome))

This way, the issues that I'm experiencing would be solved and it would make this plugin unbelievably powerful 😄.

Is this use case clear for you?

jukben commented 5 years ago

Thanks for the input. Makes sense. I'll try to do some exploration. Stay tuned. 🤓

I'll take Code as an example, good idea!

jukben commented 5 years ago

Hey, it would be wonderful @guidogast if you can try this branch https://github.com/webscopeio/react-textarea-autocomplete/pull/107 I'd appreciate your feedback! 🙏

Edit: This is sneak peek from the playground: demoproject

jukben commented 5 years ago

Closed in #107