Skip to content

Commit

Permalink
add getRef to the plugins methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nihaux committed Oct 17, 2016
1 parent c913a20 commit f2e28c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions HOW_TO_CREATE_A_PLUGIN.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ All functions receive an additional argument. This argument is an object contain
getEditorState, // a function to get the current EditorState
getReadOnly, // a function returning of the Editor is set to readOnly
setReadOnly, // a function which allows to set the Editor to readOnly
getRef, // a function to get the editor reference
}
```

Expand Down
2 changes: 2 additions & 0 deletions draft-js-plugins-editor/src/Editor/__test__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ describe('Editor', () => {
getProps: pluginEditor.getProps,
getReadOnly: pluginEditor.getReadOnly,
setReadOnly: pluginEditor.setReadOnly,
getRef: pluginEditor.getRef,
};
draftEditor.props.handleKeyCommand('command');
expect(plugin.handleKeyCommand).has.been.calledOnce();
Expand Down Expand Up @@ -303,6 +304,7 @@ describe('Editor', () => {
getProps: pluginEditor.getProps,
getReadOnly: pluginEditor.getReadOnly,
setReadOnly: pluginEditor.setReadOnly,
getRef: pluginEditor.getRef,
};
draftEditor.props.blockRendererFn('command');
expect(plugin.blockRendererFn).has.been.calledOnce();
Expand Down
3 changes: 3 additions & 0 deletions draft-js-plugins-editor/src/Editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class PluginEditor extends Component {
if (readOnly !== this.state.readOnly) this.setState({ readOnly });
};

getRef = () => this.editor;

getEditorState = () => this.props.editorState;
getPluginMethods = () => ({
getPlugins: this.getPlugins,
Expand All @@ -105,6 +107,7 @@ class PluginEditor extends Component {
getEditorState: this.getEditorState,
getReadOnly: this.getReadOnly,
setReadOnly: this.setReadOnly,
getRef: this.getRef,
});

createEventHooks = (methodName, plugins) => (...args) => {
Expand Down

0 comments on commit f2e28c7

Please sign in to comment.