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

feat: support allowTriggerInQuery #756

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The `MentionsInput` supports the following props for configuring the widget:
| singleLine | boolean | `false` | Renders a single line text input instead of a textarea, if set to `true` |
| onBlur | function (event, clickedSuggestion) | empty function | Passes `true` as second argument if the blur was caused by a mousedown on a suggestion |
| allowSpaceInQuery | boolean | false | Keep suggestions open even if the user separates keywords with spaces. |
| allowTriggerInQuery | boolean | false | Keep suggestions open even if the user separates keywords with trigger. |
| suggestionsPortalHost | DOM Element | undefined | Render suggestions into the DOM in the supplied host element. |
| inputRef | React ref | undefined | Accepts a React ref to forward to the underlying input element |
| allowSuggestionsAboveCursor | boolean | false | Renders the SuggestionList above the cursor if there is not enough space below |
Expand Down
2 changes: 1 addition & 1 deletion src/Mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Mention.propTypes = {
* If set to `true` spaces will not interrupt matching suggestions
*/
allowSpaceInQuery: PropTypes.bool,

allowTriggerInQuery: PropTypes.bool,
isLoading: PropTypes.bool,
}

Expand Down
5 changes: 3 additions & 2 deletions src/MentionsInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export const makeTriggerRegex = function(trigger, options = {}) {
if (trigger instanceof RegExp) {
return trigger
} else {
const { allowSpaceInQuery } = options
const { allowSpaceInQuery,allowTriggerInQuery } = options
const escapedTriggerChar = escapeRegex(trigger)

// first capture group is the part to be replaced on completion
// second capture group is for extracting the search query
return new RegExp(
`(?:^|\\s)(${escapedTriggerChar}([^${
allowSpaceInQuery ? '' : '\\s'
}${escapedTriggerChar}]*))$`
}${allowTriggerInQuery ? '' : escapedTriggerChar}]*))$`
)
}
}
Expand Down Expand Up @@ -72,6 +72,7 @@ const propTypes = {
*/
singleLine: PropTypes.bool,
allowSpaceInQuery: PropTypes.bool,
allowTriggerInQuery: PropTypes.bool,
allowSuggestionsAboveCursor: PropTypes.bool,
forceSuggestionsAboveCursor: PropTypes.bool,
ignoreAccents: PropTypes.bool,
Expand Down