From 57211ac3d2d05e67378cb471dd77140cf680b1e0 Mon Sep 17 00:00:00 2001 From: Ramon Date: Fri, 10 Nov 2023 08:36:23 +1100 Subject: [PATCH] Post feature image block: wrap images with hrefs in an A tag (#55498) * Wrap post featured image in an A tag so that it simulates the frontend, and ensures any styles the IMG elements inherits from the A element are also displayed in the editor. The cursor style should be default since, in the editor, we don't want to indicate that the image is clickable. * - also wrap the placeholder in an a tag for consistency * Ensure that the placeholder items are visible by overwriting the components CSS, which has an immediate child selector to show the button. With the A tag, the placeholder is no longer the immediate child. --- .../src/post-featured-image/edit.js | 43 ++++++++++++++++--- .../src/post-featured-image/editor.scss | 19 ++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/post-featured-image/edit.js b/packages/block-library/src/post-featured-image/edit.js index 96295a641a13c..843f1cf66cdfc 100644 --- a/packages/block-library/src/post-featured-image/edit.js +++ b/packages/block-library/src/post-featured-image/edit.js @@ -43,6 +43,11 @@ function getMediaSourceUrlBySizeSlug( media, slug ) { ); } +const disabledClickProps = { + onClick: ( event ) => event.preventDefault(), + 'aria-disabled': true, +}; + export default function PostFeaturedImageEdit( { clientId, attributes, @@ -67,9 +72,10 @@ export default function PostFeaturedImageEdit( { postId ); - const { media, postType } = useSelect( + const { media, postType, postPermalink } = useSelect( ( select ) => { - const { getMedia, getPostType } = select( coreStore ); + const { getMedia, getPostType, getEditedEntityRecord } = + select( coreStore ); return { media: featuredImage && @@ -77,10 +83,16 @@ export default function PostFeaturedImageEdit( { context: 'view', } ), postType: postTypeSlug && getPostType( postTypeSlug ), + postPermalink: getEditedEntityRecord( + 'postType', + postTypeSlug, + postId + )?.link, }; }, - [ featuredImage, postTypeSlug ] + [ featuredImage, postTypeSlug, postId ] ); + const mediaUrl = getMediaSourceUrlBySizeSlug( media, sizeSlug ); const imageSizes = useSelect( @@ -197,7 +209,17 @@ export default function PostFeaturedImageEdit( { <> { controls }
- { placeholder() } + { !! isLink ? ( + + { placeholder() } + + ) : ( + placeholder() + ) } ) }
- { image } + { /* If the featured image is linked, wrap in an tag to trigger any inherited link element styles */ } + { !! isLink ? ( + + { image } + + ) : ( + image + ) } tag. + // Restore cursor style so it doesn't appear 'clickable'. + > a { + cursor: default; + } + + // When the Post Featured Image block is linked, + // and wrapped with a disabled tag + // ensure that the placeholder items are visible when selected. + &.is-selected .components-placeholder.has-illustration { + .components-button, + .components-placeholder__instructions, + .components-placeholder__label { + opacity: 1; + pointer-events: auto; + } + } } div[data-type="core/post-featured-image"] {