Replace activeElement with type exact useActiveElement

This commit is contained in:
Georges-Antoine Assi
2025-09-03 09:17:42 -04:00
parent 8adea5074a
commit ed3edcdfc4
5 changed files with 30 additions and 22 deletions

View File

@@ -5,7 +5,7 @@ import CollectionListItem from "@/components/common/Collection/ListItem.vue";
import storeCollections from "@/stores/collections";
import storeNavigation from "@/stores/navigation";
import type { Events } from "@/types/emitter";
import { useLocalStorage } from "@vueuse/core";
import { useActiveElement, useLocalStorage } from "@vueuse/core";
import type { Emitter } from "mitt";
import { storeToRefs } from "pinia";
import { inject, onBeforeUnmount, onMounted, ref, watch, computed } from "vue";
@@ -15,6 +15,7 @@ import { useDisplay } from "vuetify";
const { t } = useI18n();
const navigationStore = storeNavigation();
const { mdAndUp, smAndDown } = useDisplay();
const activeElement = useActiveElement();
const collectionsStore = storeCollections();
const {
filteredCollections,
@@ -41,15 +42,11 @@ function clear() {
}
// Ref to store the element that triggered the drawer
const triggerElement = ref<HTMLElement | null>(null);
// Watch for changes in the navigation drawer state
const textFieldRef = ref();
const triggerElement = ref<HTMLElement | null | undefined>(undefined);
watch(activeCollectionsDrawer, (isOpen) => {
if (isOpen) {
// Store the currently focused element before opening the drawer
triggerElement.value = document.activeElement as HTMLElement;
// Focus the text field when the drawer is opened
// textFieldRef.value?.focus();
triggerElement.value = activeElement.value;
}
});
@@ -110,7 +107,6 @@ function onClose() {
>
<template #prepend>
<v-text-field
ref="textFieldRef"
aria-label="Search collections"
:tabindex="tabIndex"
v-model="filterText"

View File

@@ -126,7 +126,13 @@ function collapse() {
block
tabindex="7"
/>
<console-mode-btn :withTag="!mainBarCollapsed" rounded class="mt-2" block />
<console-mode-btn
:withTag="!mainBarCollapsed"
rounded
class="mt-2"
block
tabindex="8"
/>
<template #append>
<upload-btn
@@ -134,10 +140,10 @@ function collapse() {
rounded
class="mt-2 mb-6"
block
tabindex="8"
tabindex="9"
/>
<v-row no-gutters class="my-2 justify-center">
<user-btn tabindex="9" aria-label="Settings menu" />
<user-btn tabindex="10" aria-label="Settings menu" />
</v-row>
</template>
</v-navigation-drawer>

View File

@@ -3,7 +3,7 @@ import PlatformListItem from "@/components/common/Platform/ListItem.vue";
import storeNavigation from "@/stores/navigation";
import type { Platform } from "@/stores/platforms";
import storePlatforms from "@/stores/platforms";
import { useLocalStorage } from "@vueuse/core";
import { useActiveElement, useLocalStorage } from "@vueuse/core";
import { storeToRefs } from "pinia";
import { ref, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
@@ -13,14 +13,12 @@ type GroupByType = "family_name" | "generation" | "category" | null;
const { t } = useI18n();
const { mdAndUp, smAndDown } = useDisplay();
const activeElement = useActiveElement();
const navigationStore = storeNavigation();
const platformsStore = storePlatforms();
const { filteredPlatforms, filterText } = storeToRefs(platformsStore);
const { activePlatformsDrawer } = storeToRefs(navigationStore);
const textFieldRef = ref();
const triggerElement = ref<HTMLElement | null>(null);
const openPanels = ref<number[]>([]);
const groupBy = useLocalStorage<GroupByType | null>(
"settings.platformsGroupBy",
null,
@@ -80,9 +78,12 @@ watch(
{ immediate: true },
);
// Ref to store the element that triggered the drawer
const triggerElement = ref<HTMLElement | null | undefined>(undefined);
watch(activePlatformsDrawer, (isOpen) => {
if (isOpen) {
triggerElement.value = document.activeElement as HTMLElement;
// Store the currently focused element before opening the drawer
triggerElement.value = activeElement.value;
}
});
@@ -92,6 +93,7 @@ const clear = () => {
const onClose = () => {
activePlatformsDrawer.value = false;
// Focus the element that triggered the drawer
triggerElement.value?.focus();
};
</script>
@@ -113,10 +115,10 @@ const onClose = () => {
:border="0"
@update:model-value="clear"
@keydown.esc="onClose"
v-click-outside="onClose"
>
<template #prepend>
<v-text-field
ref="textFieldRef"
v-model="filterText"
:label="t('platform.search-platform')"
:tabindex="tabIndex"

View File

@@ -7,8 +7,9 @@ import storeAuth from "@/stores/auth";
import storeNavigation from "@/stores/navigation";
import type { Events } from "@/types/emitter";
import { defaultAvatarPath, getRoleIcon } from "@/utils";
import { useActiveElement } from "@vueuse/core";
import type { Emitter } from "mitt";
import { storeToRefs, getActivePinia, type StateTree } from "pinia";
import { getActivePinia, storeToRefs, type StateTree } from "pinia";
import { inject, ref, watch, computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -23,6 +24,7 @@ const emitter = inject<Emitter<Events>>("emitter");
const { activeSettingsDrawer } = storeToRefs(navigationStore);
const { smAndDown, mdAndUp } = useDisplay();
const tabIndex = computed(() => (activeSettingsDrawer.value ? 0 : -1));
const activeElement = useActiveElement();
async function logout() {
identityApi.logout().then(async () => {
@@ -47,12 +49,11 @@ async function logout() {
}
// Ref to store the element that triggered the drawer
const triggerElement = ref<HTMLElement | null>(null);
// Watch for changes in the navigation drawer state
const triggerElement = ref<HTMLElement | null | undefined>(undefined);
watch(activeSettingsDrawer, (isOpen) => {
if (isOpen) {
// Store the currently focused element before opening the drawer
triggerElement.value = document.activeElement as HTMLElement;
triggerElement.value = activeElement.value;
}
});

View File

@@ -1,10 +1,13 @@
<script setup lang="ts">
import NavigationText from "./NavigationText.vue";
import { useActiveElement } from "@vueuse/core";
import { computed, onMounted } from "vue";
const props = defineProps<{ urls: string[]; startIndex?: number }>();
const emit = defineEmits(["update:modelValue", "close"]);
const activeElement = useActiveElement();
const isOpen = computed({
get: () => true,
set: () => close(),
@@ -24,7 +27,7 @@ function closeDialog() {
}
onMounted(() => {
(document.activeElement as HTMLElement)?.blur();
activeElement.value?.blur();
});
</script>