From 847c3aaf363fe279bfcbce466c54140e7c20ad97 Mon Sep 17 00:00:00 2001 From: webfarben Date: Sun, 15 Mar 2026 20:15:34 +0100 Subject: [PATCH] UX: Seitenbaum-Filter behaelt Eltern bei Treffer in Unterknoten sichtbar --- contao/templates/be_dummy_copier.html5 | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/contao/templates/be_dummy_copier.html5 b/contao/templates/be_dummy_copier.html5 index d0211ff..597ac58 100644 --- a/contao/templates/be_dummy_copier.html5 +++ b/contao/templates/be_dummy_copier.html5 @@ -308,10 +308,34 @@ input.addEventListener('input', function () { var key = input.getAttribute('data-filter-for-tree'); var query = (input.value || '').toLowerCase(); + var items = Array.prototype.slice.call(document.querySelectorAll('[data-tree-item="' + key + '"]')); - document.querySelectorAll('[data-tree-item="' + key + '"]').forEach(function (item) { + if (query === '') { + items.forEach(function (item) { + item.hidden = false; + delete item.dataset.treeMatched; + }); + + return; + } + + items.reverse().forEach(function (item) { var label = item.getAttribute('data-tree-label') || ''; - item.hidden = query !== '' && label.indexOf(query) === -1; + var selfMatch = label.indexOf(query) !== -1; + var nested = item.querySelector(':scope > ul'); + var childMatch = false; + + if (nested) { + Array.prototype.forEach.call(nested.children, function (child) { + if (child.matches('[data-tree-item="' + key + '"]') && child.dataset.treeMatched === '1') { + childMatch = true; + } + }); + } + + var match = selfMatch || childMatch; + item.hidden = !match; + item.dataset.treeMatched = match ? '1' : '0'; }); }); });