Compare commits

...

2 Commits

Author SHA1 Message Date
Jürgen Mummert 1b477c24da Wrap event filter tag buttons in dedicated container 2026-02-22 12:11:46 +01:00
Jürgen Mummert 85b669d214 Improve event filter accessibility semantics and live status 2026-02-22 11:32:59 +01:00
@@ -1,12 +1,14 @@
<div id="eventfilters" data-eventlist-id="{{ targetEventListId|default('eventlist')|e('html_attr') }}"> <div id="eventfilters" data-eventlist-id="{{ targetEventListId|default('eventlist')|e('html_attr') }}">
<button type="button" data-filter-tag="all" class="active">Alle</button> <div class="tag-buttons">
<button type="button" data-filter-tag="all" class="active" aria-pressed="true">Alle</button>
{% for tag in tagButtons|default([]) %} {% for tag in tagButtons|default([]) %}
<button type="button" data-filter-tag="{{ tag.id }}">{{ tag.title }} ({{ tag.count }})</button> <button type="button" data-filter-tag="{{ tag.id }}" aria-pressed="false">{{ tag.title }} ({{ tag.count }})</button>
{% endfor %} {% endfor %}
</div>
<div class="widget-select places"> <div class="widget-select places">
<label for="location-filter">Orte:</label> <label for="location-filter" class="visually-hidden">Orte:</label>
<select id="location-filter"> <select id="location-filter">
<option value="all">Orte</option> <option value="all">Orte</option>
{% for location in locations|default([]) %} {% for location in locations|default([]) %}
@@ -16,7 +18,7 @@
</div> </div>
<div class="widget-select org"> <div class="widget-select org">
<label for="org-filter">Veranstalter:</label> <label for="org-filter" class="visually-hidden">Veranstalter:</label>
<select id="org-filter"> <select id="org-filter">
<option value="all">Veranstalter</option> <option value="all">Veranstalter</option>
{% for organization in organizations|default([]) %} {% for organization in organizations|default([]) %}
@@ -24,9 +26,23 @@
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
<p id="eventfilter-status" class="visually-hidden" aria-live="polite"></p>
</div> </div>
<style> <style>
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
.event-filter-target-list { .event-filter-target-list {
display: grid; display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
@@ -51,6 +67,12 @@
outline: 2px solid currentColor; outline: 2px solid currentColor;
outline-offset: 2px; outline-offset: 2px;
} }
#eventfilters button:focus-visible,
#eventfilters select:focus-visible {
outline: 2px solid currentColor;
outline-offset: 2px;
}
</style> </style>
<script type="module"> <script type="module">
@@ -73,6 +95,7 @@
const tagButtons = Array.from(filters.querySelectorAll('button[data-filter-tag]')); const tagButtons = Array.from(filters.querySelectorAll('button[data-filter-tag]'));
const locationSelect = filters.querySelector('#location-filter'); const locationSelect = filters.querySelector('#location-filter');
const orgSelect = filters.querySelector('#org-filter'); const orgSelect = filters.querySelector('#org-filter');
const status = filters.querySelector('#eventfilter-status');
const animationMs = 220; const animationMs = 220;
let hideTimers = new WeakMap(); let hideTimers = new WeakMap();
@@ -110,7 +133,9 @@
const setActiveControl = ({ type, value }) => { const setActiveControl = ({ type, value }) => {
tagButtons.forEach((button) => { tagButtons.forEach((button) => {
button.classList.toggle('active', type === 'tag' && button.dataset.filterTag === value); const isActive = type === 'tag' && button.dataset.filterTag === value;
button.classList.toggle('active', isActive);
button.setAttribute('aria-pressed', isActive ? 'true' : 'false');
}); });
if (locationSelect) { if (locationSelect) {
@@ -147,6 +172,32 @@
return true; return true;
}; };
const updateStatus = (filterState) => {
if (!status) {
return;
}
const visibleCount = events.filter((eventItem) => !eventItem.hidden).length;
let filterText = 'alle';
if (filterState.type === 'tag' && filterState.value !== 'all') {
const activeButton = tagButtons.find((button) => button.dataset.filterTag === filterState.value);
filterText = activeButton ? activeButton.textContent.trim() : `Tag ${filterState.value}`;
}
if (filterState.type === 'location' && locationSelect) {
const option = locationSelect.options[locationSelect.selectedIndex];
filterText = option ? option.textContent.trim() : 'Ort';
}
if (filterState.type === 'org' && orgSelect) {
const option = orgSelect.options[orgSelect.selectedIndex];
filterText = option ? option.textContent.trim() : 'Veranstalter';
}
status.textContent = `${visibleCount} Veranstaltungen angezeigt, Filter: ${filterText}.`;
};
const applyFilter = (filterState) => { const applyFilter = (filterState) => {
currentFilter = filterState; currentFilter = filterState;
setActiveControl(filterState); setActiveControl(filterState);
@@ -158,6 +209,8 @@
hideEvent(eventItem); hideEvent(eventItem);
} }
}); });
updateStatus(filterState);
}; };
tagButtons.forEach((button) => { tagButtons.forEach((button) => {