Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CIF-2272 - Cannot close category filter accordion once it is open #656

Merged
merged 8 commits into from
Aug 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProductCollection {
constructor(config) {
this._element = config.element;

let sortKeySelect = document.querySelector(ProductCollection.selectors.sortKey);
let sortKeySelect = this._element.querySelector(ProductCollection.selectors.sortKey);
if (sortKeySelect) {
sortKeySelect.addEventListener('change', () => this._applySortKey(sortKeySelect));
}
Expand All @@ -29,6 +29,21 @@ class ProductCollection {
loadMoreButton.addEventListener('click', () => this._loadMore(loadMoreButton));
}

let filters = this._element.querySelector(ProductCollection.selectors.filtersBody);
if (filters) {
let selectedFilter = null;
filters.addEventListener('click', e => {
if (e.target.type === 'radio') {
if (selectedFilter && selectedFilter === e.target) {
e.target.checked = false;
selectedFilter = null;
} else if (e.target.checked) {
selectedFilter = e.target;
}
}
});
}

// Local state
this._state = {
// List of skus currently displayed in the list
Expand Down Expand Up @@ -217,7 +232,8 @@ ProductCollection.selectors = {
sortKey: '.productcollection__sort-keys',
galleryItems: '.productcollection__items',
loadMoreButton: '.productcollection__loadmore-button',
loadMoreSpinner: '.productcollection__loadmore-spinner'
loadMoreSpinner: '.productcollection__loadmore-spinner',
filtersBody: '.productcollection__filters-body'
};

(function(document) {
Expand Down
Loading