Skip to content

Commit

Permalink
Fix custom classNames for dynamic blocks (#9995)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Sep 18, 2018
1 parent f874704 commit 7c7e764
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/editor/src/hooks/custom-class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export function addAttribute( settings ) {
export const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => {
return ( props ) => {
const hasCustomClassName = hasBlockSupport( props.name, 'customClassName', true );

if ( hasCustomClassName && props.isSelected ) {
return (
<Fragment>
Expand Down Expand Up @@ -145,7 +144,7 @@ export function addParsedDifference( blockAttributes, blockType, innerHTML ) {

if ( customClasses.length ) {
blockAttributes.className = customClasses.join( ' ' );
} else {
} else if ( serialized ) {
delete blockAttributes.className;
}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/editor/src/hooks/test/custom-class-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ describe( 'custom className', () => {
title: 'block title',
};

const dynamicBlockSettings = {
save: () => null,
category: 'common',
title: 'block title',
};

describe( 'addAttribute()', () => {
const addAttribute = applyFilters.bind( null, 'blocks.registerBlockType' );

Expand Down Expand Up @@ -150,5 +156,15 @@ describe( 'custom className', () => {

expect( attributes.className ).toBe( 'custom1 custom3' );
} );

it( 'should not remove the custom classes for dynamic blocks', () => {
const attributes = addParsedDifference(
{ className: 'custom1' },
dynamicBlockSettings,
null,
);

expect( attributes.className ).toBe( 'custom1' );
} );
} );
} );

0 comments on commit 7c7e764

Please sign in to comment.