@@ -6,11 +6,15 @@ import classNames from 'classnames';
66/**
77 * WordPress dependencies
88 */
9+ import { DELETE , BACKSPACE } from '@wordpress/keycodes' ;
10+ import { useDispatch } from '@wordpress/data' ;
11+
912import {
1013 InspectorControls ,
1114 URLPopover ,
1215 URLInput ,
1316 useBlockProps ,
17+ store as blockEditorStore ,
1418} from '@wordpress/block-editor' ;
1519import { useState } from '@wordpress/element' ;
1620import {
@@ -32,40 +36,60 @@ const SocialLinkURLPopover = ( {
3236 setAttributes,
3337 setPopover,
3438 popoverAnchor,
35- } ) => (
36- < URLPopover anchor = { popoverAnchor } onClose = { ( ) => setPopover ( false ) } >
37- < form
38- className = "block-editor-url-popover__link-editor"
39- onSubmit = { ( event ) => {
40- event . preventDefault ( ) ;
41- setPopover ( false ) ;
42- } }
39+ clientId,
40+ } ) => {
41+ const { removeBlock } = useDispatch ( blockEditorStore ) ;
42+ return (
43+ < URLPopover
44+ anchor = { popoverAnchor }
45+ onClose = { ( ) => setPopover ( false ) }
4346 >
44- < div className = "block-editor-url-input" >
45- < URLInput
46- __nextHasNoMarginBottom
47- value = { url }
48- onChange = { ( nextURL ) =>
49- setAttributes ( { url : nextURL } )
50- }
51- placeholder = { __ ( 'Enter address' ) }
52- disableSuggestions = { true }
47+ < form
48+ className = "block-editor-url-popover__link-editor"
49+ onSubmit = { ( event ) => {
50+ event . preventDefault ( ) ;
51+ setPopover ( false ) ;
52+ } }
53+ >
54+ < div className = "block-editor-url-input" >
55+ < URLInput
56+ __nextHasNoMarginBottom
57+ value = { url }
58+ onChange = { ( nextURL ) =>
59+ setAttributes ( { url : nextURL } )
60+ }
61+ placeholder = { __ ( 'Enter address' ) }
62+ disableSuggestions = { true }
63+ onKeyDown = { ( event ) => {
64+ if (
65+ ! ! url ||
66+ event . defaultPrevented ||
67+ ! [ BACKSPACE , DELETE ] . includes (
68+ event . keyCode
69+ )
70+ ) {
71+ return ;
72+ }
73+ removeBlock ( clientId ) ;
74+ } }
75+ />
76+ </ div >
77+ < Button
78+ icon = { keyboardReturn }
79+ label = { __ ( 'Apply' ) }
80+ type = "submit"
5381 />
54- </ div >
55- < Button
56- icon = { keyboardReturn }
57- label = { __ ( 'Apply' ) }
58- type = "submit"
59- />
60- </ form >
61- </ URLPopover >
62- ) ;
82+ </ form >
83+ </ URLPopover >
84+ ) ;
85+ } ;
6386
6487const SocialLinkEdit = ( {
6588 attributes,
6689 context,
6790 isSelected,
6891 setAttributes,
92+ clientId,
6993} ) => {
7094 const { url, service, label, rel } = attributes ;
7195 const { showLabels, iconColorValue, iconBackgroundColorValue } = context ;
@@ -143,6 +167,7 @@ const SocialLinkEdit = ( {
143167 setAttributes = { setAttributes }
144168 setPopover = { setPopover }
145169 popoverAnchor = { popoverAnchor }
170+ clientId = { clientId }
146171 />
147172 ) }
148173 </ Button >
0 commit comments