Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Fix product grid blocks markup & design inconsistencies #2428

Merged
merged 12 commits into from Jun 2, 2020

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented May 7, 2020

Part of #1916.
Fixes #2107.
Fixes #2231.
Fixes #2414.

Changes included in this PR:

  • Images in product grid blocks now occupy all the available width.
  • All Products prices have the same style as the 'legacy' product grid blocks.
  • Sale! has been renamed to Sale and now it's a div instead of a span (shouldn't affect layout).
  • There are some other small CSS changes.

Screenshots

Before (Handpicked products on top, All Products below):
imatge

After (Handpicked products on top, All Products below):
imatge

cc @LevinMedia

How to test the changes in this Pull Request:

  1. Create a page with the Handpicked products block and the All Products block.
  2. Both, in the editor and the frontend, verify they look almost the same. There might still be some differences like the Sale badge position, but that can be changed by the user with the inner blocks. Product name colors are different per Product grid blocks and All Products block have different styles for the product name storefront#1366.
  3. Test the CSS snippets in the release notes section below and make sure they undo the changes introduced in this PR.

Release notes

Images in product grid blocks now expand to occupy all the available horizontal space if they are small. You can undo this change with this CSS snippet:

.wc-block-grid__products .wc-block-grid__product-image img {
	width: auto;
}

Prices in the All Products block follow the same layout as the other product grid blocks. You can undo this change with:

.wc-block-grid__product-price .wc-block-grid__product-price__regular {
	font-size: 0.8em;
	line-height: 1;
	color: woocommerce/woocommerce-blocks#555;
	margin-top: -0.25em;
	display: block;
}
.wc-block-grid__product-price .wc-block-grid__product-price__value {
	letter-spacing: -1px;
	font-weight: 600;
	display: block;
	font-size: 1.25em;
	line-height: 1.25;
	color: #000;
	margin-left: 0;
}
.wc-block-grid__product-price .wc-block-grid__product-price__value span {
	white-space: nowrap;
}

Changelog

The All Products block and the other product grid blocks now share more styles and the markup is more similar (see release post or docs to learn how to undo this change).

@Aljullu Aljullu requested a review from a team as a code owner May 7, 2020 11:07
@Aljullu Aljullu self-assigned this May 7, 2020
@Aljullu Aljullu requested review from mikejolley and removed request for a team May 7, 2020 11:07
@github-actions
Copy link
Contributor

github-actions bot commented May 7, 2020

Size Change: -316 B (0%)

Total Size: 1.78 MB

Filename Size Change
build/all-products-frontend.js 71.9 kB +9 B (0%)
build/all-products.js 15.7 kB +11 B (0%)
build/single-product.js 14.2 kB +13 B (0%)
build/style-legacy-rtl.css 5.6 kB -93 B (1%)
build/style-legacy.css 5.61 kB -93 B (1%)
build/style-rtl.css 16.5 kB -82 B (0%)
build/style.css 16.5 kB -81 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 7.26 kB 0 B
build/active-filters.js 7.89 kB 0 B
build/all-reviews-legacy.js 9.19 kB 0 B
build/all-reviews.js 9.46 kB 0 B
build/attribute-filter-frontend.js 16.7 kB 0 B
build/attribute-filter.js 11.5 kB 0 B
build/block-error-boundary-legacy.js 774 B 0 B
build/block-error-boundary.js 775 B 0 B
build/blocks-legacy.js 2.92 kB 0 B
build/blocks.js 2.92 kB 0 B
build/cart-frontend.js 113 kB 0 B
build/cart.js 32.3 kB 0 B
build/checkout-frontend.js 129 kB 0 B
build/checkout.js 37.9 kB 0 B
build/custom-select-control-style-legacy.js 782 B 0 B
build/custom-select-control-style.js 782 B 0 B
build/editor-legacy-rtl.css 12.5 kB 0 B
build/editor-legacy.css 12.5 kB 0 B
build/editor-rtl.css 13.5 kB 0 B
build/editor.css 13.5 kB 0 B
build/featured-category-legacy.js 7.26 kB 0 B
build/featured-category.js 7.53 kB 0 B
build/featured-product-legacy.js 9.5 kB 0 B
build/featured-product.js 9.79 kB 0 B
build/handpicked-products-legacy.js 6.9 kB 0 B
build/handpicked-products.js 7.18 kB 0 B
build/panel-style-legacy.js 773 B 0 B
build/panel-style.js 773 B 0 B
build/price-filter-frontend.js 14.1 kB 0 B
build/price-filter.js 9.98 kB 0 B
build/product-best-sellers-legacy.js 6.98 kB 0 B
build/product-best-sellers.js 7.24 kB 0 B
build/product-categories-legacy.js 3.22 kB 0 B
build/product-categories.js 3.21 kB 0 B
build/product-category-legacy.js 7.89 kB 0 B
build/product-category.js 8.15 kB 0 B
build/product-list-style-legacy.js 775 B 0 B
build/product-new-legacy.js 7.13 kB 0 B
build/product-new.js 7.41 kB 0 B
build/product-on-sale-legacy.js 7.5 kB 0 B
build/product-on-sale.js 7.8 kB 0 B
build/product-search-legacy.js 3.12 kB 0 B
build/product-search.js 3.36 kB 0 B
build/product-tag-legacy.js 6.07 kB 0 B
build/product-tag.js 6.33 kB 0 B
build/product-top-rated-legacy.js 7.11 kB 0 B
build/product-top-rated.js 7.38 kB 0 B
build/products-by-attribute-legacy.js 7.87 kB 0 B
build/products-by-attribute.js 8.13 kB 0 B
build/reviews-by-category-legacy.js 11.2 kB 0 B
build/reviews-by-category.js 11.5 kB 0 B
build/reviews-by-product-legacy.js 12.7 kB 0 B
build/reviews-by-product.js 13 kB 0 B
build/reviews-frontend-legacy.js 8.03 kB 0 B
build/reviews-frontend.js 8.95 kB 0 B
build/single-product-frontend.js 58.9 kB 0 B
build/snackbar-notice-style-legacy.js 778 B 0 B
build/snackbar-notice-style.js 778 B 0 B
build/spinner-style-legacy.js 775 B 0 B
build/spinner-style.js 772 B 0 B
build/vendors-legacy.js 376 kB 0 B
build/vendors-style-legacy-rtl.css 1.65 kB 0 B
build/vendors-style-legacy.css 1.65 kB 0 B
build/vendors-style-legacy.js 105 B 0 B
build/vendors-style-rtl.css 1.65 kB 0 B
build/vendors-style.css 1.65 kB 0 B
build/vendors-style.js 105 B 0 B
build/vendors.js 473 kB 0 B
build/wc-blocks-data.js 7.08 kB 0 B
build/wc-blocks-middleware.js 932 B 0 B
build/wc-blocks-registry.js 1.78 kB 0 B
build/wc-payment-method-cheque.js 794 B 0 B
build/wc-payment-method-paypal.js 830 B 0 B
build/wc-payment-method-stripe.js 11.9 kB 0 B
build/wc-settings.js 2.14 kB 0 B
build/wc-shared-context.js 1.17 kB 0 B

compressed-size-action

@mikejolley
Copy link
Member

@Aljullu before I review this I just want to check something.

Note the weight and size of the price on the current All Products block. These were design tweaks made intentionally - shouldn't we be updating the old grid blocks to match the new styles, rather than reverting all products block styles?

@Aljullu
Copy link
Contributor Author

Aljullu commented May 7, 2020

Note the weight and size of the price on the current All Products block. These were design tweaks made intentionally - shouldn't we be updating the old grid blocks to match the new styles, rather than reverting all products block styles?

Yeah, good point, I should have specified that. I spoke about that with @LevinMedia in Slack. It was decided that:

  • The prices will be displayed in one line, as they are in the 'legacy' product grid blocks.
  • Smaller images must fill the available space, as they do in the All Products block.

@LevinMedia
Copy link
Contributor

LevinMedia commented May 8, 2020

Note the weight and size of the price on the current All Products block. These were design tweaks made intentionally - shouldn't we be updating the old grid blocks to match the new styles, rather than reverting all products block styles?

@mikejolley can you point me to where that decision was made? I don't want to steam roll something if I shouldn't.

My logic in reverting: I figured it was better to roll it back to be consistent with the legacy product blocks, since changing those to look like the all products block would impact significantly more stores vs doing it the other way around.

@mikejolley
Copy link
Member

mikejolley commented May 11, 2020

@mikejolley can you point me to where that decision was made?

I cannot sorry, but remember the designs for the All Products Block (and layouts) all came from design team and Josh. Maybe in figma somewhere, or a research post? I'm not sure where to look.

I remember specifically a figma file with explorations into price range appearance and this was the chosen option.

Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

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

Aside from the breaking change, this looks fine code-wise.

Just would like clarification from design because IMO this is the wrong direction to take—aside from the earlier comments on the evolution of the design, this ties us back to legacy class names (star-rating, price, etc) which conflict much more easily in the wild due to no prefixes.

Blocks is an opportunity to change markup, classnames, styles, without worrying too much about the legacy markup found in woo core. In my mind, blocks is supposed to supersede and replace shortcodes, so I'm confused why we need to match them stylewise.

We might just be kicking the can down the road. cc @nerrad

@@ -357,7 +355,7 @@ public function render_product( $id ) {
* @return string
*/
protected function get_image_html( $product ) {
return '<div class="wc-block-grid__product-image">' . $product->get_image( 'woocommerce_thumbnail' ) . '</div>';
return '<div class="wc-block-grid__product-image"><a href="' . esc_url( $product->get_permalink() ) . '">' . $product->get_image( 'woocommerce_thumbnail' ) . '</a></div>';
Copy link
Member

Choose a reason for hiding this comment

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

This would be a breaking change on the woocommerce_blocks_product_grid_item_html filter. The link was previously filterable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch! I will work on a solution if the discussion below is addressed.

@nerrad
Copy link
Contributor

nerrad commented May 12, 2020

Blocks is an opportunity to change markup, classnames, styles, without worrying too much about the legacy markup found in woo core. In my mind, blocks is supposed to supersede and replace shortcodes, so I'm confused why we need to match them stylewise.

For what it's worth, I strongly agree with Mike here. If I understand correctly, there's competing approaches outlined in this pull:

Approach One: Preserve styling history between Woo core and Blocks

As far as I can tell, the primary impetus for this approach is the goal of having fairly indistinguishable style between similar views in core and the blocks (i.e. all product grids look "the same" and inherit the same things from themes etc.).

Pros

Assuming this is pulled off without as planned...

  • merchants that have had their stores customized should have the blocks just fit right in.
  • themes that have customized layouts etc should just have the blocks fit in.
  • functionally there is no difference between how something like the block product grid looks on a site and the "legacy" product grids look on the site.

Cons

  • There's not much incentive for merchants to switch to the new blocks beyond potential additional functionality they have as from an appearance point of view they are just the same output.
  • Maintaining this consistency is not easy because block skeleton's are different than "legacy" skeletons. So I think we'll likely have a uphill battle trying to preserve this consistency long term.
  • Custom JS scripts that sites may have customized to hook in on existing css selectors on legacy views will also potentially hook in on the blocks which could have downsides when the skeleton isn't an exact match.
  • We effectively make the base design of all blocks the same as what has been in woo for a number of years unless we decide to update those style values - which means we also potentially update all sites.

Approach 2: Blocks have their own selectors and implement new base style and design patterns.

Pros

  • We have the opportunity to implement a fresh default for the base design of various things.
  • We can spot places to improve the selector usage and standardize around a convention to take us into the future.
  • Less risk of conflict with existing themes and customizations out there which might not work well with the block skeleton.
  • Less risk of custom JS scripts hooking in and having unexpected behaviour.
  • There's a clear demarcation between the fresh new designs and behaviour introduced by blocks vs legacy views. This potentially introduces additional incentive to use the new blocks over legacy views.

Cons

  • We don't have blocks covering or replacing all views yet. This means that there is increased potential for inconsistent views on a site implementing both blocks and legacy views.
  • There will be merchants, builders, or developers who want to keep everything consistent in design across blocks and legacy views and this will require customizing the styles for the blocks along with their other site customizations.

Wrap up

Out of the two approaches, I'm definitely leaning more to Approach 2, primarily because I think it's going to be harder to maintain consistency between shortcode or legacy content and block content going forward into the future of WordPress theming and implementation of block content. I'm concerned that there will be a continual selector battle between default theme/shortcode styling and more up-to-date design and styling defaults we have with blocks.

With a broader view, I also think of the upcoming new blocks we introduce (such as Cart & Checkout) which intentionally diverge from the "legacy" implementations. What kind of potential clash will exist between the blocks we've styled to match existing legacy views and blocks we've intentionally styled to be different from existing legacy views? I think the better approach is to decide on the default design language we want to use across all woo blocks consistently so there's no confusion why some blocks look shortcode output, but others have a more fresher look.

From the standpoint of themers and those developing for sites, it also creates the potential for one day getting rid of old styles from the site and just keeping those specific to the blocks (so a gradual deprecation over time).

@Aljullu
Copy link
Contributor Author

Aljullu commented May 12, 2020

Thanks for the feedback @nerrad and @mikejolley. I might not have been clear enough because I think there has been some misunderstanding here. This PR has no relation at all neither with shortcodes neither with the Shop page template. Instead, it tries to resolve some markup differences between PHP product grid blocks (like Hand-picked Products block, Top Rated Products block, etc.) and the All Products block.

So I completely agree with your concerns and with approach 2 presented by @nerrad.

But we have received some feedback (see #1916 and #2107, for example), about our blocks using different markup and class names whether they were PHP-based or JS-based. This PR was trying to solve that.

Just would like clarification from design because IMO this is the wrong direction to take—aside from the earlier comments on the evolution of the design, this ties us back to legacy class names (star-rating, price, etc) which conflict much more easily in the wild due to no prefixes.

If the issue is that I added the star-rating and price classes to the All Products block, I'm happy to remove them. Indeed, I wasn't 100% sure about adding them in the first place, but given that we will not be able to remove them from PHP-based blocks in the short term, it made sense to me to keep consistency with the All Products block. But I don't have a strong opinion on this, I see benefits from both approaches, so I'm fine removing them if there is an agreement. 👍

I remember specifically a figma file with explorations into price range appearance and this was the chosen option.

Whether we should make the price style consistent between PHP and JS-based blocks and which one it should be, is something that I don't have a strong opinion either and I think it's a design decision more than a technical one. I think it all depends on whether we want blocks to be consistent or we consider them to serve different use-cases so it's fine to have different styles.

@Aljullu Aljullu added the skip-changelog PRs that you don't want to appear in the changelog. label May 15, 2020
@nerrad
Copy link
Contributor

nerrad commented May 15, 2020

Whether we should make the price style consistent between PHP and JS-based blocks and which one it should be, is something that I don't have a strong opinion either and I think it's a design decision more than a technical one. I think it all depends on whether we want blocks to be consistent or we consider them to serve different use-cases so it's fine to have different styles.

So it sounds to me that what we all are in agreement on is having consistent styles among our blocks and less concerned with preserving consistency the old shortcode/template views andthe blocks.

We have a tricky situation here where folks may have already styled the php based blocks (because they've been out longer) and that means we have to be careful about what we remove or add to those blocks because of how it may affect styling.

So here's a suggested proposal:

  • we consider our base for consistency the new blocks. So whatever standard/convention we are using for classnames and/or styling, we use that.
  • This means we align the old blocks with new classes and try to keep html structure the same too where possible.
  • We announce these changes accompanying a release, why we made them, and how folks can customize/fix their designs if they are affected.
  • We make sure Storefront (and child themes) account for the changes.

While I know the main intention behind this pull is aligning the inconsistency between blocks, it does seem that at least in part, the older blocks were styled to be more consistent with existing shortcode/template output. So I do think we need to make sure the communication piece when this is released is taken care of (particularly the "Why").

Thoughts? (cc @LevinMedia as well).

@garymurray
Copy link

Regarding the style changes proposed in this PR to the weight and size of the discounted price - I spent some time trying to find where this change was made/proposed by going through Figma/P2/Github/meetings and I cannot locate it.

In the absence of knowing why the change was made - i.e. if there was research to show it was better - I do feel we should change this back to the style proposed in the PR - not because it aligns with the existing shortcodes - but more so that it appears to be more consistent with the style used by online retailers.

Currently the All Products block is also used by less stores than the others blocks - so changing it back would have far less of an impact than changing all the other blocks to align to the style as is in the current All Products block.

@Aljullu
Copy link
Contributor Author

Aljullu commented May 19, 2020

  • we consider our base for consistency the new blocks. So whatever standard/convention we are using for classnames and/or styling, we use that.
  • This means we align the old blocks with new classes and try to keep html structure the same too where possible.

That's a tricky one because we don't have a direct control of the entire markup of PHP-based blocks, instead we render the templates returned by WC Core functions. For example, see https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/master/src/BlockTypes/AbstractProductGrid.php#L393.

If we want to customize the class names, we would need to update those functions in Core so they dynamically accept a custom class name. Considering we can achieve the same result via CSS selectors on our end, I'm not sure it makes sense updating several core functions just for that. Thoughts?

We announce these changes accompanying a release, why we made them, and how folks can customize/fix their designs if they are affected.

That's a good point, sounds good to me. The changes this PR adds to PHP product grid blocks are:

  1. Small images are now expanded to cover the entire width.
  2. Product names are displayed as links instead of titles.

It shouldn't be difficult to add a CSS snippet to revert those changes. Should we add it to the readme.txt or leave it for the release post?

We can also document the changes to the All Products block and offer CSS snippets to undo them.

We make sure Storefront (and child themes) account for the changes.

For Storefront, this PR was already merged woocommerce/storefront#1344 which fixes an issue with the All Products block and incidentally it will make styles work if this PR is merged.

For child themes I took a quick look at some of them and couldn't find any adding specific styles to product grid blocks. Do you know if there is an easy way to search the code of all of them at once? Otherwise, would the release notes be enough?

@Aljullu Aljullu force-pushed the fix/2414-product-grid-inconsistencies branch from d20a819 to cad1668 Compare May 19, 2020 10:40
@Aljullu
Copy link
Contributor Author

Aljullu commented May 19, 2020

I rebased this PR so:

This way this PR is smaller and completely focused towards the block inconsistencies.

@Aljullu Aljullu force-pushed the fix/2414-product-grid-inconsistencies branch from cad1668 to ba70cb6 Compare May 19, 2020 15:25
@nerrad
Copy link
Contributor

nerrad commented May 21, 2020

Should we add it to the readme.txt or leave it for the release post?

Both?

For child themes I took a quick look at some of them and couldn't find any adding specific styles to product grid blocks. Do you know if there is an easy way to search the code of all of them at once? Otherwise, would the release notes be enough?

Honestly, I don't know 😄! I'm less concerned about what our themes do out of the box and what custom changes folks might have made for their site. What's the risk of breakage there? I'm assuming in those cases any custom css on other's sites should still apply? Regardless, yes having something in release notes would be good.

@mikejolley can you give a final review/test of this so we can get merged?

@nerrad nerrad requested a review from mikejolley May 21, 2020 13:10
@Aljullu Aljullu removed the skip-changelog PRs that you don't want to appear in the changelog. label May 22, 2020
@Aljullu
Copy link
Contributor Author

Aljullu commented May 22, 2020

What's the risk of breakage there? I'm assuming in those cases any custom css on other's sites should still apply?

Yeah, we aren't removing any class name, instead adding some new ones, so I think breakage with themes should be minimal.

However, after thinking about it, I'm a bit concerned about scaling up images and would like your thoughts on that. If a store has very narrow images, the layout might break:

master:
imatge

This branch:
imatge

Notice we already have this issue in All Products in master. But with this branch we would introduce it to the 'legacy' product grid blocks. Should we instead unify the designs so small images are not scaled-up? cc @LevinMedia

@mikejolley can you give a final review/test of this so we can get merged?

I still need to take a look at this: #2428 (comment), and would like to write the CSS snippets & release texts as part of this PR, so moving this PR back to In progress for now.

@LevinMedia
Copy link
Contributor

@Aljullu I feel like the vast majority of product images are going to be square or rectangular in aspect ratio, and that doing it the way you've got it in the PR is going work best. 👍

@Aljullu Aljullu force-pushed the fix/2414-product-grid-inconsistencies branch from a19ab97 to d24df30 Compare May 28, 2020 16:14
@Aljullu Aljullu added this to the 2.7.0 milestone May 28, 2020
@Aljullu Aljullu force-pushed the fix/2414-product-grid-inconsistencies branch from fb15265 to 68ff0c8 Compare May 28, 2020 16:31
@Aljullu
Copy link
Contributor Author

Aljullu commented May 28, 2020

@mikejolley this is ready for another look. Some comments:

  • I updated the PR description with new testing steps and new screenshots.
  • I added a release notes section with a proposed text that could go in the release post. Wondering if we should create a GitHub label to track PRs that have this kind of notes? cc @nerrad
  • @mikejolley I kept the price and star-rating classes, this way theme styles are inherited. The reason for this is that I don't think we can rely on themes switching to the new class names until Merge the markup from atomic/blocks/product-elements/ with base/components/cart-checkout/ woocommerce#42680 is fixed.
  • Instead of adding a note in readme.txt, I added it in the docs folder (you can read them here).

@Aljullu Aljullu force-pushed the fix/2414-product-grid-inconsistencies branch from 68ff0c8 to 297fe0c Compare May 29, 2020 13:29
@nerrad
Copy link
Contributor

nerrad commented Jun 1, 2020

I added a release notes section with a proposed text that could go in the release post. Wondering if we should create a GitHub label to track PRs that have this kind of notes? cc @nerrad

Maybe a status:needs-dev-note label? Then as a part of the release pull request any issues/pulls having that status indicates needing surfaced explicitly in release notes (as opposed to just a bullet item in the changelog).

If you add this label, will you also document that the label was added in our async meeting notes? That way it'll be something surfaced as a decision there.

Copy link
Member

@mikejolley mikejolley left a comment

Choose a reason for hiding this comment

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

This seems ok now, thanks for adding docs and reducing scope.

There are some merge conflicts to resolve.

We should talk sometime about classnames in layouts (grid- etc) due to the work in bringing more layout options.

@@ -20,7 +20,7 @@ const ProductPrice = ( { className, product } ) => {
<div
className={ classnames(
className,
`${ layoutStyleClassPrefix }__product-price`
`${ layoutStyleClassPrefix }__product-price price`
Copy link
Member

Choose a reason for hiding this comment

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

Just curious why price isn't it's own separate entry in classnames.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know! 😄 Should be fixed in the merge commit.

@Aljullu Aljullu added the needs: dev note PR that has some text that needs to be included in the release notes. label Jun 2, 2020
@Aljullu Aljullu merged commit 84f4940 into master Jun 2, 2020
@Aljullu Aljullu deleted the fix/2414-product-grid-inconsistencies branch June 2, 2020 15:06
@Aljullu Aljullu added the type: enhancement The issue is a request for an enhancement. label Jun 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: dev note PR that has some text that needs to be included in the release notes. type: enhancement The issue is a request for an enhancement.
Projects
None yet
6 participants