diff --git a/packages/editor/src/components/rich-text/index.js b/packages/editor/src/components/rich-text/index.js index 57cea883c75c..5a0807dc6595 100644 --- a/packages/editor/src/components/rich-text/index.js +++ b/packages/editor/src/components/rich-text/index.js @@ -93,6 +93,7 @@ export class RichText extends Component { this.onSetup = this.onSetup.bind( this ); this.onFocus = this.onFocus.bind( this ); + this.onBlur = this.onBlur.bind( this ); this.onChange = this.onChange.bind( this ); this.onDeleteKeyDown = this.onDeleteKeyDown.bind( this ); this.onKeyDown = this.onKeyDown.bind( this ); @@ -129,14 +130,6 @@ export class RichText extends Component { this.lastHistoryValue = value; } - componentDidMount() { - document.addEventListener( 'selectionchange', this.onSelectionChange ); - } - - componentWillUnmount() { - document.removeEventListener( 'selectionchange', this.onSelectionChange ); - } - setRef( node ) { this.editableRef = node; } @@ -354,6 +347,12 @@ export class RichText extends Component { if ( unstableOnFocus ) { unstableOnFocus(); } + + document.addEventListener( 'selectionchange', this.onSelectionChange ); + } + + onBlur() { + document.removeEventListener( 'selectionchange', this.onSelectionChange ); } /** @@ -891,6 +890,7 @@ export class RichText extends Component { onCompositionEnd={ this.onCompositionEnd } onKeyDown={ this.onKeyDown } onFocus={ this.onFocus } + onBlur={ this.onBlur } multilineTag={ this.multilineTag } multilineWrapperTags={ this.multilineWrapperTags } setRef={ this.setRef } diff --git a/packages/editor/src/components/rich-text/tinymce.js b/packages/editor/src/components/rich-text/tinymce.js index 3a825fb995af..a29117bdce24 100644 --- a/packages/editor/src/components/rich-text/tinymce.js +++ b/packages/editor/src/components/rich-text/tinymce.js @@ -350,6 +350,7 @@ export default class TinyMCE extends Component { onInput, onKeyDown, onCompositionEnd, + onBlur, } = this.props; /* @@ -377,6 +378,7 @@ export default class TinyMCE extends Component { onPaste, onInput, onFocus: this.onFocus, + onBlur, onKeyDown, onCompositionEnd, } );