Skip to content

Commit

Permalink
fix(storefront): BCTHEME-207 fix focus on sort by select after reload…
Browse files Browse the repository at this point in the history
…ing page
  • Loading branch information
bc-alexsaiannyi committed Jan 21, 2021
1 parent 2a3269e commit 5ac7c4c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions assets/js/theme/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ export default class Category extends CatalogPage {
super(context);
this.validationDictionary = createTranslationDictionary(context);
this.isSortBySelected = window.localStorage.getItem('sortByStatus');
}

keepActiveElementOnStorage($element) {
$element.on('change', () => window.localStorage.setItem('sortByStatus', 'selected'));
window.addEventListener('beforeunload', () => {
if (document.activeElement.id === 'sort') {
window.localStorage.setItem('sortByStatus', 'selected');
}
});
}

arrangeFocusOnElement($element) {
onReady() {
const sortBySelector = $('#sort');

if (this.isSortBySelected) {
$element.focus();
sortBySelector.focus();
window.localStorage.removeItem('sortByStatus');
}
}

onReady() {
const sortBySelector = $('[data-sort-by="product"] #sort');

$('[data-button-type="add-cart"]').on('click', (e) => {
$(e.currentTarget).next().attr({
Expand All @@ -32,9 +32,6 @@ export default class Category extends CatalogPage {
});
});

this.keepActiveElementOnStorage(sortBySelector);
this.arrangeFocusOnElement(sortBySelector);

compareProducts(this.context.urls);

if ($('#facetedSearch').length > 0) {
Expand Down

0 comments on commit 5ac7c4c

Please sign in to comment.