Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render edit view upon initial link creation in rich text #58279

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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 (
<Popover
anchor={ popoverAnchor }
Expand Down Expand Up @@ -278,6 +293,7 @@ function InlineLinkUI( {
perPage: 20,
},
} }
forceIsEditingLink={ forceEditMode }
/>
</Popover>
);
Expand Down
Loading