-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
💄 [#2741] Added multiselect listbox mobile structure
- Loading branch information
1 parent
16de4dc
commit 90b41e6
Showing
14 changed files
with
481 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 31 additions & 9 deletions
40
src/open_inwoner/components/templates/components/FilterBar/FilterBar.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,33 @@ | ||
{% load i18n form_tags %} | ||
{% load i18n form_tags button_tags %} | ||
|
||
{# Wrapper for multiple filters #} | ||
<div class="filter-bar" id="filterBar"> | ||
<form class="form" method="{{ method }}" | ||
{% if no_action %}action=""{% else %}action="{% firstof form_action request.path %}"{% endif %} | ||
{% if id %}id="{{ id }}"{% endif %}> | ||
{# Note: each element inside the form is a flex column #} | ||
{{ contents }} | ||
</form> | ||
<div class="filter-bar__backdrop" id="filterBarBackdrop"> | ||
{# Wrapper for multiple filters #} | ||
<div class="filter-bar" id="filterBar"> | ||
<div class="filter-bar__mobile-controls"> | ||
{% button icon="close" text=_("Sluiten") hide_text=True icon_outlined=True transparent=True extra_classes="show-controls" %} | ||
<div class="form__reset--mobile form__actions--fullwidth form__actions--reset"> | ||
<button class="button button--primary button--transparent" 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">Filters</p> | ||
{% button icon="filter_alt" text=_("Filters") icon_outlined=True transparent=True extra_classes="show-modal" %} | ||
<p class="utrecht-paragraph filter-bar__status-text">Status</p> | ||
</div> | ||
<form class="form filter-bar__form" method="{{ method }}" | ||
{% if no_action %}action="" {% else %}action="{% firstof form_action request.path %}" {% endif %} | ||
{% if id %}id="{{ id }}" {% endif %}> | ||
{# Note: each element inside the form is a flex column #} | ||
{{ contents }} | ||
|
||
{# Mobile submit button updates on select #} | ||
<div class="form__reload--mobile form__actions form__actions--fullwidth" id="filterFormActions"> | ||
<button class="button button--primary" type="submit" title="{% trans 'Toon resultaten' %}" aria-label="{% trans 'Toon resultaten' %}" id="filterCases"> | ||
{% trans 'Toon' %}<span class="filter-bar__frequency-sum" id="frequencySum">0</span><span id="resultText">{% trans 'resultaten' %}</span> | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
46 changes: 24 additions & 22 deletions
46
src/open_inwoner/components/templates/components/FilterBar/MultiSelectListbox.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
{% load i18n l10n form_tags icon_tags button_tags %} | ||
|
||
<div class="filter-bar__multiselect-listbox multiselect-listbox" id="selectDropdownWrapper"> | ||
<button id="selectButton" type="button" class="button button__select" aria-haspopup="listbox" aria-expanded="false" aria-live="polite"> | ||
{% trans 'Status' %}: | ||
{% 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 status, frequency in statusfrequencies %} | ||
<div class="checkbox" role="option"> | ||
<input type="checkbox" name="status" value="{{ status }}" id="id_status_{{ forloop.counter }}" class="checkbox__input"> | ||
<label class="checkbox__label" for="id_status_{{ forloop.counter }}"> | ||
<span class="ellipsis">{{ status }} </span><span class="frequency-counter">({{ frequency }})</span> | ||
</label> | ||
</div> | ||
{% endfor %} | ||
<div class="multiselect-listbox__popup"> | ||
<button id="selectButton" type="button" class="button button__select" aria-haspopup="listbox" aria-expanded="false" aria-live="polite"> | ||
{% trans 'Status' %}: | ||
{% 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 status, frequency in statusfrequencies %} | ||
<div class="checkbox" role="option"> | ||
<input type="checkbox" name="status" value="{{ status }}" id="id_status_{{ forloop.counter }}" class="checkbox__input"> | ||
<label class="checkbox__label" for="id_status_{{ forloop.counter }}"> | ||
<span class="ellipsis">{{ status }} </span><span class="frequency-counter">({{ frequency }})</span> | ||
</label> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{# Submit button updates on select #} | ||
<div class="form__actions form__actions--fullwidth" id="multiselectFormActions"> | ||
<button class="button button--primary" type="submit" title="{% trans 'Toon resultaten' %}" aria-label="{% trans 'Toon resultaten' %}" id="filterCases"> | ||
{% trans 'Toon' %}<span class="filter-bar__frequency-sum" id="frequencySum">0</span><span id="resultText">{% trans 'resultaten' %}</span> | ||
</button> | ||
</div> | ||
</div> | ||
{# Submit button appears on select #} | ||
<div class="form__actions form__actions--fullwidth" id="filterFormActions"> | ||
<button class="button button--primary" type="submit" title="{% trans 'Toon resultaten' %}" aria-label="{% trans 'Toon resultaten' %}" id="filterCases"> | ||
{% trans 'Toon' %}<span class="filter-bar__frequency-sum" id="frequencySum">0</span><span id="resultText">{% trans 'resultaten' %}</span> | ||
</button> | ||
<div class="form__reset--desktop form__actions--fullwidth form__actions--reset"> | ||
{% button bordered=False text=_("Wis alle filters") id="resetMultiSelectFilters" type="button" transparent=True primary=True %} | ||
</div> | ||
</div> | ||
<div class="form__actions form__actions--fullwidth form__actions--reset"> | ||
{% button bordered=False text=_("Wis alle filters") id="resetFilters" type="button" transparent=True primary=True %} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
export class FilterBar { | ||
static selector = '.filter-bar' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.filterPopup = node.querySelector('.show-modal') | ||
this.filterButton = node.querySelector('#selectButton') | ||
this.backdrop = document.getElementById('filterBarBackdrop') | ||
this.closeButton = node.querySelector('.show-controls') | ||
|
||
// 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!') | ||
return | ||
} | ||
|
||
// Event listeners | ||
this.filterPopup.addEventListener( | ||
'click', | ||
this.toggleOpenFilterPopup.bind(this) | ||
) | ||
this.closeButton.addEventListener( | ||
'click', | ||
this.closeFilterPopupDirect.bind(this) // Added a specific handler for direct close button click | ||
) | ||
document.addEventListener('click', this.closeFilterPopup.bind(this), false) | ||
document.addEventListener( | ||
'keydown', | ||
this.closeFilterPopup.bind(this), | ||
false | ||
) | ||
} | ||
|
||
toggleOpenFilterPopup(event) { | ||
event.preventDefault() | ||
|
||
// Add 'show' class to the backdrop to make it visible | ||
this.backdrop.classList.add('show') | ||
|
||
// Toggle mobile filter class | ||
setTimeout(() => { | ||
this.node.classList.toggle('filter-bar--mobile') | ||
const isExpanded = | ||
this.filterPopup.getAttribute('aria-expanded') === 'true' | ||
this.filterPopup.setAttribute('aria-expanded', !isExpanded) | ||
}, 5) | ||
} | ||
|
||
closeFilterPopupDirect(event) { | ||
// Remove 'show' class from the backdrop to hide it | ||
this.backdrop.classList.remove('show') | ||
|
||
// Remove mobile class and reset aria-expanded | ||
this.node.classList.remove('filter-bar--mobile') | ||
this.filterPopup.setAttribute('aria-expanded', 'false') | ||
} | ||
|
||
closeFilterPopup(event) { | ||
// Close on clicking outside or pressing Escape | ||
if ( | ||
(event.type === 'keydown' && event.key === 'Escape') || | ||
(event.type === 'click' && | ||
!this.node.contains(event.target) && | ||
!this.filterPopup.contains(event.target) && | ||
!this.backdrop.contains(event.target)) | ||
) { | ||
// Remove 'show' class from the backdrop to hide it | ||
this.backdrop.classList.remove('show') | ||
|
||
// Remove mobile class and reset aria-expanded | ||
this.node.classList.remove('filter-bar--mobile') | ||
this.filterPopup.setAttribute('aria-expanded', 'false') | ||
} | ||
} | ||
} | ||
|
||
// Reinitialize FilterBar after HTMX swap | ||
htmx.on('htmx:afterSwap', function (e) { | ||
if (e.detail && e.detail.target.id === 'cases-content') { | ||
const filterBars = document.querySelectorAll(FilterBar.selector) | ||
if (filterBars.length === 0) { | ||
console.error('No filter bars found on the page after swap.') | ||
} else { | ||
filterBars.forEach((filterbar) => new FilterBar(filterbar)) | ||
} | ||
} | ||
}) | ||
|
||
// Initialize FilterBar on DOM load for the initial page load | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const filterBars = document.querySelectorAll(FilterBar.selector) | ||
if (filterBars.length === 0) { | ||
console.error('No filter bars found on the page.') | ||
} else { | ||
filterBars.forEach((filterbar) => new FilterBar(filterbar)) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './filterbar' | ||
import './multiselect_listbox_checkbox' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.cases { | ||
position: relative; | ||
|
||
/// cards on cases list | ||
.card { | ||
&__body { | ||
|
Oops, something went wrong.