Skip to content

Commit

Permalink
Merge pull request #3587 from WoodyLetsCode/search-scroll-top
Browse files Browse the repository at this point in the history
Scroll to first search result on search
  • Loading branch information
blazoncek authored Dec 21, 2023
2 parents 6c877b6 + 37b8072 commit abf7dd5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2772,8 +2772,10 @@ function search(field, listId = null) {
field.nextElementSibling.style.display = (field.value !== '') ? 'block' : 'none';
if (!listId) return;

const search = field.value !== '';

// clear filter if searching in fxlist
if (listId === 'fxlist' && field.value !== '') {
if (listId === 'fxlist' && search) {
gId("filters").querySelectorAll("input[type=checkbox]").forEach((e) => { e.checked = false; });
}

Expand Down Expand Up @@ -2807,6 +2809,12 @@ function search(field, listId = null) {
sortedListItems.forEach(item => {
gId(listId).append(item);
});

// scroll to first search result
const firstVisibleItem = sortedListItems.find(item => item.style.display !== 'none' && !item.classList.contains('sticky') && !item.classList.contains('selected'));
if (firstVisibleItem && search) {
firstVisibleItem.scrollIntoView({ behavior: "instant", block: "center" });
}
}

function clean(clearButton) {
Expand Down

0 comments on commit abf7dd5

Please sign in to comment.