diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js
index 73e2f6bb8e0e1d..a63723e463d813 100644
--- a/packages/block-editor/src/components/link-control/index.js
+++ b/packages/block-editor/src/components/link-control/index.js
@@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
-import { Button, Spinner, Notice, TextControl } from '@wordpress/components';
+import { Button, Spinner, Notice } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useRef, useState, useEffect } from '@wordpress/element';
import { focus } from '@wordpress/dom';
@@ -136,6 +136,8 @@ function LinkControl( {
const textInputRef = useRef();
const isEndingEditWithFocus = useRef( false );
+ const [ settingsOpen, setSettingsOpen ] = useState( false );
+
const [ internalUrlInputValue, setInternalUrlInputValue ] =
useInternalInputValue( value?.url || '' );
@@ -201,6 +203,7 @@ function LinkControl( {
wrapperNode.current.ownerDocument.activeElement
);
+ setSettingsOpen( false );
setIsEditingLink( false );
};
@@ -267,7 +270,7 @@ function LinkControl( {
const shownUnlinkControl =
onRemove && value && ! isEditingLink && ! isCreatingPage;
- const showSettingsDrawer = !! settings?.length;
+ const showSettings = !! settings?.length;
// Only show text control once a URL value has been committed
// and it isn't just empty whitespace.
@@ -275,6 +278,7 @@ function LinkControl( {
const showTextControl = hasLinkValue && hasTextControl;
const isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;
+
return (
- { showTextControl && (
-
- ) }
-
) }
-
- { showSettingsDrawer && (
-
+ { isEditing && (
+
+ { ( showSettings || showTextControl ) && (
-
- ) }
+ ) }
- { isEditing && (
- ) }
-
+
+ ) }
{ renderControlBottom && renderControlBottom() }
diff --git a/packages/block-editor/src/components/link-control/settings-drawer.js b/packages/block-editor/src/components/link-control/settings-drawer.js
index 4b9d0d7f7419e7..e58b4409645b33 100644
--- a/packages/block-editor/src/components/link-control/settings-drawer.js
+++ b/packages/block-editor/src/components/link-control/settings-drawer.js
@@ -1,41 +1,96 @@
/**
* WordPress dependencies
*/
+import {
+ Button,
+ TextControl,
+ __unstableMotion as motion,
+ __unstableAnimatePresence as AnimatePresence,
+} from '@wordpress/components';
+import { settings as settingsIcon } from '@wordpress/icons';
+import { useReducedMotion, useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
-import { ToggleControl, VisuallyHidden } from '@wordpress/components';
-
-const noop = () => {};
+import { Fragment } from '@wordpress/element';
+/**
+ * Internal dependencies
+ */
+import Settings from './settings';
-const LinkControlSettingsDrawer = ( { value, onChange = noop, settings } ) => {
- if ( ! settings || ! settings.length ) {
- return null;
- }
+function LinkSettingsDrawer( {
+ settingsOpen,
+ setSettingsOpen,
+ showTextControl,
+ showSettings,
+ textInputRef,
+ internalTextInputValue,
+ setInternalTextInputValue,
+ handleSubmitWithEnter,
+ value,
+ settings,
+ onChange,
+} ) {
+ const prefersReducedMotion = useReducedMotion();
+ const MaybeAnimatePresence = prefersReducedMotion
+ ? Fragment
+ : AnimatePresence;
+ const MaybeMotionDiv = prefersReducedMotion ? 'div' : motion.div;
- const handleSettingChange = ( setting ) => ( newValue ) => {
- onChange( {
- ...value,
- [ setting.id ]: newValue,
- } );
- };
+ const id = useInstanceId( LinkSettingsDrawer );
- const theSettings = settings.map( ( setting ) => (
-
- ) );
+ const settingsDrawerId = `link-control-settings-drawer-${ id }`;
return (
-
+ <>
+