Skip to content

Commit

Permalink
fix: focus
Browse files Browse the repository at this point in the history
Signed-off-by: Hristiyan <[email protected]>
  • Loading branch information
icoxxx committed Jan 31, 2025
1 parent 8e454bf commit e6a71ef
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions front-end/src/renderer/components/ui/AppAutoComplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,7 @@ const handleKeyDown = (e: KeyboardEvent) => {
e.preventDefault();
toggleDropdown(false);
setValue((modelValue.value + autocompleteSuggestion.value).trim());
const focusableElements = Array.from(
document.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
),
);
const currentIndex = focusableElements.indexOf(document.activeElement as HTMLElement);
if (currentIndex !== -1 && focusableElements[currentIndex + 1]) {
focusableElements[currentIndex + 1].focus();
}
focusNextElement();
} else if (e.key === 'Escape') {
toggleDropdown(false);
} else if (e.code === 'Space' && props.disableSpaces) {
Expand Down Expand Up @@ -211,10 +201,28 @@ function handleGlobalEvents(add: boolean) {
}
function completeNextCharacter() {
if (!autocompleteSuggestion.value || autocompleteSuggestion.value.length === 0) return;
if (!autocompleteSuggestion.value || autocompleteSuggestion.value.length === 0) {
toggleDropdown(false);
focusNextElement();
return;
}
modelValue.value += autocompleteSuggestion.value[0];
}
function focusNextElement() {
const focusableElements = Array.from(
document.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
),
);
const currentIndex = focusableElements.indexOf(document.activeElement as HTMLElement);
if (currentIndex !== -1 && focusableElements[currentIndex + 1]) {
focusableElements[currentIndex + 1].focus();
}
}
/* Hooks */
onMounted(() => {
setTimeout(() => {
Expand Down

0 comments on commit e6a71ef

Please sign in to comment.