-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Featured Image Block: Prevent default action on image click to fix linking to post #69716
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
Featured Image Block: Prevent default action on image click to fix linking to post #69716
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
Thanks for the PR! This PR works well for me.
However, note that this PR is a temporary fix for 6.8. I think the fundamental problem is that the a
element includes interactive element (button
) even though it is not permitted by the HTML specification:
<figure class="wp-block-post-featured-image">
<a>
<div class="components-placeholder block-editor-media-placeholder is-large has-illustration">
<div class="components-placeholder__fieldset">
<div class="components-form-file-upload">
<button type="button" class="components-button">Upload</button>
</div>
<button type="button" class="components-button" aria-label="Add a featured image"></button>
</div>
</div>
</a>
</figure>
I believe the following approach is the ideal solution:
- If the block is not in the query context:
- The placeholder has an upload button, so we can't wrap the placeholder with
a
element. - If the featured image is not set, don't show the link-related settings (Lint to Post, Open in new tab, Link Rel)
- When the featured image is reset, initialize/disable all link-related attributes.
- The placeholder has an upload button, so we can't wrap the placeholder with
- If the block is in the query context:
- The placeholder doesn't have an upload button, and the featured image is set depending on the current context.
- Link related settings are always visible. When the block is linked, wrap the placeholder in an
a
element. This is safe because there are no interactive buttons inside the placeholder.
Doing these things in 6.8 may be risky, so it would be a good idea to explore the ideal solution after shipping this PR.
This PR fixes a regression that is new to 6.8, so I think we need to backport this PR. I'd be happy to get additional review/approval as we are in the RC phase. |
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.
Makes sense going with the hotfix for WP 6.8 ✅
I would be happy to work on finding ideal solution in background after hot-fix is merged 🙌🏻 |
@t-hamano, do you mind creating a new issue based on your comment? |
…to post (#69716) Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
I just cherry-picked this PR to the wp/6.8 branch to get it included in the next release: 3e457a2 |
… added checks for link to be shown only if featured image is set.
…ment (#69730) * Feat: removed the code from #69716 and fixed html structure, added checks for link to be shown only if featured image is set. * Fix: Update conditions for displaying link options in Post Featured Image edit panel * Refactor: Add conditional rendering to inspector controls * feat: add templates for single page templates Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * feat: add sizeSlug prop to reset handler --------- Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
…to post (WordPress#69716) Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: shimotmk <shimotomoki@git.wordpress.org>
…ment (WordPress#69730) * Feat: removed the code from WordPress#69716 and fixed html structure, added checks for link to be shown only if featured image is set. * Fix: Update conditions for displaying link options in Post Featured Image edit panel * Refactor: Add conditional rendering to inspector controls * feat: add templates for single page templates Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> * feat: add sizeSlug prop to reset handler --------- Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Fixes #69714
What?
Fixes an issue where the link inside the Featured Image block remains functional even when no image is set.
Why?
Currently, if you click the button from the image placeholder without setting a featured image, the link still works. This is unexpected behavior and may lead to confusion.
A related PR: #68775
How?
PreventDefault
to button from further opening the link inside editor.Testing Instructions
Screencast
Test.FI.mp4