Skip to content

Commit

Permalink
Fix: Align Hook: Impossible to set no alignment when a default align …
Browse files Browse the repository at this point in the history
…exists
  • Loading branch information
jorgefilipecosta committed Sep 21, 2018
1 parent a8bc550 commit d36d40a
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 d36d40a

Please sign in to comment.