Skip to content

Commit

Permalink
Update multiple quick add modals for parity throughout multiple sections
Browse files Browse the repository at this point in the history
Refresh quick order list elements after rendering

Simplify the refresh

Better variable naming
  • Loading branch information
cfxd committed Sep 23, 2024
1 parent cd041f6 commit 8b18d24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 20 additions & 2 deletions assets/quick-order-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,13 @@ if (!customElements.get('quick-order-list')) {
id: `quick-order-list-live-region-text-${this.dataset.productId}`,
section: 'cart-live-region-text',
selector: '.shopify-section',
selectorAll: `.quick-order-list__live-region-text[data-product-id="${this.dataset.productId}"]`,
},
{
id: `quick-order-list-total-${this.dataset.productId}-${this.dataset.section}`,
section: document.getElementById(this.quickOrderListId).dataset.section,
selector: `#${this.quickOrderListId} .quick-order-list__total`,
selectorAll: `.quick-order-list__total[data-product-id="${this.dataset.productId}"]`,
},
{
id: 'CartDrawer',
Expand Down Expand Up @@ -260,10 +262,22 @@ if (!customElements.get('quick-order-list')) {
if (elementToReplace) {
if (section.selector === `#${this.quickOrderListId} .js-contents` && this.ids.length > 0) {
this.ids.flat().forEach((i) => {
elementToReplace.querySelector(`#Variant-${i}`).innerHTML = this.getSectionInnerHTML(
document
.querySelectorAll(`.quick-order-list__container .variant-item[data-variant-id="${i}"]`)
.forEach((variantElementToReplace) => {
variantElementToReplace.innerHTML = this.getSectionInnerHTML(
parsedState.sections[section.section],
`#Variant-${i}`
);
});
});
} else if (section.selectorAll) {
document.querySelectorAll(section.selectorAll).forEach((allElementToReplace) => {
allElementToReplace.innerHTML = this.getSectionInnerHTML(
parsedState.sections[section.section],
`#Variant-${i}`
section.selector
);
allElementToReplace.closest('quick-order-list').resetAfterRender();
});
} else {
elementToReplace.innerHTML = this.getSectionInnerHTML(
Expand All @@ -273,6 +287,10 @@ if (!customElements.get('quick-order-list')) {
}
}
});
this.resetAfterRender();
}

resetAfterRender() {
this.defineInputsAndQuickOrderTable();
this.addMultipleDebounce();
this.ids = [];
Expand Down
4 changes: 3 additions & 1 deletion snippets/quick-order-list.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@
</div>

<p
class="visually-hidden"
class="quick-order-list__live-region-text visually-hidden"
id="quick-order-list-live-region-text-{{ product.id }}"
aria-live="polite"
role="status"
data-product-id="{{ product.id }}"
></p>
<p
class="visually-hidden"
Expand All @@ -126,6 +127,7 @@
<div
class="quick-order-list__total{% unless is_modal %} gradient{% endunless %}"
id="quick-order-list-total-{{ product.id }}-{{ section.id }}"
data-product-id="{{ product.id }}"
>
<div class="quick-order-list-total__info">
<div class="quick-order-list-total__column small-hide medium-hide">
Expand Down

0 comments on commit 8b18d24

Please sign in to comment.