Skip to content

Commit

Permalink
Fix for #11663 (#12728)
Browse files Browse the repository at this point in the history
* Fixed Deleting an HTML Anchor attribute leaves an empty HTML id attribute

* Fixed Deleting an HTML Anchor attribute leaves an empty
  • Loading branch information
saleehk authored and noisysocks committed Dec 10, 2018
1 parent b44a2f1 commit 47736a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/editor/src/hooks/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions packages/editor/src/hooks/test/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
} );
} );

0 comments on commit 47736a4

Please sign in to comment.