diff --git a/packages/block-library/src/social-link/edit.js b/packages/block-library/src/social-link/edit.js index 47af181bfe17e..14b0f11334a09 100644 --- a/packages/block-library/src/social-link/edit.js +++ b/packages/block-library/src/social-link/edit.js @@ -6,7 +6,7 @@ import clsx from 'clsx'; /** * WordPress dependencies */ -import { DELETE, BACKSPACE } from '@wordpress/keycodes'; +import { DELETE, BACKSPACE, ENTER } from '@wordpress/keycodes'; import { useDispatch } from '@wordpress/data'; import { @@ -16,7 +16,7 @@ import { useBlockProps, store as blockEditorStore, } from '@wordpress/block-editor'; -import { useState } from '@wordpress/element'; +import { useState, useRef } from '@wordpress/element'; import { Button, PanelBody, @@ -24,6 +24,7 @@ import { TextControl, __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, } from '@wordpress/components'; +import { useMergeRefs } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; import { keyboardReturn } from '@wordpress/icons'; @@ -112,12 +113,19 @@ const SocialLinkEdit = ( { iconBackgroundColorValue, } = context; const [ showURLPopover, setPopover ] = useState( false ); - const classes = clsx( 'wp-social-link', 'wp-social-link-' + service, { - 'wp-social-link__is-incomplete': ! url, - [ `has-${ iconColor }-color` ]: iconColor, - [ `has-${ iconBackgroundColor }-background-color` ]: - iconBackgroundColor, - } ); + const wrapperClasses = clsx( + 'wp-social-link', + // Manually adding this class for backwards compatibility of CSS when moving the + // blockProps from the li to the button: https://github.com/WordPress/gutenberg/pull/64883 + 'wp-block-social-link', + 'wp-social-link-' + service, + { + 'wp-social-link__is-incomplete': ! url, + [ `has-${ iconColor }-color` ]: iconColor, + [ `has-${ iconBackgroundColor }-background-color` ]: + iconBackgroundColor, + } + ); // Use internal state instead of a ref to make sure that the component // re-renders when the popover's anchor updates. @@ -131,11 +139,16 @@ const SocialLinkEdit = ( { // spaces. The PHP render callback fallbacks to the social name as well. const socialLinkText = label.trim() === '' ? socialLinkName : label; + const ref = useRef(); const blockProps = useBlockProps( { - className: classes, - style: { - color: iconColorValue, - backgroundColor: iconBackgroundColorValue, + className: 'wp-block-social-link-anchor', + ref: useMergeRefs( [ setPopoverAnchor, ref ] ), + onClick: () => setPopover( true ), + onKeyDown: ( event ) => { + if ( event.keyCode === ENTER ) { + event.preventDefault(); + setPopover( true ); + } }, } ); @@ -169,13 +182,27 @@ const SocialLinkEdit = ( { onChange={ ( value ) => setAttributes( { rel: value } ) } /> -
  • - + { /* eslint-enable jsx-a11y/no-redundant-roles */ } { isSelected && showURLPopover && (