Skip to content

Commit ab96d21

Browse files
committed
Added a count of the filters selected to the filter bar, added clar all function and removed pills of filters to reduce clutter on mobile view
1 parent 775aca1 commit ab96d21

3 files changed

Lines changed: 76 additions & 18 deletions

File tree

_includes/current-projects.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<nav class="filter-toolbar" aria-label="Filter Navbar">
55
<div class="filtersDiv">
66
<h3 class="filters-title">
7-
Filters
7+
<span class="filters-label-group">Filters <span id="counter_total" class="number-of-checked-boxes"></span> <a href="#" id="clear-all-filters" class="clear-filter-tags">Clear All</a></span>
88
<button class="show-filters-button" aria-label="Show All Filters">
99
<svg id='hamburger-filter-nav' width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
1010
<path d="M21.6297 12.2046H3.6297" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>

_sass/elements/_dropdown_filters.scss

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ a.clear-filter-tags {
239239
}
240240
}
241241

242+
// Style for the Clear All link
243+
.filters-title .number-of-checked-boxes {
244+
font-size: 0.85em; // slightly smaller than heading
245+
color: $color-black; // same color as the "Filters" text
246+
margin-left: 2px;
247+
}
248+
249+
.filters-title .clear-filter-tags {
250+
margin-left: 4px; // space between counter and link
251+
white-space: nowrap;
252+
display: none; // shown via JS when filters selected
253+
color: $color-cement;
254+
}
255+
242256
.number-of-checked-boxes {
243257
color: $color-red;
244258
}
@@ -252,6 +266,10 @@ a.clear-filter-tags {
252266
padding: 32px 16px;
253267
// flex-direction: column;
254268
}
269+
// Hide applied filter tags on mobile to conserve space
270+
.filter-tag-container {
271+
display: none !important;
272+
}
255273
.scroll-lock {
256274
overflow: hidden;
257275
}
@@ -364,4 +382,28 @@ a.clear-filter-tags {
364382
.show-none + .dropdown li {
365383
display: block;
366384
}
385+
386+
// Align Filters label, counter, and Clear All link
387+
.filters-label-group {
388+
display: flex;
389+
align-items: baseline;
390+
}
391+
.filters-label-group .number-of-checked-boxes {
392+
font-size: 0.85em;
393+
color: $color-black;
394+
margin-left: 4px;
395+
}
396+
.filters-label-group .clear-filter-tags {
397+
margin-left: 8px;
398+
white-space: nowrap;
399+
display: none;
400+
color: $color-cement;
401+
}
402+
}
403+
404+
@media #{$bp-tablet-up} {
405+
.filters-label-group .number-of-checked-boxes,
406+
.filters-label-group .clear-filter-tags {
407+
display: none !important; // hide on desktop
408+
}
367409
}

assets/js/current-projects.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,24 @@ function updateCategoryCounter(filterParams){
478478
}
479479
}
480480

481-
for(const [key,value] of container){
482-
// for issue #4648, added this to show the sum of selected filters for both technology and language filters
483-
let totalValue = 0
484-
for (const innerValue of container){
485-
totalValue += innerValue[1]
486-
}
487-
document.querySelector(`#${key}`).innerHTML = ` (${totalValue})`;
481+
// Calculate total selected filters across all categories (excluding Search)
482+
let totalSelected = container.reduce((sum, [,val]) => sum + val, 0);
483+
484+
// Update each category counter – preserve existing behaviour of showing combined totals
485+
for(const [key] of container){
486+
document.querySelector(`#${key}`) && (document.querySelector(`#${key}`).innerHTML = ` (${totalSelected})`);
487+
}
488+
489+
// Update the new overall filters counter in the title
490+
const totalCounterSpan = document.querySelector('#counter_total');
491+
if (totalCounterSpan){
492+
totalCounterSpan.innerHTML = totalSelected>0 ? ` (${totalSelected})` : '';
493+
}
494+
495+
// Show/hide Clear All link
496+
const clearAllLink = document.getElementById('clear-all-filters');
497+
if(clearAllLink){
498+
clearAllLink.style.display = totalSelected>0 ? 'inline' : 'none';
488499
}
489500

490501
}
@@ -621,13 +632,14 @@ function attachEventListenerToFilterTags(){
621632
button.addEventListener('click',filterTagOnClickEventHandler)
622633
})
623634

624-
// If there exist a filter-tag button on the page add a clear all button after the last filter tag button
625-
if(!document.querySelector('.clear-filter-tags')){
626-
document.querySelector('.filter-tag:last-of-type').insertAdjacentHTML('afterend',`<a class="clear-filter-tags" tabindex="0" aria-label="Clear All Filters" style="white-space: nowrap;">Clear All</a>`);
635+
// No longer inserting bottom Clear All link; top link exists.
636+
}
627637

628-
//Attach an event handler to the clear all button
629-
document.querySelector('.clear-filter-tags').addEventListener('click',clearAllEventHandler);
630-
}
638+
// Attach event to top Clear All link once (after DOM ready)
639+
const clearAllTop = document.getElementById('clear-all-filters');
640+
if(clearAllTop && !clearAllTop.dataset.listenerAdded){
641+
clearAllTop.addEventListener('click', function(e){ e.preventDefault(); clearAllEventHandler(); });
642+
clearAllTop.dataset.listenerAdded = 'true';
631643
}
632644
}
633645

@@ -647,12 +659,16 @@ function noUrlParameterUpdate(){
647659

648660
// Clear all number of checkbox counters
649661
document.querySelectorAll('.number-of-checked-boxes').forEach(checkBoxCounter => {checkBoxCounter.innerHTML = ''} );
662+
const totalCounterSpan = document.querySelector('#counter_total');
663+
if (totalCounterSpan) { totalCounterSpan.innerHTML = ''; }
650664

651-
// Clear all filter tags
652-
document.querySelectorAll('.filter-tag') && document.querySelectorAll('.filter-tag').forEach(filterTag => filterTag.remove() );
665+
const clearAllLink = document.getElementById('clear-all-filters');
666+
if(clearAllLink){ clearAllLink.style.display='none'; }
653667

654-
// Remove Clear All Button
655-
document.querySelector('.clear-filter-tags') && document.querySelector('.clear-filter-tags').remove();
668+
// Remove any legacy bottom Clear All links if present
669+
document.querySelectorAll('.clear-filter-tags').forEach(el => {
670+
if(el.id !== 'clear-all-filters') el.remove();
671+
});
656672
return;
657673
}
658674

0 commit comments

Comments
 (0)