Skip to content

Commit

Permalink
feat: disable arrow navigation when result is 1
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthyadms committed Nov 21, 2023
1 parent f355d58 commit fe46205
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/search-menu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export default {
methods: {
arrowNavigation() {
window.addEventListener("keydown", (event) => {
if (this.newResults.length <= 1) return;
const isArrow = ["ArrowDown", "ArrowUp"].includes(event.code);
if (document.getElementById("search-item-0")) {
const firstSearchItem =
document.getElementById("search-item-0").firstChild;
if (firstSearchItem.classList.contains("menu-focus"))
if (firstSearchItem.classList.contains("menu-focus") && isArrow)
firstSearchItem.classList.remove("menu-focus");
}
if (event.code === "ArrowDown") {
Expand All @@ -72,7 +74,8 @@ export default {
} else if (event.code === "ArrowUp") {
event.preventDefault();
this.selected =
(this.selected - 1 + this.maxResults) % this.newResults.length;
(this.selected - 1 + this.newResults.length) %
this.newResults.length;
document
.getElementById(`search-item-${this.selected}`)
.firstChild.focus();
Expand Down

0 comments on commit fe46205

Please sign in to comment.