Skip to content

Commit

Permalink
Fix editor refs (#1183)
Browse files Browse the repository at this point in the history
* fix editor refs

* address aman comments
  • Loading branch information
JamesPortelli authored and amanmahajan7 committed May 10, 2018
1 parent e57d20f commit 3dbf4b3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ module.exports = (ContainerEditor) => {
return this.editorRef.getValue();
}

createRef = (ref) => {
this.editorRef = ref;
}

render() {
return (<ContainerEditor refCallback={(ref) => { this.editorRef = ref; }} {...this.props} />);
return (<ContainerEditor refCallback={this.createRef} {...this.props} />);
}
};
};
2 changes: 1 addition & 1 deletion packages/react-data-grid-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Adazzle",
"license": "MIT",
"dependencies": {
"immutability-helper": "^2.4.0",
"immutability-helper": "^2.7.0",
"react-data-grid": "^4.0.7",
"react-data-grid-addons": "^4.0.7",
"react-router-dom": "^4.2.2"
Expand Down
11 changes: 7 additions & 4 deletions packages/react-data-grid/src/editors/EditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ class EditorContainer extends React.Component {
}
};

createEditorRef = (ref) => {
this.editor = ref;
}

createEditor = (): ReactElement => {
let editorRef = (c) => this.editor = c;
let editorProps = {
ref: editorRef,
ref: this.createEditorRef,
column: this.props.column,
value: this.getInitialValue(),
onCommit: this.commit,
Expand All @@ -99,10 +102,10 @@ class EditorContainer extends React.Component {
return React.cloneElement(CustomEditor, editorProps);
}
if (isFunction(CustomEditor)) {
return <CustomEditor ref={editorRef} {...editorProps} />;
return <CustomEditor ref={this.createEditorRef} {...editorProps} />;
}

return <SimpleTextEditor ref={editorRef} column={this.props.column} value={this.getInitialValue()} onBlur={this.commit} rowMetaData={this.getRowMetaData()} onKeyDown={() => {}} commit={() => {}}/>;
return <SimpleTextEditor ref={this.createEditorRef} column={this.props.column} value={this.getInitialValue()} onBlur={this.commit} rowMetaData={this.getRowMetaData()} onKeyDown={() => {}} commit={() => {}}/>;
};

onPressEnter = () => {
Expand Down

0 comments on commit 3dbf4b3

Please sign in to comment.