Skip to content

Commit

Permalink
feat: start and end position arguments for onAdd callback (#492)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhil2kumar authored May 25, 2021
1 parent 3ff626d commit 1e4bd38
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Each data source is configured using a `Mention` component, which has the follow
| markup | string | `'@[__display__](__id__)'` | A template string for the markup to use for mentions |
| displayTransform | function (id, display) | returns `display` | Accepts a function for customizing the string that is displayed for a mention |
| regex | RegExp | automatically derived from `markup` pattern | Allows providing a custom regular expression for parsing your markup and extracting the placeholder interpolations (optional) | |
| onAdd | function (id, display) | empty function | Callback invoked when a suggestion has been added (optional) |
| onAdd | function (id, display, startPos, endPos) | empty function | Callback invoked when a suggestion has been added (optional) |
| appendSpaceOnAdd | boolean | `false` | Append a space when a suggestion has been added (optional) |

If a function is passed as the `data` prop, that function will be called with the current search query as first, and a callback function as second argument. The callback can be used to provide results asynchronously, e.g., after fetch requests. (It can even be called multiple times to update the list of suggestions.)
Expand Down
2 changes: 1 addition & 1 deletion src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ class MentionsInput extends React.Component {
this.executeOnChange(eventMock, newValue, newPlainTextValue, mentions)

if (onAdd) {
onAdd(id, display)
onAdd(id, display, start, end)
}

// Make sure the suggestions overlay is closed
Expand Down

1 comment on commit 1e4bd38

@vercel
Copy link

@vercel vercel bot commented on 1e4bd38 May 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.