diff --git a/docs/reference-guides/core-blocks.md b/docs/reference-guides/core-blocks.md index d0eb25b807e6d..3c8ee800d31aa 100644 --- a/docs/reference-guides/core-blocks.md +++ b/docs/reference-guides/core-blocks.md @@ -860,7 +860,7 @@ Displays the name of this site. Update the block, and the changes apply everywhe ## Social Icon -Display an icon linking to a social media profile or site. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/social-link)) +Display an icon linking to a social profile or site. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/social-link)) - **Name:** core/social-link - **Category:** widgets @@ -870,7 +870,7 @@ Display an icon linking to a social media profile or site. ([Source](https://git ## Social Icons -Display icons linking to your social media profiles or sites. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/social-links)) +Display icons linking to your social profiles or sites. ([Source](https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/social-links)) - **Name:** core/social-links - **Category:** widgets diff --git a/packages/block-library/src/social-link/block.json b/packages/block-library/src/social-link/block.json index d487465ef7966..37e8376f22ff0 100644 --- a/packages/block-library/src/social-link/block.json +++ b/packages/block-library/src/social-link/block.json @@ -5,7 +5,7 @@ "title": "Social Icon", "category": "widgets", "parent": [ "core/social-links" ], - "description": "Display an icon linking to a social media profile or site.", + "description": "Display an icon linking to a social profile or site.", "textdomain": "default", "attributes": { "url": { diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index e08f8e6697cba..8873a4ae22082 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -23,7 +23,7 @@ import { PanelRow, TextControl, } from '@wordpress/components'; -import { __, sprintf } from '@wordpress/i18n'; +import { __ } from '@wordpress/i18n'; import { keyboardReturn } from '@wordpress/icons'; /** @@ -58,7 +58,9 @@ const SocialLinkURLPopover = ( { onChange={ ( nextURL ) => setAttributes( { url: nextURL } ) } - placeholder={ __( 'Enter address' ) } + placeholder={ __( 'Enter social link' ) } + label={ __( 'Enter social link' ) } + hideLabelFromVision disableSuggestions onKeyDown={ ( event ) => { if ( @@ -91,7 +93,7 @@ const SocialLinkEdit = ( { setAttributes, clientId, } ) => { - const { url, service, label, rel } = attributes; + const { url, service, label = '', rel } = attributes; const { showLabels, iconColor, @@ -113,7 +115,12 @@ const SocialLinkEdit = ( { const IconComponent = getIconBySite( service ); const socialLinkName = getNameBySite( service ); - const socialLinkLabel = label ?? socialLinkName; + // The initial label (ie. the link text) is an empty string. + // We want to prevent empty links so that the link text always fallbacks to + // the social name, even when users enter and save an empty string or only + // spaces. The PHP render callback fallbacks to the social name as well. + const socialLinkText = label.trim() === '' ? socialLinkName : label; + const blockProps = useBlockProps( { className: classes, style: { @@ -125,25 +132,19 @@ const SocialLinkEdit = ( { return ( <> - + - setAttributes( { label: value || undefined } ) + setAttributes( { label: value } ) } + placeholder={ socialLinkName } /> @@ -168,18 +169,18 @@ const SocialLinkEdit = ( { 'screen-reader-text': ! showLabels, } ) } > - { socialLinkLabel } + { socialLinkText } - { isSelected && showURLPopover && ( - - ) } + { isSelected && showURLPopover && ( + + ) } ); diff --git a/packages/block-library/src/social-link/index.php b/packages/block-library/src/social-link/index.php index 69a145c0ff602..5e2bc616d0e5a 100644 --- a/packages/block-library/src/social-link/index.php +++ b/packages/block-library/src/social-link/index.php @@ -19,9 +19,11 @@ function render_block_core_social_link( $attributes, $content, $block ) { $open_in_new_tab = isset( $block->context['openInNewTab'] ) ? $block->context['openInNewTab'] : false; + $text = ! empty( $attributes['label'] ) ? trim( $attributes['label'] ) : ''; + $service = isset( $attributes['service'] ) ? $attributes['service'] : 'Icon'; $url = isset( $attributes['url'] ) ? $attributes['url'] : false; - $label = ! empty( $attributes['label'] ) ? $attributes['label'] : block_core_social_link_get_name( $service ); + $text = $text ? $text : block_core_social_link_get_name( $service ); $rel = isset( $attributes['rel'] ) ? $attributes['rel'] : ''; $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false; @@ -57,7 +59,7 @@ function render_block_core_social_link( $attributes, $content, $block ) { $link = '
  • '; $link .= ''; $link .= $icon; - $link .= '' . esc_html( $label ) . ''; + $link .= '' . esc_html( $text ) . ''; $link .= '
  • '; $processor = new WP_HTML_Tag_Processor( $link ); diff --git a/packages/block-library/src/social-links/block.json b/packages/block-library/src/social-links/block.json index 0c8c7be1eba9a..45dbd9d698953 100644 --- a/packages/block-library/src/social-links/block.json +++ b/packages/block-library/src/social-links/block.json @@ -5,7 +5,7 @@ "title": "Social Icons", "category": "widgets", "allowedBlocks": [ "core/social-link" ], - "description": "Display icons linking to your social media profiles or sites.", + "description": "Display icons linking to your social profiles or sites.", "keywords": [ "links" ], "textdomain": "default", "attributes": { diff --git a/packages/block-library/src/social-links/edit.js b/packages/block-library/src/social-links/edit.js index 38a68e7f2dab2..52d26be50a6c9 100644 --- a/packages/block-library/src/social-links/edit.js +++ b/packages/block-library/src/social-links/edit.js @@ -203,7 +203,7 @@ export function SocialLinksEdit( props ) { /> setAttributes( { showLabels: ! showLabels } )