Search code examples
javascriptreactjsdrag-and-drophighlightdrag

To Highlight a word/text and drag to other text box in React


Is it possible to highlight a word or text in One text box and be able to drag the highlighted(selected) text or word to other text from a complete sentence that would be present in the first text box in React?

I have seen a package but that's for React Native not for the web.


Solution

  • You can Use React-DnD and use a Drag and Drop Operation, https://react-dnd.github.io/react-dnd/docs/overview

    You have to implement the same with text so that you can Drag and Drop them

    function collect(connect, monitor) {
      return {
        highlighted: monitor.canDrop(),
        hovered: monitor.isOver(),
        connectDropTarget: connect.dropTarget()
      }
    }