From 49cd9633fc5666c6cea9c3ee8382b2269baf851f Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 20 Jan 2020 10:51:25 -0500 Subject: [PATCH] Block Editor: Link Control: Use URL as link when title empty (#19739) --- .../block-editor/src/components/link-control/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 625218febd00f3..38fec35f6ab6b6 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -10,7 +10,6 @@ import { noop, startsWith } from 'lodash'; import { Button, ExternalLink, VisuallyHidden } from '@wordpress/components'; import { __, sprintf } from '@wordpress/i18n'; import { useCallback, useState, Fragment } from '@wordpress/element'; - import { safeDecodeURI, filterURLForDisplay, @@ -18,7 +17,6 @@ import { prependHTTP, getProtocol, } from '@wordpress/url'; - import { useInstanceId } from '@wordpress/compose'; import { useSelect } from '@wordpress/data'; @@ -44,6 +42,7 @@ function LinkControl( { fetchSearchSuggestions: getSettings().__experimentalFetchLinkSuggestions, }; }, [] ); + const displayURL = ( value && filterURLForDisplay( safeDecodeURI( value.url ) ) ) || ''; /** * onChange LinkControlSearchInput event handler @@ -175,9 +174,13 @@ function LinkControl( { className="block-editor-link-control__search-item-title" href={ value.url } > - { value.title } + { ( value && value.title ) || displayURL } - { filterURLForDisplay( safeDecodeURI( value.url ) ) || '' } + { value && value.title && ( + + { displayURL } + + ) }