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

Unify Chip styles #2765

Merged
merged 22 commits into from Jul 10, 2020
Merged

Unify Chip styles #2765

merged 22 commits into from Jul 10, 2020

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Jun 23, 2020

Fixes #1786.

This PR updates the Filter Products by Attribute and Active Filters blocks so they use the Chip component introduced in the Cart & Checkout blocks. Chip needed some changes so it could be used in those scenarios.

I also took the chance to fix some theme compatibility issues in those blocks (input backgrounds & Clear All color).

We are making some style changes and switching some components, so there is the possibility of themes breakage but I think it's quite small. IMO there is no need for a dev note. Thoughts?

Accessibility

  • I've tested using only a keyboard (no mouse)
  • I've tested using a screen reader

Screenshots

Screenshots with Bistro theme:

Before:
imatge

After:
imatge

How to test the changes in this Pull Request:

  1. Ideally, set your theme background to something different from white so you can verify inputs are still legible.
  2. Create a page with the All Products block and the Filter Products by Attribute (set the attributes to Query Type: OR, Display Style: Dropdown) and Active Filters (Display Style: Chips).
  3. Filter Products by Attribute:
    2.1. Try adding new filters.
    2.2. Verify chips have the correct styles.
    2.3. Try removing them with the keyboard (backspace or Del).
    2.4. Try removing them clicking on the chip name.
  4. Active Filters:
    3.1 Verify chips have the correct styles.
  5. Catching regressions:
    4.1. Verify there are no regression in the Filter Products by Attribute and the Active Filters blocks with other attribute combinations: verify everything is still working and there are no visual bugs.
    4.2. Verify there are no regressions with the Chips in the Cart: try adding a coupon in the Cart or Checkout blocks and verify it still looks correct.

Changelog

Chip styles of the Filter Products by Attribute and Active Filters have been updated to give a more consistent experience.

@Aljullu Aljullu added type: enhancement The issue is a request for an enhancement. focus: components Work that introduces new or updates existing components. block: filter by attribute Issues related to the Filter by Attribute block. block: active filters Issues related to the Active Filters block. labels Jun 23, 2020
@Aljullu Aljullu requested a review from a team as a code owner June 23, 2020 10:48
@Aljullu Aljullu self-assigned this Jun 23, 2020
@Aljullu Aljullu requested review from nerrad and removed request for a team June 23, 2020 10:48
@Aljullu Aljullu force-pushed the fix/1786-unify-chip-styles branch from 0377ec9 to ce181b6 Compare June 23, 2020 10:52
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2020

Size Change: +5.85 kB (0%)

Total Size: 1.59 MB

Filename Size Change
build/active-filters-frontend.js 8.47 kB +1.24 kB (14%) ⚠️
build/active-filters.js 8.75 kB +796 B (9%) 🔍
build/all-products-frontend.js 41.3 kB -30 B (0%)
build/all-products.js 24.9 kB +14 B (0%)
build/all-reviews.js 9.6 kB -1 B
build/attribute-filter-frontend.js 17.8 kB +1.01 kB (5%) 🔍
build/attribute-filter.js 12.3 kB +684 B (5%) 🔍
build/block-error-boundary.js 774 B -1 B
build/blocks.js 3.22 kB +2 B (0%)
build/cart-frontend.js 64.2 kB +349 B (0%)
build/cart.js 33.4 kB +303 B (0%)
build/checkout-frontend.js 80.8 kB +365 B (0%)
build/checkout.js 38.9 kB +329 B (0%)
build/featured-category.js 7.59 kB -4 B (0%)
build/featured-product.js 9.85 kB -2 B (0%)
build/handpicked-products.js 7.24 kB -1 B
build/price-filter-frontend.js 14.1 kB -7 B (0%)
build/price-filter.js 10.1 kB +3 B (0%)
build/product-best-sellers.js 7.3 kB +1 B
build/product-categories.js 3.22 kB +1 B
build/product-category.js 8.25 kB +3 B (0%)
build/product-on-sale.js 7.87 kB +1 B
build/product-search.js 3.43 kB -1 B
build/product-tag.js 6.39 kB +1 B
build/products-by-attribute.js 8.2 kB +2 B (0%)
build/reviews-by-category.js 11.6 kB -2 B (0%)
build/reviews-frontend.js 9 kB -9 B (0%)
build/single-product-frontend.js 44.1 kB -48 B (0%)
build/single-product.js 18.3 kB +9 B (0%)
build/style-rtl.css 18.1 kB +13 B (0%)
build/style.css 18.1 kB +14 B (0%)
build/vendors.js 415 kB +30 B (0%)
build/wc-payment-method-bacs.js 791 B +791 B (100%) 🆘
ℹ️ View Unchanged
Filename Size Change
build/all-reviews-legacy.js 9.29 kB 0 B
build/block-error-boundary-legacy.js 775 B 0 B
build/blocks-legacy.js 3.21 kB 0 B
build/custom-select-control-style-legacy.js 782 B 0 B
build/custom-select-control-style.js 783 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.25 kB 0 B
build/featured-product-legacy.js 9.51 kB 0 B
build/handpicked-products-legacy.js 6.91 kB 0 B
build/product-best-sellers-legacy.js 6.99 kB 0 B
build/product-categories-legacy.js 3.22 kB 0 B
build/product-category-legacy.js 7.91 kB 0 B
build/product-list-style-legacy.js 775 B 0 B
build/product-new-legacy.js 7.14 kB 0 B
build/product-new.js 7.47 kB 0 B
build/product-on-sale-legacy.js 7.52 kB 0 B
build/product-search-legacy.js 3.13 kB 0 B
build/product-tag-legacy.js 6.08 kB 0 B
build/product-top-rated-legacy.js 7.11 kB 0 B
build/product-top-rated.js 7.44 kB 0 B
build/products-by-attribute-legacy.js 7.88 kB 0 B
build/reviews-by-category-legacy.js 11.3 kB 0 B
build/reviews-by-product-legacy.js 12.8 kB 0 B
build/reviews-by-product.js 13.1 kB 0 B
build/reviews-frontend-legacy.js 8.16 kB 0 B
build/snackbar-notice-style-legacy.js 778 B 0 B
build/snackbar-notice-style.js 779 B 0 B
build/spinner-style-legacy.js 771 B 0 B
build/spinner-style.js 772 B 0 B
build/style-legacy-rtl.css 5.56 kB 0 B
build/style-legacy.css 5.57 kB 0 B
build/vendors-legacy.js 367 kB 0 B
build/vendors-style-legacy-rtl.css 1.03 kB 0 B
build/vendors-style-legacy.css 1.03 kB 0 B
build/vendors-style-legacy.js 102 B 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors-style.js 102 B 0 B
build/wc-blocks-data.js 7.09 kB 0 B
build/wc-blocks-middleware.js 932 B 0 B
build/wc-blocks-registry.js 2.19 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.51 kB 0 B

compressed-size-action

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Looking much better Albert! I've left some comments inline. Also, while testing, I noticed some slight padding/margin spacing issues (my testing was against Storefront 2.5.8.rc.1):

First, the dismiss "x" for the coupon chips seems to be a bit off center vertically.
Image 2020-06-24 at 1 19 21 PM

Next, the space between the chip and the bottom of the input field (with the filter block) is more than the margin at the top (and the chip doesn't look centered in it's container):

Image 2020-06-24 at 1 20 29 PM

assets/js/base/components/chip/index.js Outdated Show resolved Hide resolved
@@ -25,46 +25,79 @@ const Chip = ( {
onRemove = () => {},
disabled = false,
radius = 'small',
removeOnClick = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me a few secs to understand the purpose of this prop. At first I thought it was used to single out whether the chip is removable or not, but then I discovered that it's used simply to indicate whether the remove action is attached to the entire chip, or just the "x" element.

So with that in mind, the prop name seems like it could use some "tightening up" so it's purpose is a bit more intuitive. Maybe something like removeOnAnyClick?

Also, I wonder, will there ever be any use-case for using this same Chip Pattern for something that is not removable (meaning the chip is persistently displayed)? Should we differentiate the name of this particular component so it's clear it's always removable (i.e. RemovableChip or DismissableChip)? Eventually the ui/ux could be moved into <Chip> and this component () would wrap around the former enhancing it with the removal actions/labels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So with that in mind, the prop name seems like it could use some "tightening up" so it's purpose is a bit more intuitive. Maybe something like removeOnAnyClick?

👍 Done in ce51de2.

Also, I wonder, will there ever be any use-case for using this same Chip Pattern for something that is not removable (meaning the chip is persistently displayed)? Should we differentiate the name of this particular component so it's clear it's always removable (i.e. RemovableChip or DismissableChip)? Eventually the ui/ux could be moved into <Chip> and this component () would wrap around the former enhancing it with the removal actions/labels.

Yes, that sounds good to me. Just thinking we should wait until we see the real need to have an un-removable chip before differentiating between two kinds of chips?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking we should wait until we see the real need to have an un-removable chip before differentiating between two kinds of chips?

I'd be okay with that, but I just wonder if it would be better to be more explicit now with the name of the component and call it RemovableChip or DismissibleChip which leaves room for having just Chip down the road. It makes it a bit clearer that this is a component with dismissing behaviour?

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 ended up splitting the component in two (Chip and RemovableChip) as you suggested in the first place. This way both components can share the same CSS classes so it's not a breaking change: d0eeb26.

Comment on lines 44 to 48
: sprintf(
/* translators: %s text of the chip to remove. */
__( 'Remove "%s"', 'woo-gutenberg-products-block' ),
text
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be moved as the default for the ariaLabel for incoming props? Then you just have to check if ariaLabel is a string and if not set it to undefined ? Currently the only time __( 'Remove "%s"') will be used is if ariaLabel is set and it isn't of a type string. Plus the value here is different than the default for the prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure to understand you here. There are three posibilities:

  • arilaLabel prop is set: in that case, we use ariaLabel.
  • ariaLabel is not set:
    • If text is a string, it uses Remove "%s".
    • If text is not a string, it uses Remove.

That's because text accepts any node, so it could be a string but also an element.

Copy link
Contributor

Choose a reason for hiding this comment

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

arilaLabel prop is set: in that case, we use ariaLabel.

In the code it's always going to be set because the destructured prop value has a default:

ariaLabel = __( 'Remove', 'woo-gutenberg-products-block' ),

So the expression ariaLabel || typeof text !== 'string' will never evaluate the second condition unless ariaLabel is explicitly set to something a non-truthy value and not undefined or not set.

The problem I'm seeing might be more clear if you add some tests covering the conditions this expression uses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aaaah, of course! 🤦 I updated the logic in 273fde8. I also made it so it honors the screen reader text. I think it makes more sense to use that one than the default text.

The problem I'm seeing might be more clear if you add some tests covering the conditions this expression uses.

I think it's now covered with the tests added in d0eeb26.

assets/js/base/components/chip/index.js Outdated Show resolved Hide resolved
assets/js/base/components/chip/index.js Outdated Show resolved Hide resolved
assets/js/base/components/chip/index.js Outdated Show resolved Hide resolved
Comment on lines 19 to 25
test( 'should render nodes as the text', () => {
const component = TestRenderer.create(
<Chip text={ <h1>Test</h1> } />
);

expect( component.toJSON() ).toMatchSnapshot();
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

We should switch to use React Testing Library here. I understand though if you want to leave this for now and revisit in a potential follow-up.

@Aljullu
Copy link
Contributor Author

Aljullu commented Jun 25, 2020

Thanks for the review @nerrad!

First, the dismiss "x" for the coupon chips seems to be a bit off center vertically.

Good catch! I was struggling to get it correctly aligned. Turns out we were using the multiplication X character, which seems to be a bit misaligned to the top. I replaced it with the cancellation X character in 8edd9df:

Before After
imatge imatge

At some point we could replace it with an SVG icon, but I think the character looks good enough.

Next, the space between the chip and the bottom of the input field (with the filter block) is more than the margin at the top (and the chip doesn't look centered in it's container):

Ah, a specificity issue. 🙂 Fixed in: 392e2b1.

@Aljullu Aljullu requested a review from nerrad June 25, 2020 14:55
@Aljullu Aljullu added this to the 2.9.0 milestone Jun 25, 2020
@nerrad
Copy link
Contributor

nerrad commented Jul 2, 2020

At some point we could replace it with an SVG icon, but I think the character looks good enough.

Ya cancellation character definitely looks better 👍

@haszari haszari modified the milestones: 2.9.0, 3.0.0 Jul 5, 2020
@nerrad
Copy link
Contributor

nerrad commented Jul 6, 2020

I haven't reviewed the code yet, but did some testing. With npm run build I got this:

Chrome:
Image 2020-07-06 at 1 56 05 PM

Safari:
Image 2020-07-06 at 1 55 54 PM

I wiped node_modules and did a rebuild and got the same thing. I'm guessing this might be a styles loading issue?

@Aljullu Aljullu force-pushed the fix/1786-unify-chip-styles branch from d0eeb26 to 2ded0b8 Compare July 7, 2020 10:51
@Aljullu
Copy link
Contributor Author

Aljullu commented Jul 7, 2020

I haven't reviewed the code yet, but did some testing. With npm run build I got this:

That's weird, it's working fine for me. To me, it looks like an issue with the font?

In 52ca69a I replaced the character with an Icon, I guess that should fix it. Can you try?

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Tests well Albert and reviews good, I just have a single suggestion for a comment block so pre-approving.

Sorry for the delay in getting to the final review and thanks for handling all the feedback!

>
🗙
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting (just noting) it looks like the previous snapshot didn't print the expected char string either. Another indicator it was a good call to switch to an icon

🗙
<svg
aria-hidden="true"
className="dashicon dashicons-arrow-down-alt2"
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 hmm, this is a bit surprising, shouldn't this be the no-alt icon in the snapshot? Actually in looking closer, it looks like we have bad classnames in the no-alt.js file in our icon library folder. It could be handled in a separate issue (See #2846).

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 missed that. Will open a PR today fixing it.

Comment on lines 1 to 2
// 17px is the minimum input field line-height and 14px is the font-size of
// the drop down selector elements.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 17px is the minimum input field line-height and 14px is the font-size of
// the drop down selector elements.
// 18px is the minimum input field line-height and 14px is the font-size of
// the drop down selector elements.

@Aljullu Aljullu merged commit 0421af4 into main Jul 10, 2020
@Aljullu Aljullu deleted the fix/1786-unify-chip-styles branch July 10, 2020 09:09
@nerrad nerrad mentioned this pull request Jul 20, 2020
21 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: active filters Issues related to the Active Filters block. block: filter by attribute Issues related to the Filter by Attribute block. focus: components Work that introduces new or updates existing components. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify chips style
4 participants