fix: search-panel when ArrowUp and ArrowDown (#7922)
parent
d71c81e8ff
commit
7ec4df4995
|
|
@ -11,7 +11,12 @@ import { mapTree, traverseTreeValues, uniqueByField } from '@vben/utils';
|
||||||
import { VbenIcon, VbenScrollbar } from '@vben-core/shadcn-ui';
|
import { VbenIcon, VbenScrollbar } from '@vben-core/shadcn-ui';
|
||||||
import { isHttpUrl } from '@vben-core/shared/utils';
|
import { isHttpUrl } from '@vben-core/shared/utils';
|
||||||
|
|
||||||
import { onKeyStroke, useLocalStorage, useThrottleFn } from '@vueuse/core';
|
import {
|
||||||
|
onKeyStroke,
|
||||||
|
useEventListener,
|
||||||
|
useLocalStorage,
|
||||||
|
useThrottleFn,
|
||||||
|
} from '@vueuse/core';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'SearchPanel',
|
name: 'SearchPanel',
|
||||||
|
|
@ -34,6 +39,7 @@ const searchHistory = useLocalStorage<MenuRecordRaw[]>(
|
||||||
const activeIndex = ref(-1);
|
const activeIndex = ref(-1);
|
||||||
const searchItems = shallowRef<MenuRecordRaw[]>([]);
|
const searchItems = shallowRef<MenuRecordRaw[]>([]);
|
||||||
const searchResults = ref<MenuRecordRaw[]>([]);
|
const searchResults = ref<MenuRecordRaw[]>([]);
|
||||||
|
const isNavigating = ref(false);
|
||||||
|
|
||||||
const handleSearch = useThrottleFn(search, 200);
|
const handleSearch = useThrottleFn(search, 200);
|
||||||
|
|
||||||
|
|
@ -116,6 +122,7 @@ function handleUp() {
|
||||||
if (searchResults.value.length === 0) {
|
if (searchResults.value.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isNavigating.value = true;
|
||||||
activeIndex.value--;
|
activeIndex.value--;
|
||||||
if (activeIndex.value < 0) {
|
if (activeIndex.value < 0) {
|
||||||
activeIndex.value = searchResults.value.length - 1;
|
activeIndex.value = searchResults.value.length - 1;
|
||||||
|
|
@ -128,6 +135,7 @@ function handleDown() {
|
||||||
if (searchResults.value.length === 0) {
|
if (searchResults.value.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isNavigating.value = true;
|
||||||
activeIndex.value++;
|
activeIndex.value++;
|
||||||
if (activeIndex.value > searchResults.value.length - 1) {
|
if (activeIndex.value > searchResults.value.length - 1) {
|
||||||
activeIndex.value = 0;
|
activeIndex.value = 0;
|
||||||
|
|
@ -143,6 +151,7 @@ function handleClose() {
|
||||||
|
|
||||||
// Activate when the mouse moves to a certain line
|
// Activate when the mouse moves to a certain line
|
||||||
function handleMouseenter(e: MouseEvent) {
|
function handleMouseenter(e: MouseEvent) {
|
||||||
|
if (isNavigating.value) return;
|
||||||
const index = (e.target as HTMLElement)?.dataset.index;
|
const index = (e.target as HTMLElement)?.dataset.index;
|
||||||
activeIndex.value = Number(index);
|
activeIndex.value = Number(index);
|
||||||
}
|
}
|
||||||
|
|
@ -221,6 +230,10 @@ onMounted(() => {
|
||||||
// esc close
|
// esc close
|
||||||
onKeyStroke('Escape', handleClose);
|
onKeyStroke('Escape', handleClose);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEventListener('mousemove', () => {
|
||||||
|
isNavigating.value = false;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue