diff --git a/.changeset/six-actors-clean.md b/.changeset/six-actors-clean.md new file mode 100644 index 00000000..2b3ad04e --- /dev/null +++ b/.changeset/six-actors-clean.md @@ -0,0 +1,5 @@ +--- +"react-mentions": minor +--- + +Added RenderInput diff --git a/README.md b/README.md index 3d37bd9b..5d339acf 100755 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ You can find more examples here: [demo/src/examples](https://github.com/signavio The `MentionsInput` supports the following props for configuring the widget: | Prop name | Type | Default value | Description | -| --------------------------- | ------------------------------------------------------- | -------------- | -------------------------------------------------------------------------------------- | +|-----------------------------|---------------------------------------------------------|----------------|----------------------------------------------------------------------------------------| | value | string | `''` | The value containing markup for mentions | | onChange | function (event, newValue, newPlainTextValue, mentions) | empty function | A callback that is invoked when the user changes the value in the mentions input | | onKeyDown | function (event) | empty function | A callback that is invoked when the user presses a key in the mentions input | @@ -63,6 +63,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 | +| renderInput | React component | undefined | Allows customizing the input element | Each data source is configured using a `Mention` component, which has the following props: diff --git a/demo/src/examples/Examples.js b/demo/src/examples/Examples.js index 1e1e7e82..e828a842 100644 --- a/demo/src/examples/Examples.js +++ b/demo/src/examples/Examples.js @@ -13,6 +13,7 @@ import SingleLineIgnoringAccents from './SingleLineIgnoringAccents' import SuggestionPortal from './SuggestionPortal' import BottomGuard from './BottomGuard' import CustomSuggestionsContainer from './CustomSuggestionsContainer' +import RendererInput from './RenderInput' const users = [ { @@ -90,6 +91,7 @@ export default function Examples() { + ) diff --git a/demo/src/examples/RenderInput.js b/demo/src/examples/RenderInput.js new file mode 100644 index 00000000..11389929 --- /dev/null +++ b/demo/src/examples/RenderInput.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' + +const CustomRenderer = React.forwardRef((props, ref) => ( + +)) + +function RenderInput({ value, data, onChange, onAdd }) { + return ( +
+

Single line input

+ + + + +
+ ) +} + +const asExample = provideExampleValue('') + +export default asExample(RenderInput) diff --git a/src/MentionsInput.js b/src/MentionsInput.js index 08c7c545..01374913 100755 --- a/src/MentionsInput.js +++ b/src/MentionsInput.js @@ -101,6 +101,8 @@ const propTypes = { PropTypes.element, PropTypes.arrayOf(PropTypes.element), ]).isRequired, + + renderInput: PropTypes.elementType, } class MentionsInput extends React.Component { @@ -183,7 +185,7 @@ class MentionsInput extends React.Component { ) } - setContainerElement = (el) => { + setContainerElement = el => { this.containerElement = el } @@ -229,28 +231,35 @@ class MentionsInput extends React.Component { } renderControl = () => { - let { singleLine, style } = this.props + let { singleLine, style, renderInput } = this.props let inputProps = this.getInputProps() return (
{this.renderHighlighter()} - {singleLine + {renderInput + ? this.renderCustom(inputProps) + : singleLine ? this.renderInput(inputProps) : this.renderTextarea(inputProps)}
) } - renderInput = (props) => { + renderCustom = props => { + let { renderInput: RenderInput } = this.props + return + } + + renderInput = props => { return } - renderTextarea = (props) => { - return