Skip to content

Commit

Permalink
fix(storefront): BCTHEME-207 fix focus on sort by (bigcommerce#1964)
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi authored and sacr3dc0w committed Mar 31, 2021
1 parent efb2147 commit c1bd587
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 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
- Fixed focus for sort by dropdown on reloading page. [#1964](https://github.com/bigcommerce/cornerstone/pull/1964)
- Fixed filtered selection not announced by screen reader. [#1966](https://github.com/bigcommerce/cornerstone/pull/1966)

## 5.1.0 (01-26-2021)
Expand Down
19 changes: 19 additions & 0 deletions assets/js/theme/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import urlUtils from './common/utils/url-utils';
import Url from 'url';

export default class CatalogPage extends PageManager {
constructor(context) {
super(context);

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

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

if (window.localStorage.getItem('sortByStatus')) {
$sortBySelector.focus();
window.localStorage.removeItem('sortByStatus');
}
}

onSortBySubmit(event, currentTarget) {
const url = Url.parse(window.location.href, true);
const queryParams = $(currentTarget).serialize().split('=');
Expand Down
2 changes: 2 additions & 0 deletions assets/js/theme/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export default class Category extends CatalogPage {
}

onReady() {
this.arrangeFocusOnSortBy();

$('[data-button-type="add-cart"]').on('click', (e) => this.setLiveRegionAttributes($(e.currentTarget).next(), 'status', 'polite'));

this.makeShopByPriceFilterAccessible();
Expand Down
1 change: 1 addition & 0 deletions assets/js/theme/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export default class Search extends CatalogPage {

onReady() {
compareProducts(this.context.urls);
this.arrangeFocusOnSortBy();

const $searchForm = $('[data-advanced-search-form]');
const $categoryTreeContainer = $searchForm.find('[data-search-category-tree]');
Expand Down

0 comments on commit c1bd587

Please sign in to comment.