From d7582aa551972d3a02a58d42967488edf2ced5b5 Mon Sep 17 00:00:00 2001 From: bernie-shi <130951707+bernie-shi@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:31:08 +0800 Subject: [PATCH] feat: support allowTriggerInQuery --- README.md | 1 + src/Mention.js | 2 +- src/MentionsInput.js | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d2a7f2b..b025644e 100755 --- a/README.md +++ b/README.md @@ -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 | diff --git a/src/Mention.js b/src/Mention.js index 36bdc687..e9955168 100644 --- a/src/Mention.js +++ b/src/Mention.js @@ -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, } diff --git a/src/MentionsInput.js b/src/MentionsInput.js index 68e6b73d..0b28f29e 100755 --- a/src/MentionsInput.js +++ b/src/MentionsInput.js @@ -29,7 +29,7 @@ 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 @@ -37,7 +37,7 @@ export const makeTriggerRegex = function(trigger, options = {}) { return new RegExp( `(?:^|\\s)(${escapedTriggerChar}([^${ allowSpaceInQuery ? '' : '\\s' - }${escapedTriggerChar}]*))$` + }${allowTriggerInQuery ? '' : escapedTriggerChar}]*))$` ) } } @@ -72,6 +72,7 @@ const propTypes = { */ singleLine: PropTypes.bool, allowSpaceInQuery: PropTypes.bool, + allowTriggerInQuery: PropTypes.bool, allowSuggestionsAboveCursor: PropTypes.bool, forceSuggestionsAboveCursor: PropTypes.bool, ignoreAccents: PropTypes.bool,