feat: ora i menu a tendina sono freccettabili. fix: sistemata la modifica massiva nella pagina ricerca spudorata

This commit is contained in:
Gabriele Cimaschi committed 2026-08-31 16:03:05 +02:00
1 parent 8a617ecb22
commit b828d60bb2
6 files changed
+135 -14

No files matched your search

+61
View File
@@ -1080,6 +1080,67 @@ const App = {
});
});
},
/**
* Helper to enable arrow keys (Up/Down), Enter, and Escape navigation on autocomplete inputs.
* @param {HTMLInputElement} inputEl
* @param {HTMLElement} suggestionsEl
* @param {Function} onSelect Callback(itemElement) when an item is selected via Enter or Click
*/
setupAutocompleteKeyboardNavigation(inputEl, suggestionsEl, onSelect) {
if (!inputEl || !suggestionsEl) return;
inputEl.addEventListener('keydown', (e) => {
if (suggestionsEl.style.display === 'none' || !suggestionsEl.children.length) {
return;
}
const items = Array.from(suggestionsEl.querySelectorAll('.autocomplete-suggestion-item[data-id]'));
if (items.length === 0) return;
let currentIndex = items.findIndex(item => item.classList.contains('selected'));
if (e.key === 'ArrowDown') {
e.preventDefault();
if (currentIndex < items.length - 1) {
currentIndex++;
} else {
currentIndex = 0;
}
items.forEach((item, idx) => {
if (idx === currentIndex) {
item.classList.add('selected');
item.scrollIntoView({ block: 'nearest' });
} else {
item.classList.remove('selected');
}
});
} else if (e.key === 'ArrowUp') {
e.preventDefault();
if (currentIndex > 0) {
currentIndex--;
} else {
currentIndex = items.length - 1;
}
items.forEach((item, idx) => {
if (idx === currentIndex) {
item.classList.add('selected');
item.scrollIntoView({ block: 'nearest' });
} else {
item.classList.remove('selected');
}
});
} else if (e.key === 'Enter') {
if (currentIndex >= 0 && items[currentIndex]) {
e.preventDefault();
e.stopPropagation();
onSelect(items[currentIndex]);
}
} else if (e.key === 'Escape') {
suggestionsEl.style.display = 'none';
}
});
},
};
// Start the app when DOM is ready