Format hook
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
mounted() {
|
mounted() {
|
||||||
this.selectedIndex = -1; // -1 means search input is focused
|
this.selectedIndex = -1; // -1 means search input is focused
|
||||||
|
|
||||||
this.keydownHandler = (event) => {
|
this.keydownHandler = (event) => {
|
||||||
// Only handle keyboard navigation when the modal is open
|
// Only handle keyboard navigation when the modal is open
|
||||||
const modal = document.getElementById("universal-search-root");
|
const modal = document.getElementById("universal-search-root");
|
||||||
@@ -45,7 +45,7 @@ export default {
|
|||||||
|
|
||||||
navigateDown() {
|
navigateDown() {
|
||||||
const results = this.getResultElements();
|
const results = this.getResultElements();
|
||||||
|
|
||||||
if (results.length === 0) return;
|
if (results.length === 0) return;
|
||||||
|
|
||||||
// Move to next result or wrap to search input
|
// Move to next result or wrap to search input
|
||||||
@@ -55,13 +55,13 @@ export default {
|
|||||||
// Wrap back to search input
|
// Wrap back to search input
|
||||||
this.selectedIndex = -1;
|
this.selectedIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSelection();
|
this.updateSelection();
|
||||||
},
|
},
|
||||||
|
|
||||||
navigateUp() {
|
navigateUp() {
|
||||||
const results = this.getResultElements();
|
const results = this.getResultElements();
|
||||||
|
|
||||||
if (results.length === 0) return;
|
if (results.length === 0) return;
|
||||||
|
|
||||||
// Move to previous result or wrap to last result
|
// Move to previous result or wrap to last result
|
||||||
@@ -71,13 +71,13 @@ export default {
|
|||||||
// Wrap to last result
|
// Wrap to last result
|
||||||
this.selectedIndex = results.length - 1;
|
this.selectedIndex = results.length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSelection();
|
this.updateSelection();
|
||||||
},
|
},
|
||||||
|
|
||||||
selectCurrentResult() {
|
selectCurrentResult() {
|
||||||
const results = this.getResultElements();
|
const results = this.getResultElements();
|
||||||
|
|
||||||
if (this.selectedIndex >= 0 && this.selectedIndex < results.length) {
|
if (this.selectedIndex >= 0 && this.selectedIndex < results.length) {
|
||||||
const selectedResult = results[this.selectedIndex];
|
const selectedResult = results[this.selectedIndex];
|
||||||
// Trigger the click event on the result
|
// Trigger the click event on the result
|
||||||
@@ -87,7 +87,7 @@ export default {
|
|||||||
|
|
||||||
updateSelection() {
|
updateSelection() {
|
||||||
const results = this.getResultElements();
|
const results = this.getResultElements();
|
||||||
|
|
||||||
// Remove all aria-selected attributes
|
// Remove all aria-selected attributes
|
||||||
results.forEach((result) => {
|
results.forEach((result) => {
|
||||||
result.removeAttribute("aria-selected");
|
result.removeAttribute("aria-selected");
|
||||||
@@ -103,7 +103,7 @@ export default {
|
|||||||
// Mark selected result
|
// Mark selected result
|
||||||
const selectedResult = results[this.selectedIndex];
|
const selectedResult = results[this.selectedIndex];
|
||||||
selectedResult.setAttribute("aria-selected", "true");
|
selectedResult.setAttribute("aria-selected", "true");
|
||||||
|
|
||||||
// Scroll into view if needed
|
// Scroll into view if needed
|
||||||
selectedResult.scrollIntoView({
|
selectedResult.scrollIntoView({
|
||||||
block: "nearest",
|
block: "nearest",
|
||||||
@@ -116,7 +116,7 @@ export default {
|
|||||||
// Get all result items with role="option"
|
// Get all result items with role="option"
|
||||||
const modal = document.getElementById("universal-search-root");
|
const modal = document.getElementById("universal-search-root");
|
||||||
if (!modal) return [];
|
if (!modal) return [];
|
||||||
|
|
||||||
return Array.from(modal.querySelectorAll('[role="option"]'));
|
return Array.from(modal.querySelectorAll('[role="option"]'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user