From 388ec6e4362ac423e2653228d905564117c6cc53 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 18 Sep 2018 10:44:33 +0100 Subject: [PATCH] Fix custom classNames for dynamic blocks --- packages/editor/src/hooks/custom-class-name.js | 3 +-- .../editor/src/hooks/test/custom-class-name.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/hooks/custom-class-name.js b/packages/editor/src/hooks/custom-class-name.js index 093863fbb7bd0..9779dfd1a2bb5 100644 --- a/packages/editor/src/hooks/custom-class-name.js +++ b/packages/editor/src/hooks/custom-class-name.js @@ -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 ( @@ -145,7 +144,7 @@ export function addParsedDifference( blockAttributes, blockType, innerHTML ) { if ( customClasses.length ) { blockAttributes.className = customClasses.join( ' ' ); - } else { + } else if ( serialized ) { delete blockAttributes.className; } } diff --git a/packages/editor/src/hooks/test/custom-class-name.js b/packages/editor/src/hooks/test/custom-class-name.js index ea7b441de8459..6b2c84b886139 100644 --- a/packages/editor/src/hooks/test/custom-class-name.js +++ b/packages/editor/src/hooks/test/custom-class-name.js @@ -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' ); @@ -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' ); + } ); } ); } );