Skip to content

Commit 79b16c1

Browse files
committed
Revert "Avoid deleting the block when pressing delete key one too many times in URLPopover"
This reverts commit 78a8521.
1 parent 25ccad7 commit 79b16c1

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

packages/block-library/src/social-link/edit.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ import clsx from 'clsx';
66
/**
77
* WordPress dependencies
88
*/
9+
import { DELETE, BACKSPACE } from '@wordpress/keycodes';
10+
import { useDispatch } from '@wordpress/data';
11+
912
import {
1013
InspectorControls,
1114
URLPopover,
1215
URLInput,
1316
useBlockProps,
17+
store as blockEditorStore,
1418
} from '@wordpress/block-editor';
1519
import { useState } from '@wordpress/element';
1620
import {
@@ -32,7 +36,9 @@ const SocialLinkURLPopover = ( {
3236
setAttributes,
3337
setPopover,
3438
popoverAnchor,
39+
clientId,
3540
} ) => {
41+
const { removeBlock } = useDispatch( blockEditorStore );
3642
return (
3743
<URLPopover
3844
anchor={ popoverAnchor }
@@ -61,6 +67,18 @@ const SocialLinkURLPopover = ( {
6167
label={ __( 'Enter social link' ) }
6268
hideLabelFromVision
6369
disableSuggestions
70+
onKeyDown={ ( event ) => {
71+
if (
72+
!! url ||
73+
event.defaultPrevented ||
74+
! [ BACKSPACE, DELETE ].includes(
75+
event.keyCode
76+
)
77+
) {
78+
return;
79+
}
80+
removeBlock( clientId );
81+
} }
6482
/>
6583
</div>
6684
<Button
@@ -78,6 +96,7 @@ const SocialLinkEdit = ( {
7896
context,
7997
isSelected,
8098
setAttributes,
99+
clientId,
81100
} ) => {
82101
const { url, service, label = '', rel } = attributes;
83102
const {
@@ -165,6 +184,7 @@ const SocialLinkEdit = ( {
165184
setAttributes={ setAttributes }
166185
setPopover={ setPopover }
167186
popoverAnchor={ popoverAnchor }
187+
clientId={ clientId }
168188
/>
169189
) }
170190
</li>

0 commit comments

Comments
 (0)