When typing text into a contenteditable span in Safari or Firefox the caret moves to the start on each keypress. This only seems to happen when React re/renders the component.
Chrome works just fine. Haven't tested IE.
An example where |
is the caret and typing Hello
:
|
|H
|eH
|leH
|lleH
|olleH
Here's a simplified version of my component:
import React, { Component } from 'react';
class ContentEditable extends Component {
constructor(props) {
super(props);
this.state = {
value: props.value
};
}
createMarkup() {
return { __html: this.state.value };
}
handleInput(event) {
this.setState({
value: event.target.innerText
});
}
isValid() {
let bestLength = 3;
return this.state.value.length > bestLength;
}
render() {
let className = '';
if (this.isValid()) {
className = 'is-valid';
}
return (
<span
contentEditable="true"
onInput={ this.handleInput.bind(this) }
className={ className }
dangerouslySetInnerHTML={ this.createMarkup() }
>
</span>
);
}
}
ContentEditable.propTypes = {
value: React.PropTypes.string.isRequired
};
export default ContentEditable;
Anyone come across this before?