-
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.
Merge pull request #763 from maykinmedia/feature/1711-hide-filters-wh…
…en-unused [#1711] [#1710] Make search filters conditional and add mobile toggle
- Loading branch information
Showing
11 changed files
with
252 additions
and
44 deletions.
There are no files selected for viewing
9 changes: 5 additions & 4 deletions
9
src/open_inwoner/components/templates/components/Filter/Filter.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,15 +1,16 @@ | ||
{% load i18n filter_tags icon_tags form_tags %} | ||
{% load i18n filter_tags icon_tags button_tags form_tags %} | ||
|
||
<div> | ||
<fieldset class="filter filter--open" aria-label="{% trans "Filter" %}"> | ||
<fieldset class="filter" aria-label="{% trans "Filter" %}"> | ||
{% button href="#" icon="expand_more" icon_position="after" extra_classes="filter__mobile filter--toggle" bordered=False text=field.label %} | ||
<legend class="filter__title"> | ||
{{ field.label }} | ||
<span class="filter__legend-label">{{ field.label }}</span> | ||
</legend> | ||
<div class="filter__list"> | ||
{% for option in field.field.choices %} | ||
{% choice_checkbox choice=option name=field.name data=field.data index=forloop.counter %} | ||
{% endfor %} | ||
</div> | ||
</fieldset> | ||
<hr class="divider divider--small"> | ||
<hr class="divider divider--tiny"> | ||
</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
40 changes: 40 additions & 0 deletions
40
src/open_inwoner/configurations/migrations/0052_siteconfiguration_search_filters.py
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,40 @@ | ||
# Generated by Django 3.2.20 on 2023-09-18 10:09 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("configurations", "0051_merge_20230907_1800"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="siteconfiguration", | ||
name="search_filter_categories", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Whether to show category-checkboxes in order to filter the search result.", | ||
verbose_name="Add category filter for search results", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="siteconfiguration", | ||
name="search_filter_organizations", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Whether to show organization-checkboxes in order to filter the search result.", | ||
verbose_name="Add organization filter for search results", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="siteconfiguration", | ||
name="search_filter_tags", | ||
field=models.BooleanField( | ||
default=True, | ||
help_text="Whether to show tag-checkboxes in order to filter the search result.", | ||
verbose_name="Add tag filter for search results", | ||
), | ||
), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export class FilterMobile { | ||
static selector = '.filter--toggle' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.node.addEventListener('click', this.toggleOpen.bind(this)) | ||
document.addEventListener('keydown', this.filterClosing.bind(this), false) | ||
} | ||
|
||
toggleOpen(event) { | ||
event.preventDefault() | ||
console.log('this is mobile') | ||
const filterParent = this.node.parentElement | ||
if (filterParent) { | ||
filterParent.classList.toggle('filter--open') | ||
} | ||
} | ||
|
||
filterClosing(event) { | ||
if (event.type === 'keydown' && event.key === 'Escape') { | ||
const filterParent = this.node.parentElement | ||
if (filterParent) { | ||
filterParent.classList.remove('filter--open') | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Controls the toggling of filter lists on mobile to view more | ||
*/ | ||
document | ||
.querySelectorAll(FilterMobile.selector) | ||
.forEach((filterToggle) => new FilterMobile(filterToggle)) |
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,28 @@ | ||
const radioButtons = document.querySelectorAll( | ||
'.feedback__options .button-radio__input' | ||
) | ||
|
||
;[...radioButtons].forEach((radioButton) => { | ||
radioButton.addEventListener('click', (event) => { | ||
const feedbackRemarks = document.querySelectorAll('.feedback__remark') | ||
;[...feedbackRemarks].forEach((feedbackRemark) => | ||
feedbackRemark.classList.add('feedback__remark--show') | ||
) | ||
}) | ||
}) | ||
|
||
let timerId = null | ||
|
||
const searchForm = document.getElementById('search-form') | ||
|
||
const filterButtons = document.querySelectorAll('.filter .checkbox__input') | ||
;[...filterButtons].forEach((checkbox) => { | ||
checkbox.addEventListener('change', (event) => { | ||
clearTimeout(timerId) | ||
|
||
// Set a new interval | ||
timerId = setTimeout(() => { | ||
searchForm.submit() | ||
}, 250) | ||
}) | ||
}) |
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,28 +1,2 @@ | ||
const radioButtons = document.querySelectorAll( | ||
'.feedback__options .button-radio__input' | ||
) | ||
|
||
;[...radioButtons].forEach((radioButton) => { | ||
radioButton.addEventListener('click', (event) => { | ||
const feedbackRemarks = document.querySelectorAll('.feedback__remark') | ||
;[...feedbackRemarks].forEach((feedbackRemark) => | ||
feedbackRemark.classList.add('feedback__remark--show') | ||
) | ||
}) | ||
}) | ||
|
||
let timerId = null | ||
|
||
const searchForm = document.getElementById('search-form') | ||
|
||
const filterButtons = document.querySelectorAll('.filter .checkbox__input') | ||
;[...filterButtons].forEach((checkbox) => { | ||
checkbox.addEventListener('change', (event) => { | ||
clearTimeout(timerId) | ||
|
||
// Set a new timeout | ||
timerId = setTimeout(() => { | ||
searchForm.submit() | ||
}, 250) | ||
}) | ||
}) | ||
import './filter-mobile' | ||
import './filter-options' |
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,27 +1,106 @@ | ||
.filter { | ||
border: 0 solid transparent; | ||
margin: 0; | ||
padding: 0; | ||
|
||
&--open { | ||
.filter__list { | ||
@media (min-width: 768px) { | ||
padding: 0 var(--spacing-large) var(--spacing-large) var(--spacing-large); | ||
} | ||
|
||
&__list { | ||
padding-top: 0; | ||
padding-bottom: var(--spacing-large); | ||
display: none; | ||
grid-template-columns: 1fr; | ||
gap: var(--spacing-large); | ||
|
||
@media (min-width: 768px) { | ||
display: grid; | ||
padding-top: var(--spacing-large); | ||
padding-bottom: 0; | ||
} | ||
|
||
.checkbox .checkbox__label { | ||
cursor: pointer; | ||
} | ||
} | ||
|
||
.button { | ||
color: var(--font-color-body); | ||
font-weight: bold; | ||
padding: 0; | ||
} | ||
|
||
&__title { | ||
color: var(--font-color-heading-4); | ||
font-family: var(--font-family-heading); | ||
font-size: var(--font-size-heading-4); | ||
font-weight: bold; | ||
letter-spacing: 0; | ||
line-height: 21px; | ||
cursor: pointer; | ||
display: flex; | ||
} | ||
|
||
&__list { | ||
padding-top: var(--spacing-large); | ||
display: none; | ||
grid-template-columns: 1fr; | ||
gap: var(--spacing-large); | ||
&__legend { | ||
&-label { | ||
display: none; | ||
@media (min-width: 768px) { | ||
display: inline; | ||
} | ||
} | ||
} | ||
|
||
.divider { | ||
background-color: yellow; | ||
border: red solid 5px !important; | ||
&--small { | ||
display: none; | ||
@media (min-width: 768px) { | ||
display: block; | ||
} | ||
} | ||
&--tiny { | ||
display: block; | ||
@media (min-width: 768px) { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
&__mobile { | ||
@media (min-width: 768px) { | ||
display: none; | ||
} | ||
} | ||
|
||
//toggling dropdows | ||
&.filter--open { | ||
.button { | ||
color: var(--color-secondary); | ||
padding: 0; | ||
} | ||
|
||
.button--textless [class*='icon'] { | ||
display: inline-block; | ||
right: var(--spacing-large); | ||
top: 0; | ||
transform: rotate(180deg); | ||
transition: all 0.3s; | ||
} | ||
|
||
.filter__list { | ||
display: grid; | ||
} | ||
} | ||
} | ||
|
||
.grid__filters { | ||
.h2 { | ||
border-bottom: 2px solid var(--color-gray-light); | ||
display: block; | ||
padding-bottom: var(--spacing-large); | ||
@media (min-width: 768px) { | ||
display: none; | ||
} | ||
} | ||
} |
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