Skip to content

Commit 8412f7a

Browse files
authored
Merge pull request #565 from tswfi/pager_scroll_to_top_of_products
Change pager scrolling behaviour, Fixes #562
2 parents ec089f5 + 4a29900 commit 8412f7a

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

src/js/constants/selectors-map.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const listing = {
2626
listHeader: '#js-product-list-header',
2727
searchFiltersClearAll: '.js-search-filters-clear-all',
2828
searchLink: '.js-search-link',
29+
pagerLink: '.js-pager-link',
2930
};
3031

3132
export const cart = {

src/js/modules/facetedsearch/update.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ export default () => {
8080
);
8181
});
8282

83+
/**
84+
* Pager links also scroll up
85+
*/
86+
$('body').on('click', Theme.selectors.listing.pagerLink, (event) => {
87+
event.preventDefault();
88+
document.querySelector(Theme.selectors.listing.listTop)?.scrollIntoView({block: 'start', behavior: 'auto'});
89+
prestashop.emit(
90+
events.updateFacets,
91+
$(event.target)?.closest('a')?.get(0)?.getAttribute('href'),
92+
);
93+
});
94+
8395
if ($(Theme.selectors.listing.list).length) {
8496
window.addEventListener('popstate', (e) => {
8597
const {state} = e;
@@ -99,6 +111,5 @@ export default () => {
99111
prestashop.on(events.updateProductList, (data: Record<string, never>) => {
100112
updateProductListDOM(data);
101113
useQuantityInput();
102-
window.scrollTo(0, 0);
103114
});
104115
};

src/scss/custom/components/category/_product-list.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
.layout-left-column,
88
.layout-full-width {
9+
#js-product-list-top {
10+
scroll-margin: 120px;
11+
}
12+
913
.products-selection {
1014
margin-bottom: 1.25rem;
1115

templates/_partials/pagination.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<li class="page-item{if $page.current} active{/if}" {if $page.current}aria-current="page" {/if}>
2626
<a rel="{if $page.type === 'previous'}prev{elseif $page.type === 'next'}next{else}nofollow{/if}"
2727
href="{$page.url}"
28-
class="page-link btn-with-icon {if $page.type === 'previous'}previous {elseif $page.type === 'next'}next {/if}{['disabled' => !$page.clickable, 'js-search-link' => true]|classnames}">
28+
class="page-link btn-with-icon {if $page.type === 'previous'}previous {elseif $page.type === 'next'}next {/if}{['disabled' => !$page.clickable, 'js-pager-link' => true]|classnames}">
2929
{if $page.type === 'previous'}
3030
<i class="material-icons rtl-flip" aria-hidden="true">&#xE314;</i>
3131
<span class="d-none d-md-flex">{l s='Previous' d='Shop.Theme.Actions'}</span>

types/selectors.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ declare type listing = {
2626
listHeader: string,
2727
searchFiltersClearAll: string,
2828
searchLink: string,
29+
pagerLink: string,
2930
};
3031

3132
declare type cart = {

0 commit comments

Comments
 (0)