webscopeio / react-textarea-autocomplete

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

Custom callback-based trigger #77

Closed glimow closed 6 years ago

glimow commented 6 years ago

This looks like a very nicely done component. I wondered if there is a more general way to trigger an autocomplete than using string matching, like a function that would take current text and caret position and returns a boolean e.g.

 trigger: (text, caretPosition) => {
   // some code that computes if autocomplete should trigger or not
}

As I want to provide grammar-based autocomplete rather than character-based one.

jukben commented 6 years ago

That's actually interesting idea. I will try to play with it and come up with some solution. 👍

P.S: I like the suggested API I'll try to stick with it.

glimow commented 6 years ago

Thanks for the answer, that's awesome ! I'll definitely keep an eye on this

jukben commented 6 years ago

Hey, @glimow could you please elaborate more how you're thinking about this feature?

Let's say that I will create such a prop, but right now for example trigger character has relation to dataProvider. With your approach, I can only decide when to open the autocomplete, but which data should I load?

It probably doesn't make a sense to have such a possibility bound to some trigger char, right?

jukben commented 6 years ago

Ping @glimow 😸

jukben commented 6 years ago

Closing for now for inactivity.