react-mentions icon indicating copy to clipboard operation
react-mentions copied to clipboard

Offer a function to extract mentions from value

Open zenVentzi opened this issue 6 years ago • 7 comments

There is an onAdd function where we can get the added mentions but there is no onRemove, which is just as needed in most cases.

The second best solution to my awareness is to derive the mentions from the onChange callback. Problem is, one's knowledge of regex expressions must be sufficient to do the job. And in most cases, where we'd like to have the most basic use recovered, one will have to spend quite some time learning regex expressions just to get basics working and only to forget them later on.

Of course there will be many developers comfortable with regexes but this issue would be useful for those who aren't.

zenVentzi avatar Apr 02 '19 08:04 zenVentzi

I'd like to ask again why you need to know when a mention is removed. We've never needed this functionality in the last years. It would help greatly to understand what you're doing that requires knowledge of when that part of the text is removed.

frontendphil avatar Apr 03 '19 09:04 frontendphil

Appreciate the response! Using Backspace. E.g. user mentions @frontendphil but then decides to "backspace" remove that mention. The idea is to keep track of the mentions and then, "onSubmit" submit both the comment's text and the mentioned users.

I could be wrong but to my current awareness, onAdd is called when user selects a suggestion, then presses Enter but then on "Backspace" these mentions do not get updated from anywhere

zenVentzi avatar Apr 03 '19 13:04 zenVentzi

An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.

For my use case, this library without the ability to extract the mentioned users, is not sufficient at all.

xtrinch avatar Feb 10 '20 08:02 xtrinch

An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.

@xtrinch The list of all mentioned items is already passed to the onChange handler as 4th argument (see https://github.com/signavio/react-mentions#configuration).

jfschwarz avatar Feb 10 '20 09:02 jfschwarz

Okay, then that kind of also solves the original poster's problem, doesn't it? I missed that in the documentation completely.

May be worth investing an additional line in the documentation for onChange to make that clearer.

xtrinch avatar Feb 10 '20 09:02 xtrinch

An idea is to perhaps just append the list of mentioned identifiers in the onChange handler.

@xtrinch The list of all mentioned items is already passed to the onChange handler as 4th argument (see https://github.com/signavio/react-mentions#configuration).

I think this solves all of the use cases.

frnk01 avatar Dec 23 '20 08:12 frnk01

@jfschwarz Perhaps one weakness is that if I change the markup, that also affects the object returned in the mentions object in the onChange function. I would like the mentions object to hold the full user object that was sent to the component.

Any other way to solve this perhaps?

frnk01 avatar Dec 23 '20 10:12 frnk01