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
  • Loading branch information
yurytut1993 committed Apr 30, 2021
1 parent 31ac15a commit f49ff39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Draft
- Reviews pagination navigation buttons reload the whole page and does not open the Reviews tab. [#2047](https://github.com/bigcommerce/cornerstone/pull/2047)
- Added settings for payment banners. [#2021](https://github.com/bigcommerce/cornerstone/pull/2021)
- Use https:// for schema markup. [#2039](https://github.com/bigcommerce/cornerstone/pull/2039)
- Update focus tooltip styles contrast to achieve accessibility AA Complaince. [#2047](https://github.com/bigcommerce/cornerstone/pull/2047)
Expand Down
23 changes: 12 additions & 11 deletions assets/js/theme/product/reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,39 @@ export default class {
});

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

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);
}
});
$('#productReview_link').on('click', () => this.showReviews());
}

collapseReviews() {
setupReviews() {
// We're in paginating state, do not collapse
if (window.location.hash && window.location.hash.indexOf('#product-reviews') === 0) {
return;
return this.showReviews();
}

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

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

/**
* Inject ID into the pagination link
*/
Expand Down

0 comments on commit f49ff39

Please sign in to comment.