contentEditable value is getting wiped out (question)
See original GitHub issueI am not sure what I am doing wrong but certainly contentEditable value is getting reset on blur. Sorry for stupid question (I did search but did not find anything related to it.) also it is working in React set up but not in this setup
To reproduce JSfiddle https://jsfiddle.net/q4bbceg2/1/
problematic part of code is this
class ChildComponent extends Component {
constructor() {
super();
this.state = {
inputActive: false,
};
}
render() {
return ( <div
role="button" style="border:1px solid red;"
tabIndex="0"
onFocus={() => { this.setState({ inputActive: true }); }}
onBlur={() => { this.setState({ inputActive: false }); }}
ref={(e) => { this.userInput = e; }}
contentEditable="true"
placeholder="Write a reply..."
className="sc-user-input--text"
>AAA
</div>)
}
}
I just wondering what I am missing here, if someone can point me in right direction it would be great.
Here is the same code in react https://jsfiddle.net/69z2wepo/173750/
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Why does React warn against an contentEditable component ...
The disadvantage would be that you might forget and get stuck wondering why user content is getting destroyed. No suppressing the error doesn't ......
Read more >contenteditable - HTML: HyperText Markup Language | MDN
Chrome Edge
contenteditable Full support. ChromeYes. Toggle history Full suppo...
contenteditable="caret". Experimental Full support. ChromeYes. Toggle history Full suppo...
contenteditable="events". Experimental Full support. ChromeYes. Toggle history...
Read more >226941 - Contenteditable issues related to backspace handling
In DOM there is a <strong> element, then we are editing <strong> element, not bold text. The <strong> element has been removed from...
Read more >Adjustable Form Text Area with the contenteditable Tag
A contenteditable div will keep the formatting and tags of whatever is pasted into it, which may be a headache if it needs...
Read more >Fixing ContentEditable - Medium
That's pretty much the situation of contentEditable today. The difference here is that in order to fix it, first you need to convince...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In react diffing is done with comparing two vnodes, so in react, state change triggers a rerender, but vnode has not changed, so no changes applies to DOM, thus your own change to DOM preserves.
But in preact diffing is done with DOM node reference and vnode. In rerender preact would think vnode has changed thus a update on DOM, which applies the original vnode to DOM.
@paritoshmmmec The safest way to do it in both
react
andpreact
is to store the content inside the componentsstate
. Here is the fixed version of your fiddle: https://jsfiddle.net/q4bbceg2/4/