Skip to content

Commit

Permalink
Revert "Avoid deleting the block when pressing delete key one too man…
Browse files Browse the repository at this point in the history
…y times in URLPopover"

This reverts commit 78a8521.
  • Loading branch information
talldan committed May 3, 2024
1 parent c6f1d5d commit b64b824
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import classNames from 'classnames';
/**
* 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 {
Expand All @@ -32,7 +36,9 @@ const SocialLinkURLPopover = ( {
setAttributes,
setPopover,
popoverAnchor,
clientId,
} ) => {
const { removeBlock } = useDispatch( blockEditorStore );
return (
<URLPopover
anchor={ popoverAnchor }
Expand Down Expand Up @@ -61,6 +67,18 @@ const SocialLinkURLPopover = ( {
label={ __( 'Enter social link' ) }
hideLabelFromVision
disableSuggestions
onKeyDown={ ( event ) => {
if (
!! url ||
event.defaultPrevented ||
! [ BACKSPACE, DELETE ].includes(
event.keyCode
)
) {
return;
}
removeBlock( clientId );
} }
/>
</div>
<Button
Expand All @@ -78,6 +96,7 @@ const SocialLinkEdit = ( {
context,
isSelected,
setAttributes,
clientId,
} ) => {
const { url, service, label = '', rel } = attributes;
const {
Expand Down Expand Up @@ -165,6 +184,7 @@ const SocialLinkEdit = ( {
setAttributes={ setAttributes }
setPopover={ setPopover }
popoverAnchor={ popoverAnchor }
clientId={ clientId }
/>
) }
</li>
Expand Down

0 comments on commit b64b824

Please sign in to comment.