Skip to content

Commit

Permalink
Quote Block: Fixing focus transfer between citation and content (#5100)
Browse files Browse the repository at this point in the history
* Quote Block: Fixing focus transfer between citation and content

* Update RichText's content before calling onSplit
  • Loading branch information
youknowriad authored Feb 16, 2018
1 parent 7e26164 commit a961fef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions blocks/library/pullquote/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
}

.wp-block-pullquote {
cite {
display: block;
}

cite .blocks-rich-text__tinymce[data-is-empty="true"]:before {
font-size: 14px;
font-family: $default-font;
Expand Down
4 changes: 4 additions & 0 deletions blocks/library/quote/editor.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.wp-block-quote {
margin: 0;

cite {
display: block;
}
}

.wp-block-quote:not(.is-large) {
Expand Down
4 changes: 3 additions & 1 deletion blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ export const settings = {
} )( ( { attributes, setAttributes, isSelected, mergeBlocks, onReplace, className, editable, setState } ) => {
const { align, value, citation, style } = attributes;
const containerClassname = classnames( className, style === 2 ? 'is-large' : '' );
const onSetActiveEditable = ( newEditable ) => () => setState( { editable: newEditable } );
const onSetActiveEditable = ( newEditable ) => () => {
setState( { editable: newEditable } );
};

return [
isSelected && (
Expand Down
26 changes: 21 additions & 5 deletions blocks/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export class RichText extends Component {
const beforeElement = nodeListToReact( beforeNodes, createTinyMCEElement );
const afterElement = nodeListToReact( afterNodes, createTinyMCEElement );

this.props.onSplit( beforeElement, afterElement );
this.restoreContentAndSplit( beforeElement, afterElement );
} else {
event.preventDefault();
this.onCreateUndoLevel();
Expand Down Expand Up @@ -638,9 +638,10 @@ export class RichText extends Component {

const beforeElement = nodeListToReact( beforeFragment.childNodes, createTinyMCEElement );
const afterElement = nodeListToReact( filterEmptyNodes( afterFragment.childNodes ), createTinyMCEElement );
this.props.onSplit( beforeElement, afterElement, ...blocks );

this.restoreContentAndSplit( beforeElement, afterElement, blocks );
} else {
this.props.onSplit( [], [], ...blocks );
this.restoreContentAndSplit( [], [], blocks );
}
}

Expand Down Expand Up @@ -686,7 +687,7 @@ export class RichText extends Component {
// Splitting into two blocks
this.setContent( this.props.value );

this.props.onSplit(
this.restoreContentAndSplit(
nodeListToReact( before, createTinyMCEElement ),
nodeListToReact( after, createTinyMCEElement )
);
Expand Down Expand Up @@ -740,7 +741,9 @@ export class RichText extends Component {
!! this.editor &&
this.props.tagName === prevProps.tagName &&
this.props.value !== prevProps.value &&
this.props.value !== this.savedContent
this.props.value !== this.savedContent &&
! isEqual( this.props.value, prevProps.value ) &&
! isEqual( this.props.value, this.savedContent )
) {
this.updateContent();
}
Expand Down Expand Up @@ -796,6 +799,19 @@ export class RichText extends Component {
} ) );
}

/**
* Calling onSplit means we need to abort the change done by TinyMCE.
* we need to call updateContent to restore the initial content before calling onSplit.
*
* @param {Array} before content before the split position
* @param {Array} after content after the split position
* @param {?Array} blocks blocks to insert at the split position
*/
restoreContentAndSplit( before, after, blocks ) {
this.updateContent();
this.props.onSplit( before, after, ...blocks );
}

render() {
const {
tagName: Tagname = 'div',
Expand Down

0 comments on commit a961fef

Please sign in to comment.