Skip to content

Commit

Permalink
feat: limited custom upload dropdown height and enabled scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
jstucke committed Dec 10, 2024
1 parent d42c5be commit 78d9363
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/web_interface/static/css/upload.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
left: 135px; /* upload-label width */
right: 35px; /* dropdown button width */
font-family: monospace;
max-height: 40vh;
overflow-x: hidden;
overflow-y: auto;
scroll-behavior: smooth;
}
.autocomplete-items li {
cursor: pointer;
Expand Down
23 changes: 18 additions & 5 deletions src/web_interface/static/js/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ function autocompleteInput(inputId, options) {
let currentFocus;

input.addEventListener("input", populateAutocomplete);
dropdownButton.addEventListener("click", () => {
input.value = "";
populateAutocomplete();
dropdownButton.addEventListener("click", (event) => {
let autoComplete = getAutocompleteElement(event.target.parentNode.parentNode);
if (autoComplete) {
// clicked on a dropdown button but a menu already exists => close the menu
closeAll();
} else {
input.value = "";
populateAutocomplete();
}
});

input.addEventListener("keydown", (event) => {
Expand Down Expand Up @@ -87,7 +93,7 @@ function autocompleteInput(inputId, options) {
list.setAttribute("class", "autocomplete-items list-group border");
input.parentNode.appendChild(list);

let listItem, target;
let listItem;
options.forEach(option => {
let index = option.toLowerCase().indexOf(input.value.toLowerCase());
if (!input.value || index !== -1) {
Expand Down Expand Up @@ -124,7 +130,14 @@ function autocompleteInput(inputId, options) {
} else if (currentFocus < 0) {
currentFocus = (elements.length - 1);
}
elements[currentFocus].classList.add("active");
const selectedElement = elements[currentFocus];
if (selectedElement) {
selectedElement.classList.add("active");
// scroll to the element above the selected one
selectedElement.parentNode.scroll(
0, Math.max(0, selectedElement.offsetTop - selectedElement.clientHeight)
);
}
}
}

Expand Down

0 comments on commit 78d9363

Please sign in to comment.