Search code examples
reactjsdraftjs

Draft.js - How to apply custom entity to current selection only?


I'm using a sample code found here to implement a custom entity for links.

What is the current behavior?

Select a portion of text, and create a link. Then keep typing after the link is created, and the editor will mark all characters you type in as a part of the link.

What is the expected behavior?

The link should be created for the current selection only. When you type more characters after creating a link, they should be plain text, not a link.


Solution

  • I ended up using IMMUTABLE entity.

    https://draftjs.org/docs/advanced-topics-entities.html#mutability