From be4a70331e3bf0b6d53ad75034b61bfe04eb5c00 Mon Sep 17 00:00:00 2001 From: saleeh Date: Sun, 9 Dec 2018 12:02:35 -0600 Subject: [PATCH 1/2] Fixed Deleting an HTML Anchor attribute leaves an empty HTML id attribute --- packages/editor/src/hooks/anchor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/editor/src/hooks/anchor.js b/packages/editor/src/hooks/anchor.js index 66b1c4f01eef4..714dced6c70b2 100644 --- a/packages/editor/src/hooks/anchor.js +++ b/packages/editor/src/hooks/anchor.js @@ -73,7 +73,7 @@ export const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => onChange={ ( nextValue ) => { nextValue = nextValue.replace( ANCHOR_REGEX, '-' ); props.setAttributes( { - anchor: nextValue, + anchor: nextValue === '' ? null : nextValue, } ); } } /> From 4c43c0201e21c06d58b0f3df121ea2b5b40bc945 Mon Sep 17 00:00:00 2001 From: saleeh Date: Sun, 9 Dec 2018 13:20:23 -0600 Subject: [PATCH 2/2] Fixed Deleting an HTML Anchor attribute leaves an empty --- packages/editor/src/hooks/anchor.js | 4 ++-- packages/editor/src/hooks/test/anchor.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/editor/src/hooks/anchor.js b/packages/editor/src/hooks/anchor.js index 714dced6c70b2..3af32e39ef2ac 100644 --- a/packages/editor/src/hooks/anchor.js +++ b/packages/editor/src/hooks/anchor.js @@ -73,7 +73,7 @@ export const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => onChange={ ( nextValue ) => { nextValue = nextValue.replace( ANCHOR_REGEX, '-' ); props.setAttributes( { - anchor: nextValue === '' ? null : nextValue, + anchor: nextValue, } ); } } /> @@ -98,7 +98,7 @@ export const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => */ export function addSaveProps( extraProps, blockType, attributes ) { if ( hasBlockSupport( blockType, 'anchor' ) ) { - extraProps.id = attributes.anchor; + extraProps.id = attributes.anchor === '' ? null : attributes.anchor; } return extraProps; diff --git a/packages/editor/src/hooks/test/anchor.js b/packages/editor/src/hooks/test/anchor.js index 74bfa2e20dfc2..21a5c65be83cb 100644 --- a/packages/editor/src/hooks/test/anchor.js +++ b/packages/editor/src/hooks/test/anchor.js @@ -62,5 +62,17 @@ describe( 'anchor', () => { expect( extraProps.id ).toBe( 'foo' ); } ); + + it( 'should remove an anchor attribute ID when feild is cleared', () => { + const attributes = { anchor: '' }; + const extraProps = getSaveContentExtraProps( {}, { + ...blockSettings, + supports: { + anchor: true, + }, + }, attributes ); + + expect( extraProps.id ).toBe( null ); + } ); } ); } );