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

Fix double-taping on iPad to open popover in Quick Order List #2934

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

eugenekasimov
Copy link
Contributor

@eugenekasimov eugenekasimov commented Aug 2, 2023

PR Summary:

This PR fixes the issue when you need to tap twice on info-icon on iPad(tablets) in order to open the popover.

Why are these changes introduced?

Fixes #2890.

What approach did you take?

There was a conflict between two event listeners mouseenter and click that fired the same function same time. On iPad when you tap an element both events are fired, first mouseenter and then click.

We still need to keep them both because we have to cover cases for mouse and keyboard users and iPad and Desktop may have the same screen size.

I added a variable eventMouseEnterHappened to track a state of the mouseenter event. Now, if the mouseenter happens the click event won't be fired until eventMouseEnterHappened is reset.

Other considerations

Decision log

Visual impact on existing themes

Testing steps/scenarios

  • Add the quick order list section to the product page.
  • Login as a b2b customer and go to a product that has volume-pricing or qty rule.
  • Hovering mouse over info-icon test that popover element appears as expected.
  • Test the same on a tablet and make sure the popover element opens after first tap on the info-icon.

Demo links

Checklist

Copy link

@edmund-teh edmund-teh left a comment

Choose a reason for hiding this comment

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

This works beautifully on my iPad @eugenekasimov— great work!
Also, tested on my phone and on Desktop for any regressions... everything's looking solid. Thanks!

Copy link
Contributor

@andrewetchen andrewetchen left a comment

Choose a reason for hiding this comment

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

This works great! Left some small feedback in case you decide to change the variable name.

@@ -11,6 +11,7 @@ if (!customElements.get('quantity-popover')) {
this.popoverInfo = this.querySelector('.quantity-popover__info');
this.closeButton = this.querySelector('.button-close');
this.variantInfo = this.querySelector('.quantity-popover-container');
this.eventMouseEnterHappened = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nitpick but maybe we can simplify this to just this.mouseEnterCompleted as it conveys that the variable is related to the completion of the mouseenter event.

@@ -37,6 +39,11 @@ if (!customElements.get('quantity-popover')) {

togglePopover(event) {
event.preventDefault();
if (event.type === 'mouseenter') {
Copy link
Contributor

@sofiamatulis sofiamatulis Aug 3, 2023

Choose a reason for hiding this comment

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

Small suggestion: Maybe we can convert these to variables

this.actions = {
      mouseEnter: 'mouseenter',
      click: 'click'
    }

And refer to it as this.actions.click and this.actions.mouseEnter throughout the file

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 see we use it a lot in the file, we use it only in one function. Am I getting you right that you suggest we do it this way? I'm not sure if it's worth it but I'm okay if everyone agrees.

Suggested change
if (event.type === 'mouseenter') {
this.actions = {
mouseEnter: 'mouseenter',
click: 'click'
}
if (event.type === this.actions.mouseEnter) {
this.eventMouseEnterHappened = true;
}
if (event.type === this.actions.click && this.eventMouseEnterHappened) return;
const button = this.infoButtonDesktop && this.mql.matches ? this.infoButtonDesktop : this.infoButtonMobile;
const isExpanded = button.getAttribute('aria-expanded') === 'true';
button.setAttribute('aria-expanded', !isExpanded);
this.popoverInfo.toggleAttribute('hidden');
const isOpen = button.getAttribute('aria-expanded') === 'true';
button.classList.toggle('quantity-popover__info-button--open');
if (isOpen && event.type !== this.actions.mouseEnter) {
button.focus();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

That is fair! We can keep it as is, but if we repeat it more often throughout the file we can change that

Copy link
Contributor

@sofiamatulis sofiamatulis left a comment

Choose a reason for hiding this comment

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

Looks good! Added a small suggestion

@eugenekasimov eugenekasimov merged commit 7d02769 into main Aug 4, 2023
@eugenekasimov eugenekasimov deleted the fix-double-tap-quick-order-list branch August 4, 2023 14:57
TimmersThomas added a commit to TimmersThomas/shopify-template-houseofchocolate that referenced this pull request Aug 13, 2023
* upstream/main: (205 commits)
  Fix for small screens with large fonts don't fit all content (Shopify#2946)
  Adjust quantity rules margin (Shopify#2948)
  Update Social media settings defaults to remove Shopify links (Shopify#2830)
  added json to barcode to pass gtin as a json string (Shopify#2804)
  Fixed extra margin spacing in collage section when header is empty (Shopify#2770)
  Track state of mouseenter event (Shopify#2934)
  Fix misalignment of total items in quick order list (Shopify#2923)
  Hide vol pricing and qty rules when variant is unavailable (Shopify#2889)
  Fix font family for quick order list (Shopify#2888)
  v11.0.0 version bump and release notes (Shopify#2916)
  Revert "v11.0.0 version bump and release notes (Shopify#2906)" (Shopify#2915)
  Update quantity-popover.css
  v11.0.0 version bump and release notes (Shopify#2906)
  Fix social list styles loading (Shopify#2900)
  Fix an error (Shopify#2903)
  Fix hardcoded info color (Shopify#2893)
  Fix error misalignment for Quick order list (Shopify#2887)
  Replace generic section name with section ID. (Shopify#2884)
  Fix cart drawer for variant list and tablet spacing (Shopify#2880)
  Add missing shadow styles to inputs in Quick Order List (Shopify#2879)
  ...
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.

Quick order list: To open the popover on iPad Pro (and larger tablets), it requires a double-tap
4 participants