Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow typing in search box while dropdown is open #694

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/assets/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ searchClearBtn.addEventListener("click", function (e) {
searchClearBtn.setAttribute("hidden", "");
});

if (resultsElement) {
resultsElement.addEventListener("keydown", e => {
if (
e.key !== "ArrowUp" &&
e.key !== "ArrowDown" &&
e.key !== "Tab" &&
e.key !== "Shift"
) {
searchInput.focus();
searchInput.setSelectionRange(
searchInput.value.length,
searchInput.value.length,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite correct as it puts the focus at the end of the input. What we really want is to getSelectionRange() when the search input loses focus and then restore it here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. I will make the changes accordingly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
});
}

document.addEventListener("keydown", function (e) {
const searchResults = Array.from(
document.querySelectorAll(".search-results__item"),
Expand Down