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

Hide variant images setting #158

Merged
merged 18 commits into from
Aug 19, 2021
Merged

Hide variant images setting #158

merged 18 commits into from
Aug 19, 2021

Conversation

ludoboludo
Copy link
Contributor

@ludoboludo ludoboludo commented Jul 8, 2021

Why are these changes introduced?

Fixes #30
Fixes #191

What approach did you take?

I used CSS to hide variant images as mentioned in the issue. I had to also add some JS to deal with it on mobile where I needed to tweak how the total of slides was calculated.
So I'm creating a new array that regroup all li elements that have a clientWidth > 0. This is my way for not including hidden elements (using display: none;) within the array we use to calculate our totalPages.

Other considerations

One thing I'm noticing as I was playing with it, is that when you change the variant, it doesn't scroll you back up on the new image. I see in the JS: window.setTimeout(() => { parent.scroll(0, 0) }); but it doesn't seem to do anything. Video.

Demo links

Testing

Go to the Editor linked above, to the product page (Shoes > Louise Slide Sandal) and click on the Product information heading and check the Hide inactive variants box.

Checklist

@ludoboludo ludoboludo marked this pull request as ready for review July 12, 2021 16:14
@ludoboludo ludoboludo requested a review from tyleralsbury July 12, 2021 16:26
Copy link
Contributor

@tyleralsbury tyleralsbury left a comment

Choose a reason for hiding this comment

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

Quick suggestion. Will finish review afterwards.

@LucasLacerdaUX LucasLacerdaUX self-requested a review July 12, 2021 21:02
Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

Still testing, but thought I'd leave a couple quick notes.

One thing I'm noticing as I was playing with it, is that when you change the variant, it doesn't scroll you back up on the new image. I see in the JS: window.setTimeout(() => { parent.scroll(0, 0) }); but it doesn't seem to do anything.

Seems like this line will successfully reset the horizontal scrolling on mobile when the slider is displayed. But on desktop, the scrollable element isn't the parent element of the media, it's the document/window.

Copy link
Contributor

@melissaperreault melissaperreault left a comment

Choose a reason for hiding this comment

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

One thing I'm noticing as I was playing with it, is that when you change the variant, it doesn't scroll you back up on the new image.

From a UX perspective, it would be expected to scroll back up when the buyer interacts with the variant. If they have the interest to explore the variant list and that merchants assigned a media to it, it's relevant in the purchase flow to have focus on the right visual.

Other than that, looks good to me! 🎉 🎉

kmeleta
kmeleta previously approved these changes Jul 15, 2021
Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

This looks good Ludo. Changing sizes now doesn’t scroll the featured image into view but color variant changes do. Good work getting that included.

On mobile though I notice a couple inconsistencies that I'll describe here, but I'm fine investigating them as a separate issue. They seem to be related to how the slider interacts with the variant picking in general, not necessarily a direct result of this PR.

@kmeleta kmeleta removed their assignment Jul 15, 2021
Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX left a comment

Choose a reason for hiding this comment

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

Tested and it works as expected. I have a question about the expectation for modals, though.

@@ -1273,6 +1273,9 @@
"enable_sticky_info": {
"label": "Enable sticky product information on large screens"
},
"hide_variants": {
"label": "Hide other variants’ media when a variant is selected"
Copy link
Contributor

Choose a reason for hiding this comment

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

If the expectation is to have all variant media visible inside the modal, does this setting naming still makes sense? My expectation is that turning this on will hide other variants' media EVERYWHERE.

Copy link
Contributor

Choose a reason for hiding this comment

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

The expectation is to hide everywhere when the setting is true, I believe it was the case when I tested if I recall. Otherwise it was overlooked, when this setting is enabled, it applies to all devices! 🙌

Copy link
Contributor

@melissaperreault melissaperreault Aug 16, 2021

Choose a reason for hiding this comment

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

Suggested change
"label": "Hide other variants’ media when a variant is selected"
"label": "Hide other variants’ media after selecting a variant"

Hey @gretchen-willenberg the reason why we didn't see this line of text is because the PR was not merged yet. I suggested the change based on your audit! Confirming this is a setting label, so no period at the end of the sentence.

@ludoboludo ludoboludo force-pushed the variant-img-setting branch from 1ba0a33 to a02eb3b Compare August 5, 2021 15:59
@ludoboludo
Copy link
Contributor Author

@LucasLacerdaUX & @kmeleta, I've made a few changes to address some of your comments:

  • the scroll into view works better now but still some issues specifically on Chrome. It seems to have more issues. Firefox and Safari seem to work just fine but on Chrome it won't always happen or scrollLeft properly 🤷 trying to see what I can find. I saw mentioned that scrollTo might work better but it didn't seem to help when I tested. (issue I found and this one though it might not be the exact same issue 🤔
  • I used a setTimeout for preventing the sticky header to show up. When I test on a slow 3g connection it still seemed to work fine. I wanted to use something different but concerned if I added an element to product__media-list as it would potentially mess with some CSS styling specificity. Curious to hear your thoughts though.

@kmeleta kmeleta self-assigned this Aug 9, 2021
Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

Wanted to share a couple thoughts on potential improvements, but I think it'd be nice to get this work merged despite some little scroll quirks.

Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX left a comment

Choose a reason for hiding this comment

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

I believe the JS needs some refactoring. Let me know if you have any questions or if there is something I can add to make it clearer.

Overall, I feel like this interaction between VariantSelects and StickyHeader can be improved by removing the .product-section interface between the two and concentrating the scroll prevention logic in the StickyHeader component.

Co-authored-by: melissaperreault <melissa.perreault@shopify.com>
Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX left a comment

Choose a reason for hiding this comment

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

Mostly nitpicks, but there are some code-design related questions / discussions that I'd like to hear your thoughts.


document.addEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not so sure about this preventHeaderReveal listener on a document level + use of bubbling, because that means the event is being propagated on multiple levels...

Sure, from my limited knowledge, it seems like the performance impact is probably insignificant. But from a code design perspective, I feel like this event should be dispatched directly to the sticky-header from VariantSelects so this StickyHeader JS can easily add the eventListeners to itself.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea. It sounds much cleaner. My interpretation of dispatchEvent was that I was setting the element receiving a change to say to the others Hey, something happened within me!. I've changed the approach now: c09d46d

Comment on lines 474 to 478
window.clearTimeout(this.isScrolling);

this.isScrolling = setTimeout(() => {
this.preventReveal = false;
}, 66);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed when if (this.preventReveal == false)? If not, we can include it inside if (this.preventReveal) below.

Also, where is this 66 timeout coming from? 👀

Copy link
Contributor Author

@ludoboludo ludoboludo Aug 17, 2021

Choose a reason for hiding this comment

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

Done 👍 As for the 66 it was just something I used because of the article reference I was using.

@LucasLacerdaUX LucasLacerdaUX mentioned this pull request Aug 18, 2021
5 tasks
@ludoboludo
Copy link
Contributor Author

@LucasLacerdaUX, @kmeleta ready for another review. I've requested the translations in the mean time.

Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

Looking real nice now! I just see one little thing, then I feel like we're gtg.

@ludoboludo ludoboludo requested a review from kmeleta August 19, 2021 14:49
kmeleta
kmeleta previously approved these changes Aug 19, 2021
Copy link
Contributor

@kmeleta kmeleta left a comment

Choose a reason for hiding this comment

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

:shipit:

assets/global.js Outdated
Comment on lines 540 to 544
const modalContent = document.querySelector(`#ProductModal-${this.dataset.section}`);
const newMediaModal = modalContent.querySelector( `[data-media-id="${this.currentVariant.featured_media.id}"]`);
const parent = newMedia.parentElement;
if (parent.firstChild == newMedia) return;
modalContent.prepend(newMediaModal);
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that this modalContent element is not the right one.

#ProductModal-${this.dataset.section} points to the external modal, not its content wrapper.

image

This is causing the element to be prepended to the wrong container:
image

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🎯

Copy link
Contributor

@LucasLacerdaUX LucasLacerdaUX left a comment

Choose a reason for hiding this comment

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

image

@ludoboludo ludoboludo merged commit ce0e5ec into main Aug 19, 2021
@ludoboludo ludoboludo deleted the variant-img-setting branch August 19, 2021 18:46
tairli added a commit to tairli/dawn that referenced this pull request Aug 22, 2021
commit 399626d
Author: tairli <tairli@yahoo.com>
Date:   Mon Aug 23 04:47:25 2021 +0930

    Update product-form.js

commit 330e6b4
Merge: 79467e4 7a2f34f
Author: tairli <tairli@yahoo.com>
Date:   Mon Aug 23 04:45:54 2021 +0930

    Merge remote-tracking branch 'upstream/main' into main

commit 7a2f34f
Author: Lucas Lacerda <37168033+LucasLacerdaUX@users.noreply.github.com>
Date:   Thu Aug 19 15:55:39 2021 -0400

    Add featured product section (Shopify#261)

commit 9789ae1
Author: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Date:   Thu Aug 19 15:52:08 2021 -0400

    Update 2 translation files (Shopify#449)

    Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

commit d83f16f
Author: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Date:   Thu Aug 19 15:51:51 2021 -0400

    Update 7 translation files (Shopify#448)

    Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

commit ce0e5ec
Author: Ludo <ludo.segura@shopify.com>
Date:   Thu Aug 19 14:46:05 2021 -0400

    Hide variant images setting (Shopify#158)

commit d3b44e7
Author: Ludo <ludo.segura@shopify.com>
Date:   Thu Aug 19 10:29:50 2021 -0400

    Update font style for Default preset (Shopify#435)

    * Update font style for Default preset

    * updated default in settings_schema

commit 2643bab
Author: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Date:   Thu Aug 19 10:29:34 2021 -0400

    Update 15 translation files (Shopify#439)

    Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

commit e9a2fd4
Author: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Date:   Thu Aug 19 10:02:16 2021 -0400

    Update 4 translation files (Shopify#440)

    Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

commit 9ea0392
Author: Ludo <ludo.segura@shopify.com>
Date:   Wed Aug 18 17:19:16 2021 -0400

    404 continue shopping style (Shopify#419)

commit 6c2128a
Author: Ken Meleta <30790058+kmeleta@users.noreply.github.com>
Date:   Wed Aug 18 15:14:33 2021 -0600

    Update price sale badge spacing (Shopify#430)

commit a6d25cf
Author: Kai <KaichenWang@users.noreply.github.com>
Date:   Wed Aug 18 11:13:22 2021 -0400

    Adjust global focus styles for inputs, selects and collection filter UI elements (Shopify#389)

    * Adjust global focus styles for inputs, selects and collection filter UI elements

    * Fix focus for filter drawer summary elements

    * Simplify focus for elements that are always "focus-visible" when in focus

    * Adjust focus style of search submit button

commit 002b6b0
Author: Ken Meleta <30790058+kmeleta@users.noreply.github.com>
Date:   Wed Aug 18 09:01:47 2021 -0600

    Product card spacing and price polish (Shopify#407)

    * Adjust product card spacing and price styles

    * Fix unit price/sale badge spacing

    * Revert flex gap approach

commit 6fa46b7
Author: Ludo <ludo.segura@shopify.com>
Date:   Wed Aug 18 10:54:58 2021 -0400

    Update Preset default (Shopify#410)

commit 341e051
Author: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>
Date:   Wed Aug 18 10:43:37 2021 -0400

    Update 10 translation files (Shopify#427)

    Co-authored-by: translation-platform[bot] <34770790+translation-platform[bot]@users.noreply.github.com>

commit 79467e4
Merge: 42cad96 789c3d9
Author: tairli <tairli@yahoo.com>
Date:   Wed Aug 18 19:26:00 2021 +0930

    Merge branch 'Shopify:main' into main

commit 42cad96
Merge: b5ddb38 2ba2725
Author: tairli <tairli@yahoo.com>
Date:   Tue Aug 17 22:06:29 2021 +0930

    Merge branch 'Shopify:main' into main
phapsidesGT pushed a commit to Gravytrain-UK/gt-shopify-dawn-theme that referenced this pull request Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variant image switching Product Page: New Setting: Show only images for currently selected variants
6 participants