react-contenteditable icon indicating copy to clipboard operation
react-contenteditable copied to clipboard

If any of the styled(e.g <b>, <a>) HTML tags are used in default state, the continuing text comes under those tags only.

Open Puspendert opened this issue 5 years ago • 7 comments

If the state has <b>hello/<b> and then we type into the ContentEdittable, then all of the new text comes into the <b>hello new text</>. For new text to come out of the <b> the state should have some text written outside the <b>. E.g <b>hello/<b>.

Here is a codesandbox https://codesandbox.io/s/polished-hooks-xxkxj?file=/src/App.js:0-906

Puspendert avatar Apr 20 '20 10:04 Puspendert

Hello. I don't think this is an issue with react-contenteditable. This is just how contenteditable works in the browser. It's your application's responsibility to handle that case.

lovasoa avatar Apr 20 '20 10:04 lovasoa

I made it working through my code. Moving the caret to the last.

Puspendert avatar Apr 21 '20 20:04 Puspendert

I made it working through my code. Moving the caret to the last.

can you share how you do that? I have the same issue here, thank you!

Sashagi avatar Sep 06 '20 14:09 Sashagi

@Puspendert Can you please share how did you do that? Having the same issue.

im-amir avatar Oct 06 '22 15:10 im-amir

@im-amir Not sure what I wanted to do and what solution did I put 😅. But doesn't the codesandbox link above provide a solution?

Puspendert avatar Oct 06 '22 16:10 Puspendert

Nope, I tried to add the useEffect code in my change handler, but the issue is still same. The continuing text comes inside the last added html tag. :(

im-amir avatar Oct 06 '22 16:10 im-amir

I think a lucky day for me. :) Adding a contenteditable="false" to the custom HTML added will bring the continuing text out of this custom HTML. setMessage(`${message}<span class="variable-text" contenteditable="false">${variable}</span>`) image

im-amir avatar Oct 06 '22 16:10 im-amir