JedWatson/react-codemirror

Focus lost after typing character

alchy58 opened this issue · 2 comments

Hi,
I'm facing a strange issue, I suppose I did something wrong.
When I type a character, I lost the focus on the editor. Moreover, the autoFocus option did work so I need to click inside the editor before typing.
What have I missed ?

I'm using react-codemirror 1.0.0

import React from 'react'
import ReactMarkdown from 'react-markdown'
import CodeMirror from 'react-codemirror'
import 'codemirror/mode/markdown/markdown'

export default class TopicContentComponent extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            source: props.source,
        }
    }

    render () {
        const options = {
            lineNumbers: true,
            autoFocus: true,
            mode: 'markdown',
            theme: 'monokai',
        }

        const Preview = () => <ReactMarkdown source={this.state.source} />
        const Editor = () =>
            <CodeMirror
                value={this.state.source}
                onChange={(source) => this.setState({source})}
                options={options}
            />

        return (
            <div>
                <Preview />
                <Editor />
            </div>
        )
    }
}

Thank you

I am facing the same issue as well , the state change is causing this issue but i am unable to find a workaround.

+1 on this one