Skip to content

Commit

Permalink
fix(storefront): Reviews pagination navigation buttons reload the who…
Browse files Browse the repository at this point in the history
…le page and does not open the Reviews tab (#2048)
  • Loading branch information
yurytut1993 authored Jul 22, 2021
1 parent 6a683ae commit fa09490
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Draft
- Reviews pagination navigation buttons reload page and does not open the Reviews tab. [#2048](https://github.com/bigcommerce/cornerstone/pull/2048)
- Fix social share links for product pages and blog posts [#2082](https://github.com/bigcommerce/cornerstone/pull/2082)
- 'undefined' is announced with screen reader while changing Product quantity on PDP. [#2094](https://github.com/bigcommerce/cornerstone/pull/2094)
- Counter on the Wish Lists tab on Account page has been removed. [#2087](https://github.com/bigcommerce/cornerstone/pull/2087)
Expand Down
4 changes: 4 additions & 0 deletions assets/js/theme/global/quick-view.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'foundation-sites/js/foundation/foundation';
import 'foundation-sites/js/foundation/foundation.dropdown';
import utils from '@bigcommerce/stencil-utils';
import Review from '../product/reviews';
import ProductDetails from '../common/product-details';
import { defaultModal, ModalEvents } from './modal';
import 'slick-carousel';
Expand Down Expand Up @@ -41,6 +42,9 @@ export default function (context) {
}
}

/* eslint-disable no-new */
new Review({ $context: modal.$content });

return new ProductDetails(modal.$content.find('.quickView'), context);
});
});
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class Product extends PageManager {

if ($reviewForm.length === 0) return;

const review = new Review($reviewForm);
const review = new Review({ $reviewForm });

$('body').on('click', '[data-reveal-id="modal-review-form"]', () => {
validator = review.registerValidation(this.context);
Expand Down
59 changes: 39 additions & 20 deletions assets/js/theme/product/reviews.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
import nod from '../common/nod';
import { CollapsibleEvents } from '../common/collapsible';
import collapsibleFactory, { CollapsibleEvents } from '../common/collapsible';
import forms from '../common/models/forms';
import { safeString } from '../common/utils/safe-string';
import { announceInputErrorMessage } from '../common/utils/form-utils';

export default class {
constructor($reviewForm) {
this.validator = nod({
submit: $reviewForm.find('input[type="submit"]'),
tap: announceInputErrorMessage,
});
constructor({ $reviewForm, $context }) {
if ($reviewForm && $reviewForm.length) {
this.validator = nod({
submit: $reviewForm.find('input[type="submit"]'),
tap: announceInputErrorMessage,
});
}

this.$reviewsContent = $('#product-reviews');
this.$context = $context;
this.$reviewTabLink = $('.productView-reviewTabLink', this.$context);
this.$reviewsContent = $('#product-reviews', this.$context);
this.$reviewsContentList = $('#productReviews-content', this.$reviewsContent);
this.$collapsible = $('[data-collapsible]', this.$reviewsContent);

this.initLinkBind();
if (this.$context) {
collapsibleFactory('[data-collapsible]', { $context });
} else {
this.initLinkBind();
}

this.injectPaginationLink();
this.collapseReviews();
this.setupReviews();
}

/**
* On initial page load, the user clicks on "(12 Reviews)" link
* The browser jumps to the review page and should expand the reviews section
*/
initLinkBind() {
const $content = $('#productReviews-content', this.$reviewsContent);

$('#productReview_link').on('click', () => {
$('.productView-reviewTabLink').trigger('click');
if (!$content.hasClass('is-open')) {
this.$collapsible.trigger(CollapsibleEvents.click);
}
});
const $productReviewLink = $('#productReview_link');
$productReviewLink
.attr('href', `${$productReviewLink.attr('href')}${window.location.search}#product-reviews`)
.on('click', () => this.expandReviews());
}

collapseReviews() {
// We're in paginating state, do not collapse
if (window.location.hash && window.location.hash.indexOf('#product-reviews') === 0) {
setupReviews() {
// We're in paginating state, reviews should be visible
if (
window.location.hash
&& window.location.hash.indexOf('#product-reviews') === 0
&& this.$reviewsContent.parents('.quickView').length === 0
) {
this.expandReviews();
return;
}

// force collapse on page load
this.$collapsible.trigger(CollapsibleEvents.click);
}

expandReviews() {
this.$reviewTabLink.trigger('click');

if (!this.$reviewsContentList.hasClass('is-open')) {
this.$collapsible.trigger(CollapsibleEvents.click);
}
}

/**
* Inject ID into the pagination link
*/
Expand Down
2 changes: 1 addition & 1 deletion templates/components/products/product-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h2 class="productView-brand"{{#if schema}} itemprop="brand" itemscope itemtype=
{{/if}}
{{> components/products/ratings rating=product.rating}}
{{#if product.num_reviews '>' 0}}
<a href="{{product.url}}#product-reviews" id="productReview_link">
<a href="{{product.url}}{{#if is_ajax}}#product-reviews{{/if}}" id="productReview_link">
{{lang 'products.reviews.link_to_review' total=product.num_reviews}}
</a>
{{else}}
Expand Down
4 changes: 4 additions & 0 deletions templates/components/products/quick-view.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<div class="modal-body quickView">
{{> components/products/product-view schema=false}}

{{#all settings.show_product_reviews theme_settings.show_product_reviews (if theme_settings.show_product_details_tabs '!==' true)}}
{{> components/products/reviews reviews=product.reviews product=product urls=urls}}
{{/all}}
</div>
2 changes: 1 addition & 1 deletion templates/components/products/reviews.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h5 itemprop="name" class="productReview-title">{{{ sanitize title }}}</h5>
</li>
{{/each}}
</ul>
{{> components/common/paginator pagination.reviews}}
{{> components/common/paginator pagination.reviews reload=true}}
</div>
</section>
{{/if}}

0 comments on commit fa09490

Please sign in to comment.