-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
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.
Quick suggestion. Will finish review afterwards.
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.
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.
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.
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! 🎉 🎉
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.
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.
-
Changing the variants still often doesn’t scroll to the top. This seems to mostly happen when the hide variant setting is disabled OR when it is enabled but you scrolled the slider to another image. https://screenshot.click/15-08-bzap0-dhhkb.mp4
-
The slider counter also counts down as the scroll position is reset to 0 upon changing the variant. This isn't a big deal but it'd be nice to try and fix. https://screenshot.click/15-12-v284p-uh7qr.mp4
-
I have also seen the slider lose track of it's position, which is kind of weird and hard to reproduce reliably https://screenshot.click/15-43-thbkj-8acf5.mp4
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.
Tested and it works as expected. I have a question about the expectation for modals, though.
locales/en.default.schema.json
Outdated
@@ -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" |
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.
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.
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.
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! 🙌
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.
"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.
1ba0a33
to
a02eb3b
Compare
@LucasLacerdaUX & @kmeleta, I've made a few changes to address some of your comments:
|
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.
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.
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.
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>
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.
Mostly nitpicks, but there are some code-design related questions / discussions that I'd like to hear your thoughts.
sections/header.liquid
Outdated
|
||
document.addEventListener('preventHeaderReveal', this.hideHeaderOnScrollUp); |
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.
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?
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.
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
sections/header.liquid
Outdated
window.clearTimeout(this.isScrolling); | ||
|
||
this.isScrolling = setTimeout(() => { | ||
this.preventReveal = false; | ||
}, 66); |
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.
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? 👀
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.
Done 👍 As for the 66
it was just something I used because of the article reference I was using.
@LucasLacerdaUX, @kmeleta ready for another review. I've requested the translations in the mean time. |
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.
Looking real nice now! I just see one little thing, then I feel like we're gtg.
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.
assets/global.js
Outdated
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); |
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.
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.
🎯
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.
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
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 aclientWidth > 0
. This is my way for not including hidden elements (usingdisplay: none;
) within the array we use to calculate ourtotalPages
.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 theHide inactive variants
box.Checklist