Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Puspendert opened this issue Apr 20, 2020 · 7 comments

Comments

@Puspendert
Copy link

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

@lovasoa
Copy link
Owner

lovasoa commented Apr 20, 2020

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.

@Puspendert
Copy link
Author

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

@Sashagi
Copy link

Sashagi commented Sep 6, 2020

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!

@im-amir
Copy link

im-amir commented Oct 6, 2022

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

@Puspendert
Copy link
Author

@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?

@im-amir
Copy link

im-amir commented Oct 6, 2022

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
Copy link

im-amir commented Oct 6, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants