From 0c1ca8fe6b30208e3d7255abd80fa6d743abd591 Mon Sep 17 00:00:00 2001 From: Alf Eaton <eaton.alf@gmail.com> Date: Wed, 15 Nov 2017 22:33:55 +0000 Subject: [PATCH] Fire onBlur event --- packages/xpub-edit/src/components/Editor.js | 9 +++++++++ packages/xpub-edit/src/components/HtmlEditor.js | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/xpub-edit/src/components/Editor.js b/packages/xpub-edit/src/components/Editor.js index c3f16a06e..26c0d4ab4 100644 --- a/packages/xpub-edit/src/components/Editor.js +++ b/packages/xpub-edit/src/components/Editor.js @@ -28,8 +28,17 @@ class Editor extends React.Component { }), attributes: { class: classnames(baseClasses.ProseMirror, classes.ProseMirror) + }, + handleDOMEvents: { + blur: this.props.onBlur ? view => { + this.props.onBlur(view.state.doc.content) + } : null } }) + + if (this.props.autoFocus) { + this.view.focus() + } } dispatchTransaction = transaction => { diff --git a/packages/xpub-edit/src/components/HtmlEditor.js b/packages/xpub-edit/src/components/HtmlEditor.js index 3adb67dc8..9f6ff1456 100644 --- a/packages/xpub-edit/src/components/HtmlEditor.js +++ b/packages/xpub-edit/src/components/HtmlEditor.js @@ -26,7 +26,7 @@ const serializer = schema => { class HtmlEditor extends React.Component { componentWillMount () { - const { value, onChange, options } = this.props + const { value, onChange, onBlur, options } = this.props const { schema } = options const parse = parser(schema) @@ -37,6 +37,10 @@ class HtmlEditor extends React.Component { this.onChange = debounce(value => { onChange(serialize(value)) }, 1000, { maxWait: 5000 }) + + this.onBlur = value => { + onBlur(serialize(value)) + } } render () { @@ -50,6 +54,7 @@ class HtmlEditor extends React.Component { placeholderClassName={placeholderClassName} title={title} onChange={this.onChange} + onBlur={this.onBlur} /> ) } -- GitLab