Skip to content

Commit 6f66087

Browse files
committed
Adding the autoFocus attribute, closes JedWatson#101
1 parent 3cecf93 commit 6f66087

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

example/src/example.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ var App = createReactClass({
3737
readOnly: !this.state.readOnly
3838
}, () => this.refs.editor.focus());
3939
},
40-
interact (cm) {
41-
console.log(cm.getValue());
42-
},
4340
render () {
4441
var options = {
4542
lineNumbers: true,
@@ -48,7 +45,7 @@ var App = createReactClass({
4845
};
4946
return (
5047
<div>
51-
<Codemirror ref="editor" value={this.state.code} onChange={this.updateCode} options={options} interact={this.interact} />
48+
<Codemirror ref="editor" value={this.state.code} onChange={this.updateCode} options={options} autoFocus={true} />
5249
<div style={{ marginTop: 10 }}>
5350
<select onChange={this.changeMode} value={this.state.mode}>
5451
<option value="markdown">Markdown</option>

src/Codemirror.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function normalizeLineEndings (str) {
1414

1515
const CodeMirror = createReactClass({
1616
propTypes: {
17+
autoFocus: PropTypes.bool,
1718
className: PropTypes.any,
1819
codeMirrorInstance: PropTypes.func,
1920
defaultValue: PropTypes.string,
@@ -116,7 +117,13 @@ const CodeMirror = createReactClass({
116117
);
117118
return (
118119
<div className={editorClassName}>
119-
<textarea ref="textarea" name={this.props.path} defaultValue={this.props.value} autoComplete="off" />
120+
<textarea
121+
ref="textarea"
122+
name={this.props.path}
123+
defaultValue={this.props.value}
124+
autoComplete="off"
125+
autoFocus={this.props.autoFocus}
126+
/>
120127
</div>
121128
);
122129
},

0 commit comments

Comments
 (0)