Added a render prop to Mention component for custom rendering the display value#502
Added a render prop to Mention component for custom rendering the display value#502nikhil2kumar wants to merge 7 commits intosignavio:masterfrom
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/signavio/react-mentions/ApJRr7Y36K1aDsgrdEYuXew9ASM6 |
Codecov Report
@@ Coverage Diff @@
## master #502 +/- ##
==========================================
- Coverage 78.84% 78.76% -0.09%
==========================================
Files 32 32
Lines 695 697 +2
Branches 108 109 +1
==========================================
+ Hits 548 549 +1
- Misses 146 147 +1
Partials 1 1
Continue to review full report at Codecov.
|
|
This would be a much needed addition for my needs as well! |
8265bf0 to
8dedc5d
Compare
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
I would love this as well. |
|
was this merged yet? i also want this as well |
|
Any update? |
|
Really need support for this, can we get this merged please? |
|
Since internally this library uses only Mention props, we can create our own Mention component that just follows the same API, so to make it work I did: const Mention = ({
id,
render,
display,
}) => {
if (render) {
return render({ children: display, label: display, value: id });
}
return <strong {...props}>{display}</strong>;
};
Mention.defaultProps = {
onAdd: () => null,
markup: "@[__display__](__id__)",
trigger: "@",
onRemove: () => null,
isLoading: false,
displayTransform: (id?: string | number, display?: string) => display || id,
renderSuggestion: null,
appendSpaceOnAdd: false,
};And then I just use this Mention instead of the library one |

This PR includes the addition of the render method to the Mention component.
The method has display parameters and expects to return a react component to render the mention display value.
This would come in handy if there's a need to pass our own component instead of relying on the default functionality.
<Tooltip title="customTitleGoesHere"> <strong className="myClassName">{display}</strong> </Tooltip>