Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web/satellite/vuetify-poc: improve keyboard navigation for sidebars
This change improves keyboard navigation for the Vuetify UI's navigation sidebars. Navigation items can now be focused with the tab key and selected with the enter or space key. Resolves #6411 Change-Id: I6416efbee74209e089abbccd0e1a7f1c0f4b80cb
- Loading branch information
Showing
5 changed files
with
308 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
web/satellite/vuetify-poc/src/layouts/default/NavigationItem.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (C) 2023 Storj Labs, Inc. | ||
// See LICENSE for copying information. | ||
|
||
<template> | ||
<v-list-item link lines="one" :to="to" class="my-1" tabindex="0" @click="onClick" @keydown.space.prevent="onClick"> | ||
<template #prepend> | ||
<slot name="prepend" /> | ||
</template> | ||
<v-list-item-title class="ml-3">{{ title }}</v-list-item-title> | ||
<v-list-item-subtitle v-if="subtitle" class="ml-3">{{ subtitle }}</v-list-item-subtitle> | ||
<template #append> | ||
<slot name="append" /> | ||
</template> | ||
</v-list-item> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { VListItem, VListItemTitle, VListItemSubtitle } from 'vuetify/components'; | ||
import { useDisplay } from 'vuetify'; | ||
import { useRouter } from 'vue-router'; | ||
import { useAppStore } from '@poc/store/appStore'; | ||
import { useAnalyticsStore } from '@/store/modules/analyticsStore'; | ||
import { useProjectsStore } from '@/store/modules/projectsStore'; | ||
const { mdAndDown } = useDisplay(); | ||
const router = useRouter(); | ||
const appStore = useAppStore(); | ||
const projectsStore = useProjectsStore(); | ||
const analyticsStore = useAnalyticsStore(); | ||
const props = defineProps<{ | ||
title: string; | ||
subtitle?: string; | ||
to?: string; | ||
}>(); | ||
/** | ||
* Conditionally closes the navigation drawer and tracks page visit. | ||
*/ | ||
function onClick(e: MouseEvent | KeyboardEvent): void { | ||
if (!props.to) return; | ||
const next = router.resolve(props.to).path; | ||
if (next === router.currentRoute.value.path) return; | ||
if (mdAndDown.value) appStore.toggleNavigationDrawer(false); | ||
analyticsStore.pageVisit(next); | ||
// Vuetify handles navigation via click or pressing the Enter key. | ||
// We must handle the space key ourselves. | ||
if ('key' in e && e.key === ' ') router.push(props.to); | ||
} | ||
</script> |
Oops, something went wrong.