Skip to content

Commit

Permalink
Blocks: Remove onFocus from core block's RichText (#7029)
Browse files Browse the repository at this point in the history
Use unstable, internal compatibility prop instead
  • Loading branch information
aduth authored and gziolo committed May 31, 2018
1 parent 6c8ab9b commit 5673eb8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core-blocks/gallery/gallery-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class GalleryImage extends Component {
value={ caption }
isSelected={ this.state.captionSelected }
onChange={ ( newCaption ) => setAttributes( { caption: newCaption } ) }
onFocus={ this.onSelectCaption }
unstableOnFocus={ this.onSelectCaption }
inlineToolbar
/>
) : null }
Expand Down
2 changes: 1 addition & 1 deletion core-blocks/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class ImageEdit extends Component {
tagName="figcaption"
placeholder={ __( 'Write caption…' ) }
value={ caption || [] }
onFocus={ this.onFocusCaption }
unstableOnFocus={ this.onFocusCaption }
onChange={ ( value ) => setAttributes( { caption: value } ) }
isSelected={ this.state.captionFocused }
inlineToolbar
Expand Down
26 changes: 26 additions & 0 deletions editor/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class RichText extends Component {
this.onInit = this.onInit.bind( this );
this.getSettings = this.getSettings.bind( this );
this.onSetup = this.onSetup.bind( this );
this.onFocus = this.onFocus.bind( this );
this.onChange = this.onChange.bind( this );
this.onNewBlock = this.onNewBlock.bind( this );
this.onNodeChange = this.onNodeChange.bind( this );
Expand Down Expand Up @@ -185,6 +186,7 @@ export class RichText extends Component {
editor.on( 'BeforeExecCommand', this.onPropagateUndo );
editor.on( 'PastePreProcess', this.onPastePreProcess, true /* Add before core handlers */ );
editor.on( 'paste', this.onPaste, true /* Add before core handlers */ );
editor.on( 'focus', this.onFocus );
editor.on( 'input', this.onChange );
// The change event in TinyMCE fires every time an undo level is added.
editor.on( 'change', this.onCreateUndoLevel );
Expand Down Expand Up @@ -399,6 +401,30 @@ export class RichText extends Component {
}
}

/**
* Handles a focus event on the contenteditable field, calling the
* `unstableOnFocus` prop callback if one is defined. The callback does not
* receive any arguments.
*
* This is marked as a private API and the `unstableOnFocus` prop is not
* documented, as the current requirements where it is used are subject to
* future refactoring following `isSelected` handling.
*
* In contrast with `setFocusedElement`, this is only triggered in response
* to focus within the contenteditable field, whereas `setFocusedElement`
* is triggered on focus within any `RichText` descendent element.
*
* @see setFocusedElement
*
* @private
*/
onFocus() {
const { unstableOnFocus } = this.props;
if ( unstableOnFocus ) {
unstableOnFocus();
}
}

/**
* Handles any case where the content of the TinyMCE instance has changed.
*/
Expand Down

0 comments on commit 5673eb8

Please sign in to comment.