Skip to content

Commit abf7dd5

Browse files
authored
Merge pull request #3587 from WoodyLetsCode/search-scroll-top
Scroll to first search result on search
2 parents 6c877b6 + 37b8072 commit abf7dd5

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

wled00/data/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2772,8 +2772,10 @@ function search(field, listId = null) {
27722772
field.nextElementSibling.style.display = (field.value !== '') ? 'block' : 'none';
27732773
if (!listId) return;
27742774

2775+
const search = field.value !== '';
2776+
27752777
// clear filter if searching in fxlist
2776-
if (listId === 'fxlist' && field.value !== '') {
2778+
if (listId === 'fxlist' && search) {
27772779
gId("filters").querySelectorAll("input[type=checkbox]").forEach((e) => { e.checked = false; });
27782780
}
27792781

@@ -2807,6 +2809,12 @@ function search(field, listId = null) {
28072809
sortedListItems.forEach(item => {
28082810
gId(listId).append(item);
28092811
});
2812+
2813+
// scroll to first search result
2814+
const firstVisibleItem = sortedListItems.find(item => item.style.display !== 'none' && !item.classList.contains('sticky') && !item.classList.contains('selected'));
2815+
if (firstVisibleItem && search) {
2816+
firstVisibleItem.scrollIntoView({ behavior: "instant", block: "center" });
2817+
}
28102818
}
28112819

28122820
function clean(clearButton) {

0 commit comments

Comments
 (0)