Skip to content

Commit

Permalink
🚧 [#3018] Refactor filters out of modal into checkbox-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jiromaykin committed Feb 25, 2025
1 parent eaf6816 commit 563dbdf
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% load i18n icon_tags button_tags form_tags %}

<div>
<fieldset class="filter" aria-label="Filter">
<a class="button filter__mobile filter--toggle button--textless button--icon button--icon-after" href="#" title="Onderwerpen" aria-label="Onderwerpen">
<span aria-hidden="true" class="material-icons ">expand_more</span>
{{ field.label }}
</a>
<legend class="filter__title">
<span class="filter__legend-label">{{ field.label }}</span>
</legend>
<div class="filter__list">

<div class="filter-bar__multiselect-listbox multiselect-listbox">
<div class="multiselect-listbox__popup">
<button id="selectButton" type="button" class="button button__select selectButton" aria-haspopup="listbox" aria-expanded="false" aria-live="polite">
<span class="filter__legend-label">{{ field.label }}</span>:
{% icon icon="expand_more" icon_position="after" icon_outlined=True %}
</button>
<div id="listboxDropdown" class="multiselect-listbox__content" role="listbox" aria-labelledby="selectButton">
<div class="multiselect-listbox__scroll" role="presentation">
{% for option in field.field.choices %}
{% choice_checkbox choice=option name=field.name data=field.data index=forloop.counter form_id=form_id %}
{% endfor %}
</div>
{# No submit button for direct query #}
</div>
<div class="form__reset--desktop form__actions--fullwidth form__actions--reset">
{% button bordered=False text=_("Wis alle filters") id="resetMultiSelectFilters" extra_classes="resetMultiSelectFilters" type="button" transparent=True primary=True %}
</div>
</div>
</div>

</div>
</fieldset>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,8 @@ document.body.addEventListener('htmx:afterSwap', function () {
document.addEventListener('click', function (e) {
if (e.target && e.target.classList.contains('pagination__link')) {
scrollToTopOfWindow() // Scroll up after clicking pagination
setTimeout(function () {
initFilterBar() // Reinitialize filter bar after HTMX swap from pagination
}, 20)
}
})
31 changes: 31 additions & 0 deletions src/open_inwoner/js/components/search/filter-dropdown-submit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export class FilterDropdownSubmit {
static selector = '.filter-dropdown'

constructor(node) {
this.node = node
this.submitButton = node.querySelector('.filter-dropdown__submit')
this.checkboxes = node.querySelectorAll(
'.filter-dropdown__list input[type="checkbox"]'
)

if (!this.submitButton || !this.checkboxes.length) return

this.checkboxes.forEach((checkbox) => {
checkbox.addEventListener('change', this.updateSubmitButton.bind(this))
})
}

updateSubmitButton() {
const selectedCount = this.node.querySelectorAll(
'.filter-dropdown__list input[type="checkbox"]:checked'
).length
this.submitButton.textContent = `Apply Filters (${selectedCount})`
}
}

/**
* Initialize only dropdowns with submit buttons
*/
document
.querySelectorAll(FilterDropdownSubmit.selector)
.forEach((dropdown) => new FilterDropdownSubmit(dropdown))
59 changes: 59 additions & 0 deletions src/open_inwoner/js/components/search/filter-dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export class FilterDropdown {
static selector = '.filter-dropdown'

constructor(node) {
this.node = node
this.button = node.querySelector('.filter-dropdown__button')
this.menu = node.querySelector('.filter-dropdown__menu')
this.checkboxes = node.querySelectorAll(
'.filter-dropdown__list input[type="checkbox"]'
)
this.clearButton = node.querySelector('.filter-dropdown__clear')
this.filterCount = node.querySelector('.filter-count')

if (!this.button || !this.menu || !this.checkboxes.length) return

this.button.addEventListener('click', this.toggleDropdown.bind(this))
document.addEventListener('click', this.closeDropdown.bind(this))

this.checkboxes.forEach((checkbox) => {
checkbox.addEventListener('change', this.updateFilters.bind(this))
})

if (this.clearButton) {
this.clearButton.addEventListener('click', this.clearFilters.bind(this))
}
}

toggleDropdown(event) {
event.preventDefault()
this.node.classList.toggle('open')
}

closeDropdown(event) {
if (!this.node.contains(event.target)) {
this.node.classList.remove('open')
}
}

updateFilters() {
const selectedCount = this.node.querySelectorAll(
'.filter-dropdown__list input[type="checkbox"]:checked'
).length
if (this.filterCount) {
this.filterCount.textContent = `(${selectedCount})`
}
}

clearFilters() {
this.checkboxes.forEach((checkbox) => (checkbox.checked = false))
this.updateFilters()
}
}

/**
* Initialize all dropdowns
*/
document
.querySelectorAll(FilterDropdown.selector)
.forEach((dropdown) => new FilterDropdown(dropdown))
2 changes: 1 addition & 1 deletion src/open_inwoner/js/components/search/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import './filter-mobile'
import './filter-dropdown'
import './filter-options'

const searchForm = document.getElementById('search-form')
Expand Down
8 changes: 8 additions & 0 deletions src/open_inwoner/scss/components/Filter/Filter.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
.filter {
display: none;
@media (min-width: 768px) {
display: block;
}
border: 0 solid transparent;
margin: 0;
padding: 0;
Expand Down Expand Up @@ -94,6 +98,10 @@
}

.grid__filters {
display: none;
@media (min-width: 768px) {
display: block;
}
.utrecht-heading-2 {
border-bottom: 2px solid var(--color-gray-light);
display: block;
Expand Down
65 changes: 65 additions & 0 deletions src/open_inwoner/scss/components/Filter/FilterDropdown.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
.filter-dropdown {
position: relative;
display: inline-block;

&__button {
background: var(--color-white);
color: var(--color-body);
border: 1px solid var(--color-gray-dark-900);
border-radius: var(--border-radius);
padding: 10px 15px;
cursor: pointer;
border-radius: 5px;
}

&__menu {
position: absolute;
top: 100%;
left: 0;
background: white;
border: 1px solid #ccc;
border-radius: 5px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
display: none;
padding: 10px;
width: 200px;
z-index: 100;
}

&__list {
list-style: none;
padding: 0;
margin: 0;

li {
margin-bottom: 5px;
}
}

&__actions {
display: flex;
justify-content: space-between;
margin-top: 10px;
}

&__submit {
background: var(--color-primary);
color: white;
border: none;
padding: 5px 10px;
cursor: pointer;
border-radius: 3px;
}

&__clear {
background: none;
border: none;
color: var(--color-primary);
cursor: pointer;
}
}

// Show dropdown when button is clicked
.filter-dropdown.open .filter-dropdown__menu {
display: block;
}
1 change: 1 addition & 0 deletions src/open_inwoner/scss/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@import './File/File.scss';
@import './File/FileList.scss';
@import './Filter/Filter.scss';
@import 'Filter/FilterDropdown';
@import './FilterBar/FilterBar.scss';
@import './FilterBar/MultiSelectListbox';
@import './Footer/Footer.scss';
Expand Down
50 changes: 50 additions & 0 deletions src/open_inwoner/templates/pages/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,56 @@ <h2 class="utrecht-heading-2">{% trans "Zoekfilters" %}</h2>
{% include "components/Filter/Filter.html" with field=search_form.organizations form_id="search-form" only %}
{% endif %}
</aside>

<div class="filter-bar__backdrop">
<div class="filter-bar">
<div class="filter-bar__mobile-controls">
<button class="button show-controls button--textless button--icon button--transparent" type="" name="" value="" title="Sluiten" aria-label="Sluiten">
<span aria-hidden="true" class="material-icons-outlined ">close</span>
</button>
<div class="form__reset--mobile form__actions--fullwidth form__actions--reset">
<button class="button button--primary button--transparent resetAllFilters" type="button" name="" value="" title="Wis alle filters" aria-label="Wis alle filters" id="resetAllFilters">
Wis alle filters
</button>
</div>
</div>
<div class="filter-bar__mobile-button">
<p class="utrecht-paragraph filter-bar__heading">{% trans "Zoekfilters" %}</p>
<div class="filter-bar__mobile-selection inactive" >
<button class="button show-modal button--textless button--icon button--transparent" title="Filters" aria-label="Filters" aria-expanded="false">
<span aria-hidden="true" class="material-icons-outlined ">filter_alt</span>
<span class="button__inner-text">Filters</span>
</button>
<span aria-hidden="true" class="material-icons-outlined ">check</span>
<span class="sr-only">Gekozen filters</span>
</div>
<p class="utrecht-paragraph filter-bar__status-text">{% trans "Zoekfilters" %}</p>
<aside class="grid__sidebar grid__filters--mobile" aria-label="{% trans "Zoekfilters" %}">
<div class="filter-dropdown">
<button type="button" class="button button__select filter-dropdown__button" aria-haspopup="listbox" aria-expanded="false" aria-live="polite">Onderwerpen <span class="filter-count">(0)</span> <span class="material-icons" aria-hidden="true">expand_more</span></button>

<div class="filter-dropdown__menu">
<ul class="filter-dropdown__list">
<li><label><input type="checkbox" value="option1"> Option 1</label></li>
<input type="checkbox" name="status" value="Lopende aanvragen" id="id_status_2" class="checkbox__input">
<li><label class="checkbox__label" for="id_status_2">
<span class="ellipsis">Lopende aanvragen </span><span class="frequency-counter">(5)</span>
</label></li>
<li><label><input type="checkbox" value="option3"> Option 3</label></li>
</ul>

<div class="filter-dropdown__actions">
<button class="filter-dropdown__submit">Apply Filters (0)</button>
<button class="filter-dropdown__clear">Clear All</button>
</div>
</div>
</div>


</aside>
</div>
</div>
</div>
{% endif %}
{# end search filters #}
{% endif %}
Expand Down

0 comments on commit 563dbdf

Please sign in to comment.