-
Notifications
You must be signed in to change notification settings - Fork 6
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
💄 [#2741] Add multiselect listbox mobile design #1398
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to distinguish the two events and have two separate handlers:
closeFilterPopupByEscape
andcloseFilterPopupByOutsideClick
. That way, you can (a) avoid the disjunction in your handler and (b) simplify the logic. For example, incloseFilterPopupByEscape
you can checkif event.key != 'Escape': return;
and then do the removal afterwards outside the conditional (following the never-nester approach). However, I'm not too familiar with the coding conventions in JS land, so leaving it to you.