Skip to content

Commit

Permalink
#9634 cherry picked tempararly; This commit should be deleted as soon…
Browse files Browse the repository at this point in the history
… as the other PR is merged
  • Loading branch information
jorgefilipecosta committed Sep 5, 2018
1 parent fc56484 commit 3669265
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/editor/src/hooks/align.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { assign, get, includes } from 'lodash';
*/
import { createHigherOrderComponent } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import { hasBlockSupport, getBlockSupport } from '@wordpress/blocks';
import { hasBlockSupport, getBlockSupport, getBlockType } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -77,7 +77,17 @@ export const withToolbarControls = createHigherOrderComponent( ( BlockEdit ) =>
return ( props ) => {
const validAlignments = getBlockValidAlignments( props.name );

const updateAlignment = ( nextAlign ) => props.setAttributes( { align: nextAlign } );
const updateAlignment = ( nextAlign ) => {
if ( ! nextAlign ) {
const blockType = getBlockType( props.name );
const blockDefaultAlign = get( blockType, [ 'attributes', 'align', 'default' ] );
if ( blockDefaultAlign ) {
props.setAttributes( { align: 'none' } );
return;
}
}
props.setAttributes( { align: nextAlign } );
};

return [
validAlignments.length > 0 && props.isSelected && (
Expand Down

0 comments on commit 3669265

Please sign in to comment.