Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks: Remove onFocus from core blocks' RichText usage #7029

Merged
merged 1 commit into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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