diff --git a/packages/block-editor/src/components/link-control/constants.js b/packages/block-editor/src/components/link-control/constants.js index 6c4b7dd42c4735..92727b7c8e0265 100644 --- a/packages/block-editor/src/components/link-control/constants.js +++ b/packages/block-editor/src/components/link-control/constants.js @@ -1,4 +1,16 @@ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; + // Used as a unique identifier for the "Create" option within search results. // Used to help distinguish the "Create" suggestion within the search results in // order to handle it as a unique case. export const CREATE_TYPE = '__CREATE__'; + +export const DEFAULT_LINK_SETTINGS = [ + { + id: 'opensInNewTab', + title: __( 'Open in new tab' ), + }, +]; diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index db6b005ac79fab..5b333a683cdb33 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -21,6 +21,7 @@ import LinkControlSearchInput from './search-input'; import LinkPreview from './link-preview'; import useCreatePage from './use-create-page'; import { ViewerFill } from './viewer-slot'; +import { DEFAULT_LINK_SETTINGS } from './constants'; /** * Default properties associated with a link control value. @@ -104,7 +105,7 @@ import { ViewerFill } from './viewer-slot'; function LinkControl( { searchInputPlaceholder, value, - settings, + settings = DEFAULT_LINK_SETTINGS, onChange = noop, onRemove, noDirectEntry = false, @@ -190,6 +191,11 @@ function LinkControl( { stopEditing(); }; + const shownUnlinkControl = + onRemove && value && ! isEditingLink && ! isCreatingPage; + + const showSettingsDrawer = !! settings?.length; + return (
) } -
- - { onRemove && value && ! isEditingLink && ! isCreatingPage && ( - - ) } -
+ { ( showSettingsDrawer || shownUnlinkControl ) && ( +
+ + { shownUnlinkControl && ( + + ) } +
+ ) }
); } 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 cdba15d6d4f7b9..ef1bf3e81afbbc 100644 --- a/packages/block-editor/src/components/link-control/settings-drawer.js +++ b/packages/block-editor/src/components/link-control/settings-drawer.js @@ -9,18 +9,7 @@ import { noop } from 'lodash'; import { __ } from '@wordpress/i18n'; import { ToggleControl, VisuallyHidden } from '@wordpress/components'; -const defaultSettings = [ - { - id: 'opensInNewTab', - title: __( 'Open in new tab' ), - }, -]; - -const LinkControlSettingsDrawer = ( { - value, - onChange = noop, - settings = defaultSettings, -} ) => { +const LinkControlSettingsDrawer = ( { value, onChange = noop, settings } ) => { if ( ! settings || ! settings.length ) { return null; } diff --git a/packages/block-editor/src/components/media-replace-flow/style.scss b/packages/block-editor/src/components/media-replace-flow/style.scss index 7af0f7bfbd2fce..1fd01cf8514832 100644 --- a/packages/block-editor/src/components/media-replace-flow/style.scss +++ b/packages/block-editor/src/components/media-replace-flow/style.scss @@ -23,12 +23,17 @@ padding: $grid-unit-15 $grid-unit-30 0; .block-editor-media-replace-flow__image-url-label { + display: block; top: $grid-unit-20; + margin-bottom: $grid-unit-10; } .block-editor-link-control { - margin-top: -16px; - width: auto; + width: 200px; // hardcoded width avoids resizing of control when switching between preview/edit + + .block-editor-url-input { + padding: 0; // cancel unnecessary default 1px padding in this case + } .components-base-control .components-base-control__field { margin-bottom: 0; @@ -36,7 +41,6 @@ .block-editor-link-control__search-item-title { max-width: 180px; - margin-top: $grid-unit-20; } .block-editor-link-control__search-item.is-current { @@ -45,11 +49,12 @@ } .block-editor-link-control__search-input.block-editor-link-control__search-input input[type="text"] { - margin: 16px 0 0 0; + margin: 0; width: 100%; } .block-editor-link-control__search-actions { + top: 0; // cancel default top positioning right: 4px; } }