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

💄 [#2888] Indicate active case-filters on mobile #1550

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions src/open_inwoner/js/components/FilterBar/filterbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ export class FilterBar {
this.filterButton = node.querySelector('#selectButton')
this.backdrop = document.getElementById('filterBarBackdrop')
this.closeButton = node.querySelector('.show-controls')
this.selectionFilterBar = document.getElementById('selectionFilterBar')

// Check if elements are found
if (!this.filterPopup) {
console.error('Filter popup button not found!')
return
}

if (!this.filterButton) {
console.error('Select button not found!')
// Break if critical elements are not found
if (!this.filterPopup || !this.filterButton || !this.selectionFilterBar) {
return
}

Expand All @@ -34,6 +29,14 @@ export class FilterBar {
this.closeFilterPopup.bind(this),
false
)

// Attach checkbox listeners and update state
this.attachCheckboxListeners()

// Ensure the correct state is applied on page load
setTimeout(() => {
this.updateFilterBarState()
}, 100)
}

toggleOpenFilterPopup(event) {
Expand All @@ -47,11 +50,11 @@ export class FilterBar {
this.node.classList.toggle('filter-bar--mobile')
const isExpanded =
this.filterPopup.getAttribute('aria-expanded') === 'true'
this.filterPopup.setAttribute('aria-expanded', !isExpanded)
this.filterPopup.setAttribute('aria-expanded', (!isExpanded).toString())
}, 5)
}

closeFilterPopupDirect(event) {
closeFilterPopupDirect() {
// Remove 'show' class from the backdrop to hide it
this.backdrop.classList.remove('show')

Expand All @@ -77,6 +80,35 @@ export class FilterBar {
this.filterPopup.setAttribute('aria-expanded', 'false')
}
}

updateFilterBarState() {
const checkboxes = this.node.querySelectorAll(
'#listboxDropdown .checkbox__input'
)
const anyChecked = Array.from(checkboxes).some(
(checkbox) => checkbox.checked
)

if (anyChecked) {
this.selectionFilterBar.classList.add('active')
this.selectionFilterBar.classList.remove('inactive')
} else {
this.selectionFilterBar.classList.remove('active')
this.selectionFilterBar.classList.add('inactive')
}
}

attachCheckboxListeners() {
const checkboxes = this.node.querySelectorAll(
'#listboxDropdown .checkbox__input'
)

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

// Reinitialize FilterBar after HTMX swap
Expand Down
39 changes: 39 additions & 0 deletions src/open_inwoner/scss/components/FilterBar/FilterBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

&__mobile-button {
.button.show-modal {
padding-right: var(--spacing-small);
margin-top: 0;

& [class*='icons'] {
Expand All @@ -72,6 +73,36 @@
}
}

&__mobile-selection {
display: flex;
align-items: center;
justify-content: left;
gap: 0;
color: var(--color-gray-dark);
& > [class*='icons'] {
display: none;
}
.button {
color: var(--color-gray-dark);
[class*='icons'] {
color: var(--color-gray-dark);
}
}

&.active {
color: var(--color-primary);
& > [class*='icons'] {
display: inline;
}
.button {
color: var(--color-primary);
[class*='icons'] {
color: var(--color-primary);
}
}
}
}

&__label {
display: none;
padding-top: calc(var(--font-size-body) / 2);
Expand Down Expand Up @@ -165,5 +196,13 @@
position: static;
z-index: initial;
}

.filter-bar__mobile-selection {
&.active {
& > [class*='icons'] {
display: none;
}
}
}
}
}
6 changes: 5 additions & 1 deletion src/open_inwoner/templates/pages/cases/list_inner.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ <h1 class="utrecht-heading-1" id="cases">{{ page_title }} ({{ paginator.count }}
</div>
<div class="filter-bar__mobile-button">
<p class="utrecht-paragraph filter-bar__heading">Filters</p>
{% button icon="filter_alt" text=_("Filters") icon_outlined=True transparent=True extra_classes="show-modal" %}
<div class="filter-bar__mobile-selection" id="selectionFilterBar">
{% button icon="filter_alt" text=_("Filters") icon_outlined=True transparent=True extra_classes="show-modal" %}
{% icon icon="check" icon_position="after" outlined=True %}
<span class="sr-only">Gekozen filters</span>
</div>
<p class="utrecht-paragraph filter-bar__status-text">Status</p>
</div>
<form class="form filter-bar__form" method="GET" id="filter-form" novalidate>
Expand Down
Loading