Skip to content

Commit

Permalink
Adding the autoFocus attribute, closes #101
Browse files Browse the repository at this point in the history
  • Loading branch information
JedWatson committed May 14, 2017
1 parent 3cecf93 commit 6f66087
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 1 addition & 4 deletions example/src/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ var App = createReactClass({
readOnly: !this.state.readOnly
}, () => this.refs.editor.focus());
},
interact (cm) {
console.log(cm.getValue());
},
render () {
var options = {
lineNumbers: true,
Expand All @@ -48,7 +45,7 @@ var App = createReactClass({
};
return (
<div>
<Codemirror ref="editor" value={this.state.code} onChange={this.updateCode} options={options} interact={this.interact} />
<Codemirror ref="editor" value={this.state.code} onChange={this.updateCode} options={options} autoFocus={true} />
<div style={{ marginTop: 10 }}>
<select onChange={this.changeMode} value={this.state.mode}>
<option value="markdown">Markdown</option>
Expand Down
9 changes: 8 additions & 1 deletion src/Codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function normalizeLineEndings (str) {

const CodeMirror = createReactClass({
propTypes: {
autoFocus: PropTypes.bool,
className: PropTypes.any,
codeMirrorInstance: PropTypes.func,
defaultValue: PropTypes.string,
Expand Down Expand Up @@ -116,7 +117,13 @@ const CodeMirror = createReactClass({
);
return (
<div className={editorClassName}>
<textarea ref="textarea" name={this.props.path} defaultValue={this.props.value} autoComplete="off" />
<textarea
ref="textarea"
name={this.props.path}
defaultValue={this.props.value}
autoComplete="off"
autoFocus={this.props.autoFocus}
/>
</div>
);
},
Expand Down

0 comments on commit 6f66087

Please sign in to comment.