Skip to content

Commit

Permalink
fix(storefront): BCTHEME-431 remove horizontal scroll on swatch optio…
Browse files Browse the repository at this point in the history
…ns PDP
  • Loading branch information
bc-alexsaiannyi committed Mar 29, 2021
1 parent 437f0cc commit bdc9e88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -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
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);

$(window).on('load', () => {
$.each($productSwatchLabels, (_, label) => {
const $optionImage = $('.form-option-expanded', $(label));
const optionImageWidth = $optionImage.outerWidth();
const { right } = label.getBoundingClientRect();
const emptySpaceToScreenRightBorder = window.screen.width - right;
const shiftValue = optionImageWidth - emptySpaceToScreenRightBorder;

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

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

0 comments on commit bdc9e88

Please sign in to comment.