Skip to content
Closed
Show file tree
Hide file tree
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
72 changes: 37 additions & 35 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ function LinkControl( {

const currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length;

const shownUnlinkControl =
onRemove && value && ! isEditingLink && ! isCreatingPage;
const shownUnlinkControl = onRemove && value && ! isCreatingPage;

const showActions = isEditingLink && hasLinkValue;

Expand All @@ -356,6 +355,41 @@ function LinkControl( {
</div>
) }

{ hasLinkValue && ! isCreatingPage && (
<LinkPreview
key={ value?.url } // force remount when URL changes to avoid race conditions for rich previews
value={ value }
isEditing={ isEditing }
onEditClick={ () => setIsEditingLink( true ) }
hasRichPreviews={ hasRichPreviews }
hasUnlinkControl={ shownUnlinkControl }
additionalControls={ () => {
// Expose the "Opens in new tab" settings in the preview
// as it is the most common setting to change.
if (
! isEditing &&
settings?.find(
( setting ) => setting.id === 'opensInNewTab'
)
) {
return (
<LinkSettings
value={ internalControlValue }
settings={ settings?.filter(
( { id } ) => id === 'opensInNewTab'
) }
onChange={ onChange }
/>
);
}
} }
onRemove={ () => {
onRemove();
setIsEditingLink( true );
} }
/>
) }

{ isEditing && (
<>
<div
Expand All @@ -377,6 +411,7 @@ function LinkControl( {
size="__unstable-large"
/>
) }

<LinkControlSearchInput
currentLink={ value }
className="block-editor-link-control__field block-editor-link-control__search-input"
Expand Down Expand Up @@ -420,39 +455,6 @@ function LinkControl( {
</>
) }

{ value && ! isEditingLink && ! isCreatingPage && (
<LinkPreview
key={ value?.url } // force remount when URL changes to avoid race conditions for rich previews
value={ value }
onEditClick={ () => setIsEditingLink( true ) }
hasRichPreviews={ hasRichPreviews }
hasUnlinkControl={ shownUnlinkControl }
additionalControls={ () => {
// Expose the "Opens in new tab" settings in the preview
// as it is the most common setting to change.
if (
settings?.find(
( setting ) => setting.id === 'opensInNewTab'
)
) {
return (
<LinkSettings
value={ internalControlValue }
settings={ settings?.filter(
( { id } ) => id === 'opensInNewTab'
) }
onChange={ onChange }
/>
);
}
} }
onRemove={ () => {
onRemove();
setIsEditingLink( true );
} }
/>
) }

{ showSettings && (
<div className="block-editor-link-control__tools">
{ ! currentInputIsEmpty && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function LinkPreview( {
hasUnlinkControl = false,
onRemove,
additionalControls,
isEditing,
} ) {
// Avoid fetching if rich previews are not desired.
const showRichPreviews = hasRichPreviews ? value?.url : null;
Expand Down Expand Up @@ -120,7 +121,9 @@ export default function LinkPreview( {
className="block-editor-link-control__search-item-action"
onClick={ onEditClick }
size="compact"
disabled={ isEditing }
/>

{ hasUnlinkControl && (
<Button
icon={ linkOff }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ $block-editor-link-control-number-of-actions: 1;
width: 100%;
cursor: default;
padding: $grid-unit-20;
border-bottom: 1px solid $gray-200;
}

.block-editor-link-control__search-item-header {
Expand Down