diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index ba0d7298c567e..1c17b0696bd02 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -6,11 +6,15 @@ import clsx from 'clsx'; /** * WordPress dependencies */ +import { DELETE, BACKSPACE } from '@wordpress/keycodes'; +import { useDispatch } from '@wordpress/data'; + import { InspectorControls, URLPopover, URLInput, useBlockProps, + store as blockEditorStore, } from '@wordpress/block-editor'; import { useState } from '@wordpress/element'; import { @@ -32,7 +36,9 @@ const SocialLinkURLPopover = ( { setAttributes, setPopover, popoverAnchor, + clientId, } ) => { + const { removeBlock } = useDispatch( blockEditorStore ); return ( { + if ( + !! url || + event.defaultPrevented || + ! [ BACKSPACE, DELETE ].includes( + event.keyCode + ) + ) { + return; + } + removeBlock( clientId ); + } } />