Draft.js Fiddle
A fiddle to repro issues in Draft.js
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/immutable/3.8.1/immutable.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/draft-js/0.9.1/Draft.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/draft-js/0.9.1/Draft.css">
<div id="react-root"></div>
CSS
body {
font-family: Helvetica, sans-serif;
}
.container-root {
border: 1px solid black;
padding: 5px;
margin: 5px;
height: 100px;
overflow-y: scroll;
}
Babel + JSX
const {Editor, EditorState, CompositeDecorator} = Draft;
const SimpleSpan = (props) => {
return <span {...props} style={{background:'blue'}}>{props.children}</span>;
}
function simpleStrategy(contentBlock, callback) {
const textLength = contentBlock.getText().length;
if (textLength >= 200) {
callback(199, textLength);
//callback(199, 299); //comment the previous line out and this one in and it works....
}
}
const compositeDecorator = new CompositeDecorator([
{
strategy: simpleStrategy,
component: SimpleSpan
}
]);
class Container extends React.Component {
constructor(props) {
super(props);
this.state = {
editorState: EditorState.createEmpty(compositeDecorator)
};
}
render() {
return (
<div className="container-root">
<Editor
placeholder="Type away :)"
editorState={this.state.editorState}
onChange={this._handleChange}
/>
</div>
);
}
_handleChange = (editorState) => {
this.setState({editorState});
}
}
ReactDOM.render(<Container />, document.getElementById('react-root'))