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(storefront): BCTHEME-431 remove horizontal scroll on swatch options PDP #2023

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Fixed unnecessary horizontal scroll on swatch options on PDP. [#2023](https://github.com/bigcommerce/cornerstone/pull/2023)

## 5.3.0 (03-24-2021)
- IE11 - Clicking on Search Does Not Display Search Bar. [#2017](https://github.com/bigcommerce/cornerstone/pull/2017)
Expand Down
15 changes: 15 additions & 0 deletions assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ export default class ProductDetails extends ProductDetailsBase {
const hasOptions = $productOptionsElement.html().trim().length;
const hasDefaultOptions = $productOptionsElement.find('[data-default]').length;
const $productSwatchGroup = $('[id*="attribute_swatch"]', $form);
const $productSwatchLabels = $('.form-option-swatch', $form);
const placeSwatchLabelImage = (_, label) => {
const $optionImage = $('.form-option-expanded', $(label));
const optionImageWidth = $optionImage.outerWidth();
const extendedOptionImageOffsetLeft = 55;
yurytut1993 marked this conversation as resolved.
Show resolved Hide resolved
const { right } = label.getBoundingClientRect();
const emptySpaceToScreenRightBorder = window.screen.width - right;
const shiftValue = optionImageWidth - emptySpaceToScreenRightBorder;

if (emptySpaceToScreenRightBorder < (optionImageWidth + extendedOptionImageOffsetLeft)) {
$optionImage.css('left', `${shiftValue > 0 ? -shiftValue : shiftValue}px`);
}
};

BC-tymurbiedukhin marked this conversation as resolved.
Show resolved Hide resolved
$(window).on('load', () => $.each($productSwatchLabels, placeSwatchLabelImage));

if (context.showSwatchNames) {
this.$swatchOptionMessage.removeClass('u-hidden');
Expand Down