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

[Quick Order List] Prevent selected inputs being covered by total bar or header #3278

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions assets/quantity-popover.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ quantity-popover volume-pricing li {

.quantity-popover__info.global-settings-popup {
width: 100%;
z-index: 2;
z-index: 3;
position: absolute;
background-color: rgb(var(--color-background));
max-width: 36rem;
Expand Down Expand Up @@ -161,4 +161,4 @@ quantity-popover .quantity__rules .divider:nth-child(2)::before {
quantity-popover .quantity__button:not(:focus-visible):not(.focused),
quantity-popover .quantity__input:not(:focus-visible):not(.focused) {
background-color: initial;
}
}
2 changes: 1 addition & 1 deletion assets/quick-order-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ quick-order-list input::placeholder {
.quick-order-list__total {
position: sticky;
bottom: 0;
z-index: 1;
z-index: 2;
background-color: rgb(var(--color-background));
}

Expand Down
33 changes: 31 additions & 2 deletions assets/quick-order-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ class QuickOrderList extends HTMLElement {
this.quickOrderListId = 'quick-order-list'
this.variantItemStatusElement = document.getElementById('shopping-cart-variant-item-status');
const form = this.querySelector('form');
this.inputFieldHeight = this.querySelector('.variant-item__quantity-wrapper').offsetHeight;
this.stickyHeaderElement = document.querySelector('sticky-header');

if (this.stickyHeaderElement) {
this.stickyHeader = {
height: this.stickyHeaderElement.offsetHeight,
type: `${this.stickyHeaderElement.getAttribute('data-sticky-type')}`
};
}

this.totalBarPosition = window.innerHeight - this.querySelector('.quick-order-list__total').offsetHeight;

window.addEventListener('resize', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Good idea to think of this use case 👍

this.totalBarPosition = window.innerHeight - this.querySelector('.quick-order-list__total').offsetHeight;
this.stickyHeader.height = this.stickyHeaderElement ? this.stickyHeaderElement.offsetHeight: null;
});

form.addEventListener('submit', this.onSubmit.bind(this));
const debouncedOnChange = debounce((event) => {
Expand Down Expand Up @@ -189,6 +205,7 @@ class QuickOrderList extends HTMLElement {
if (event.target.tagName !== 'INPUT') {
return;
}

this.VariantListInput = event.target;
this.VariantListInput.select()
this.VariantListInput.addEventListener('keydown', (e) => {
Expand All @@ -200,14 +217,26 @@ class QuickOrderList extends HTMLElement {
if (!e.shiftKey) {
const nextIndex = currentIndex + 1;
const nextVariant = this.allInputsArray[nextIndex] || this.allInputsArray[0];
nextVariant.focus();
nextVariant.select();
} else {
const previousIndex = currentIndex - 1;
const previousVariant = this.allInputsArray[previousIndex] || this.allInputsArray[this.allInputsArray.length - 1];
previousVariant.focus();
previousVariant.select();
}
}
});

const inputTopBorder = this.VariantListInput.getBoundingClientRect().top;
const inputBottomBorder = this.VariantListInput.getBoundingClientRect().bottom;
const stickyHeaderBottomBorder = this.stickyHeaderElement && this.stickyHeaderElement.getBoundingClientRect().bottom;
const totalBarCrossesInput = inputBottomBorder > this.totalBarPosition;
const inputOutsideOfViewPort = inputBottomBorder < this.inputFieldHeight;
const stickyHeaderCrossesInput = this.stickyHeaderElement && this.stickyHeader.type !== 'on-scroll-up' && this.stickyHeader.height > inputTopBorder;
const stickyHeaderScrollupCrossesInput = this.stickyHeaderElement && this.stickyHeader.type === 'on-scroll-up' && this.stickyHeader.height > inputTopBorder && stickyHeaderBottomBorder > 0;

if (totalBarCrossesInput || inputOutsideOfViewPort || stickyHeaderCrossesInput || stickyHeaderScrollupCrossesInput) {
this.VariantListInput.scrollIntoView({ block: 'center', behavior: 'smooth' });
}
}

updateMultipleQty(items) {
Expand Down
Loading