-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post feature image block: wrap images with hrefs in an A tag #55498
Conversation
Size Change: +297 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is generally working nicely for me, great catch that the default border for a linked image will use the link color!
One thing I noticed in testing is that the placeholder state for the featured image block when rendered within a Query Loop is for it to use a div
and no a
tag. Is it worth adding the a
tag in that case, too (wrapped around the placeholder()
? Here's the relevant code:
gutenberg/packages/block-library/src/post-featured-image/edit.js
Lines 211 to 218 in ba56c3b
<div { ...blockProps }> | |
{ placeholder() } | |
<Overlay | |
attributes={ attributes } | |
setAttributes={ setAttributes } | |
clientId={ clientId } | |
/> | |
</div> |
Without that, there's an inconsistency in the site editor between "real" and placeholder featured image blocks:
Good spotting, thanks! I think it is worth making them consistent. I'll take care of it. |
ba56c3b
to
a2591df
Compare
Did a quick wrap around the placeholder content (the Seems to work okay so far, I'll test more tomorrow. 2023-11-08.17.24.53.mp4Thanks again! |
…d, 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.
…onents CSS, which has an immediate child selector to show the button. With the A tag, the placeholder is no longer the immediate child.
a2591df
to
6c800b2
Compare
// When the Post Featured Image block is linked, | ||
// and wrapped with a disabled <a /> tag | ||
// ensure that the placeholder items are visible when selected. | ||
&.is-selected .components-placeholder.has-illustration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwrites placeholder component CSS
There was a small bug with the post editor placeholder media upload button not showing, but that's fixed now 😅 |
Flaky tests detected in 6c800b2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6807178175
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all testing nicely for me now with the placeholder state working correctly in the post editor, site editor, and within a Query Loop 👍
Looks like there are some intermittent test failures across a few PRs today, I think the most common failure I've seen is to do with waiting for the selector for deactivating test plugins:
That all seems very unrelated to this PR.
This is looking good:
LGTM! ✨
* 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.
Context: #55336 (comment)
Props to @TheRadicalDreamer
What?
From the back catalogue of wrapping A tag hits, comes: "Let's wrap the image element in an A tag (in the editor only)"!
So, in the editor, where
isLink
istrue
let's wrap the featured image in an A tag!Why?
Copy paste quote from #55470:
Also, the CSS change is to force the cursor style to be default since, in the editor, because we don't want to indicate that the image is clickable.
How?
As in #55470, wraps 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.
Testing Instructions
For testing I've used Empty Theme, but any block theme will do.
To ensure we can see the effect, it's important to set different colors for the body background and element links. Here are some test styles to whack into your theme.json.
Some example Query block code
Testing Instructions for Keyboard
Screenshots or screencast
2023-10-20.14.26.53.mp4