From 518ac08c21d7a35b5031a59bf357f48143975db1 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 25 Jan 2024 20:25:34 +0000 Subject: [PATCH] Go directly to edit mode after initial creation --- packages/format-library/src/link/inline.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index c12ccc0b08f7f..ff8b7868212e7 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -1,7 +1,11 @@ /** * WordPress dependencies */ -import { useMemo, createInterpolateElement } from '@wordpress/element'; +import { + useMemo, + createInterpolateElement, + useState, +} from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { speak } from '@wordpress/a11y'; import { Popover } from '@wordpress/components'; @@ -48,6 +52,8 @@ function InlineLinkUI( { stopAddingLink, contentRef, } ) { + const [ justCreated, setJustCreated ] = useState( false ); + const richLinkTextValue = getRichTextValueFromSelection( value, isActive ); // Get the text content minus any HTML tags. @@ -182,8 +188,11 @@ function InlineLinkUI( { // being created for the first time. If it is then focus should remain within the // Link UI because it should remain open for the user to modify the link they have // just created. - if ( ! isNewLink ) { + if ( isNewLink ) { + setJustCreated( true ); + } else { stopAddingLink(); + setJustCreated( false ); } if ( ! isValidHref( newUrl ) ) { @@ -250,6 +259,12 @@ function InlineLinkUI( { ); } + // If the link is being created for the first time then force the Link UI + // to be in edit mode so that the user can modify the link they have just + // created. Passing undefined will allow the default behaviour to continue + // uninterrupted. + const forceEditMode = justCreated ? true : undefined; + return ( );