From 3a5036d51ff5816bf3e286ba6060abc90db093cd Mon Sep 17 00:00:00 2001 From: Aleksei Date: Mon, 23 Sep 2024 11:45:30 +0300 Subject: [PATCH] Allow the use of a custom input component (#739) --- .changeset/popular-toys-wait.md | 5 +++ .gitignore | 4 ++- README.md | 1 + demo/src/examples/CustomInputComponent.js | 37 +++++++++++++++++++++++ demo/src/examples/Examples.js | 2 ++ demo/src/examples/example.module.css | 22 ++++++++++++++ src/MentionsInput.js | 12 +++++--- src/MentionsInput.spec.js | 15 +++++++++ 8 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 .changeset/popular-toys-wait.md create mode 100644 demo/src/examples/CustomInputComponent.js diff --git a/.changeset/popular-toys-wait.md b/.changeset/popular-toys-wait.md new file mode 100644 index 00000000..52e72455 --- /dev/null +++ b/.changeset/popular-toys-wait.md @@ -0,0 +1,5 @@ +--- +"react-mentions": minor +--- + +Allow the use of a custom input component diff --git a/.gitignore b/.gitignore index c3f746cd..aac15554 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ npm-debug.log* -*.log \ No newline at end of file +*.log + +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index 6d2a7f2b..86b9cb23 100755 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ The `MentionsInput` supports the following props for configuring the widget: | forceSuggestionsAboveCursor | boolean | false | Forces the SuggestionList to be rendered above the cursor | | a11ySuggestionsListLabel | string | `''` | This label would be exposed to screen readers when suggestion popup appears | | customSuggestionsContainer | function(children) | empty function | Allows customizing the container of the suggestions | +| inputComponent | React component | undefined | Allows the use of a custom input component component | Each data source is configured using a `Mention` component, which has the following props: diff --git a/demo/src/examples/CustomInputComponent.js b/demo/src/examples/CustomInputComponent.js new file mode 100644 index 00000000..6de3e772 --- /dev/null +++ b/demo/src/examples/CustomInputComponent.js @@ -0,0 +1,37 @@ +import React from 'react' + +import { Mention, MentionsInput } from '../../../src' + +import { provideExampleValue } from './higher-order' +import defaultStyle from './defaultStyle' +import defaultMentionStyle from './defaultMentionStyle' + +// eslint-disable-next-line no-unused-vars +import classNames from './example.module.css' // uses global css selector + +const CustomInput = React.forwardRef((props, ref) => { + return