Skip to content
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

Add option to use Post Featured Image with consistent height #27545

Closed
wants to merge 2 commits into from

Conversation

ntsekouras
Copy link
Contributor

@ntsekouras ntsekouras commented Dec 7, 2020

Description

This PR adds support for setting consistent height for the Post Featured Image block, using css background-image property. I think this is a very important thing for Post Featured Image to support, so as to enable basic/common designs mostly used through Query block.

I intentionally handled this specifically in this block by providing minimum functionality which provides value ( IMO :) ), as there are discussions for creating a generic background control to handle featured images, along with other options (#24660).

How has this been tested?

Manually

Screenshots

useAsCover

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

min-height: 300px;
background-position: center center;
background-size: cover;
a {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasmussen is there a better way to achieve full height/width link with no content?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make more sense to just wrap the image in an a tag?

@ntsekouras ntsekouras requested a review from mtias December 7, 2020 12:13
@github-actions
Copy link

github-actions bot commented Dec 7, 2020

Size Change: +654 B (0%)

Total Size: 1.19 MB

Filename Size Change
build/block-library/index.js 150 kB +558 B (0%)
build/block-library/style-rtl.css 8.38 kB +48 B (0%)
build/block-library/style.css 8.38 kB +48 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 128 kB 0 B
build/block-editor/style-rtl.css 11.2 kB 0 B
build/block-editor/style.css 11.2 kB 0 B
build/block-library/editor-rtl.css 9.07 kB 0 B
build/block-library/editor.css 9.07 kB 0 B
build/block-library/theme-rtl.css 789 B 0 B
build/block-library/theme.css 790 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 172 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.95 kB 0 B
build/core-data/index.js 15.3 kB 0 B
build/data-controls/index.js 827 B 0 B
build/data/index.js 8.98 kB 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.95 kB 0 B
build/edit-navigation/index.js 11.1 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.49 kB 0 B
build/edit-post/style.css 6.47 kB 0 B
build/edit-site/index.js 24.7 kB 0 B
build/edit-site/style-rtl.css 3.93 kB 0 B
build/edit-site/style.css 3.93 kB 0 B
build/edit-widgets/index.js 26.3 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 43.6 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.84 kB 0 B
build/element/index.js 4.63 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.74 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.27 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.82 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 2.92 kB 0 B
build/rich-text/index.js 13.4 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 2.84 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@aristath
Copy link
Member

aristath commented Dec 7, 2020

I'm a little confused... Is the purpose of this PR to allow consistent height for all featured image blocks when used in a grid?
The wording "cover" here is basically what confused me, I was expecting to be able to add inner blocks - just like in the cover block - which is not the case here (I saw the title of the PR and thought "niiiice!! I'll be able to add the post-title on top of the image")
If the sole purpose is to have all featured images use a consistent height, then perhaps the wording should change to avoid confusion with the cover block?

@ntsekouras
Copy link
Contributor Author

If the sole purpose is to have all featured images use a consistent height, then perhaps the wording should change to avoid confusion with the cover block?

Yes. I had the css background-size:cover in mind :). I'll change the title/description.

@ntsekouras ntsekouras changed the title Add option to use Post Featured Image as cover Add option to use Post Featured Image with consistent height Dec 7, 2020
@jasmussen
Copy link
Contributor

Yes, I'd echo Ari, the use of "Cover" is a little misleading. I understand this to be that you are using the background-size: cover; on a div with a background, instead of inserting an img as it is now.

I do agree, this is a nice feature for the Featured Image block to have. But having just worked on #27331, one thing that became clear to me from that effort was that we have a lot of very very different UI across sidebars, and it's making it very inconcistent and confusing.

So my first question is: how urgent is the need for this feature (perhaps @kjellr who's working on block themes can help answer)? If it's very urgent, we can probably make some small tweaks and land this as a small solution.

If it's not urgent, I think we might want to wait for some of the efforts to address #27331 to land, so we can make a consistent UI for this. Because what it boils down to is two things:

  1. A toggle to choose between outputting an IMG, vs. outputting a div with a background image.
  2. Controls to adjust the properties of the background image.

2 is where it gets really tricky — how deep do we go? Here's a mockup of the controls for the Cover block in the new layout:

Cover Sidebar

  • Do we allow fixed background?
  • Do we allow arbitrary positions or is it always centered?
  • Should you be able to choose between cover/contain? How about repeat/no-repeat?

The thing is, ideally the UI here should be identical between any block that allows background images, give or take controls that get hidden on a per-block basis if they don't make sense. And for every new variation of this UI we create, we have to go back and fix up the old ones once we finally do get to a point. So while I deeply appreciate your work here, the thing is, I can see this UI being used in many places that allow backgrounds, and it might be nice to get this UI super duper right and consistent for the cover block, before we expand it further.

CC: @ItsJonQ @mtias

@kjellr
Copy link
Contributor

kjellr commented Dec 7, 2020

So my first question is: how urgent is the need for this feature (perhaps @kjellr who's working on block themes can help answer)? If it's very urgent, we can probably make some small tweaks and land this as a small solution.

I wouldn't describe it as urgent, though I do think this sort of thing should make its way in eventually.

@jasmussen
Copy link
Contributor

A simpler if perhaps interim alternative is to use object-fit, which the gallery block does at the moment.

https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit

@ntsekouras
Copy link
Contributor Author

A simpler if perhaps interim alternative is to use object-fit, which the gallery block does at the moment.

Yeah, I know. I saw that we already use this in a couple of places in GB, but since it doesn't have full browser support (IE) I didn't go for it.

Anyway, it seems from the discussions that this PR will not go through and we'll wait for the new designs/implementations.

@jasmussen
Copy link
Contributor

While we still support IE11, everything beyond that supports object fit, and I would suggest that given the feature image will still work in IE11, just not cover the area, that it's a decent solution that should be somewhat simpler to implement, with this toggle in the sidebar:

Screenshot 2020-12-08 at 09 09 11

But okay to wait if you prefer the background approach.

@ntsekouras
Copy link
Contributor Author

But okay to wait if you prefer the background approach.

It's not about the specific approach - using object-fit would make things simpler code-wise.. Still this will have to use the same two controls in InspectorControls. I understand that the proposition is to wait for the new components design/implementation.

I'll wait a day or two for any other comments and will close the PR..

@jasmussen jasmussen added the Needs Design Feedback Needs general design feedback. label Dec 8, 2020
@jasmussen
Copy link
Contributor

I've added a label to get some additional thoughts.

@scruffian
Copy link
Contributor

It could be interesting to work on the link aspect of this separately, so that when we are ready for this the link is already in place.

@ntsekouras
Copy link
Contributor Author

It could be interesting to work on the link aspect of this separately, so that when we are ready for this the link is already in place.

You mean making the Post Featured Image a link? Because it's implemented already on master.

@scruffian
Copy link
Contributor

Ah OK, I wasn't aware of that. I guess the part that seemed challenging in the PR was ensuring that the image was wrapped in the a tag, but I don't know how that's working on master...

@ntsekouras ntsekouras closed this Dec 8, 2020
@kjellr
Copy link
Contributor

kjellr commented Dec 9, 2020

I opened an issue here to continue tracking this feature: #27620.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Featured Image Affects the Post Featured Image Block Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants