Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(a11y): add access keys shortcuts #2768

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/main/MainContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defineProps<{
back?: boolean
/** Do not applying overflow hidden to let use floatable components in title */
noOverflowHidden?: boolean
/** Add the skip content link: it is the translation key */
skipContent?: string
}>()

const container = ref()
Expand All @@ -26,6 +28,9 @@ const containerClass = computed(() => {

<template>
<div ref="container" :class="containerClass">
<SkipContentLink v-if="skipContent">
{{ $t(skipContent) }}
</SkipContentLink>
<div
sticky top-0 z10
pt="[env(safe-area-inset-top,0)]"
Expand Down
14 changes: 14 additions & 0 deletions components/skip/SkipContent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @unocss-include
import { accessKeys } from '~/constants/access-keys'

export default defineComponent({
setup() {
const { t } = useI18n()
return () => h('a', {
id: 'skip-navigation',
class: 'sr-only',
href: '#skip-content',
accesskey: accessKeys.SkipContent,
}, t(`a11y.skip_navigation`))
},
})
5 changes: 5 additions & 0 deletions components/skip/SkipContentLink.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<NuxtLink id="skip-content" sr-only>
<slot />
</NuxtLink>
</template>
6 changes: 6 additions & 0 deletions constants/access-keys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const accessKeys = {
Home: 'S',
SkipContent: '1',
Search: '2',
Shortcuts: '3',
} as const
1 change: 1 addition & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const isGrayscale = usePreferences('grayscaleMode')

<template>
<div h-full :data-mode="isHydrated && isGrayscale ? 'grayscale' : ''" data-tauri-drag-region>
<SkipContent />
<main flex w-full mxa lg:max-w-80rem class="native:grid native:sm:grid-cols-[auto_1fr] native:lg:grid-cols-[auto_minmax(600px,2fr)_1fr]">
<aside class="native:w-auto w-1/8 md:w-1/6 lg:w-1/5 xl:w-1/4 zen-hide" hidden sm:flex justify-end xl:me-4 native:me-0 relative>
<div sticky top-0 w-20 xl:w-100 h-100dvh flex="~ col" lt-xl-items-center>
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"loading_titled_page": "Loading {0} page, please wait",
"locale_changed": "Language changed to {0}",
"locale_changing": "Changing language, please wait",
"route_loaded": "Page {0} loaded"
"route_loaded": "Page {0} loaded",
"skip_navigation": "Skip navigation"
},
"account": {
"authorize": "Authorize to follow",
Expand Down
3 changes: 2 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"loading_titled_page": "Cargando página {0}, espera por favor",
"locale_changed": "Idioma cambiado a {0}",
"locale_changing": "Cambiando idioma, espera por favor",
"route_loaded": "Página {0} cargada"
"route_loaded": "Página {0} cargada",
"skip_navigation": "Saltar navegación"
},
"account": {
"authorize": "Autorizar seguimiento",
Expand Down
2 changes: 1 addition & 1 deletion pages/blocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="nav.blocked_users">
<template #title>
<span timeline-title-style>{{ $t('nav.blocked_users') }}</span>
</template>
Expand Down
2 changes: 1 addition & 1 deletion pages/bookmarks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="nav.bookmarks">
<template #title>
<NuxtLink to="/bookmarks" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:bookmark-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/conversations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="nav.conversations">
<template #title>
<NuxtLink to="/conversations" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:at-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/domain_blocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="nav.blocked_domains">
<template #title>
<span timeline-title-style>{{ $t('nav.blocked_domains') }}</span>
</template>
Expand Down
2 changes: 1 addition & 1 deletion pages/favourites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="nav.favourites">
<template #title>
<NuxtLink to="/favourites" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div :class="useStarFavoriteIcon ? 'i-ri:star-line' : 'i-ri:heart-3-line'" />
Expand Down
2 changes: 1 addition & 1 deletion pages/hashtags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="nav.hashtags">
<template #title>
<NuxtLink to="/hashtags" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div class="i-ri:hashtag" />
Expand Down
2 changes: 1 addition & 1 deletion pages/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="nav.home">
<template #title>
<NuxtLink to="/home" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:home-5-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/mutes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="nav.muted_users">
<template #title>
<span timeline-title-style>{{ $t('nav.muted_users') }}</span>
</template>
Expand Down
6 changes: 5 additions & 1 deletion pages/notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,14 @@ const moreOptions = computed<CommonRouteTabMoreOption>(() => ({
tooltip: filterText.value,
match: !!filter.value,
}))
const skipContent = computed(() => {
const name = route.params.filter
return name ? `tab.notifications_${name}` : 'tab.notifications_all'
})
</script>

<template>
<MainContent>
<MainContent :skip-content="skipContent">
<template #title>
<NuxtLink to="/notifications" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:notification-4-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/pinned.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent>
<MainContent skip-content="account.pinned">
<template #title>
<NuxtLink to="/public/pinned" timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:pushpin-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const isRootPath = computed(() => route.name === 'settings')
<div>
<div min-h-screen flex>
<div border="e base" :class="isRootPath ? 'block lg:flex-none flex-1' : 'hidden lg:block'">
<MainContent>
<MainContent :skip-content="isRootPath ? 'nav.settings' : undefined">
<template #title>
<div timeline-title-style flex items-center gap-2 @click="$scrollToTop">
<div i-ri:settings-3-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/about/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function handleShowCommit() {
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.about.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.about.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/interface/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ useHydratedHead({
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.interface.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.interface.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/language/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const status = computed(() => {
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.language.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.language.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/notifications/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ useHydratedHead({
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.notifications.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.notifications.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/notifications/notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="settings.notifications.notifications.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<div i-ri:test-tube-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/notifications/push-notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="settings.notifications.push_notifications.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.notifications.push_notifications.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/preferences/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const userSettings = useUserSettings()
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.preferences.label">
<template #title>
<h1 text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
{{ $t('settings.preferences.label') }}
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/profile/appearance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ onReactivated(refreshInfo)
</script>

<template>
<MainContent back>
<MainContent back skip-content="settings.profile.appearance.title">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.profile.appearance.title') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/profile/featured-tags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back>
<MainContent back skip-content="settings.profile.featured_tags.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<div i-ri:test-tube-line />
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/profile/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ useHydratedHead({
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.profile.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.profile.label') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion pages/settings/users/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function importTokens() {
</script>

<template>
<MainContent back-on-small-screen>
<MainContent back-on-small-screen skip-content="settings.users.label">
<template #title>
<div text-lg font-bold flex items-center gap-2 @click="$scrollToTop">
<span>{{ $t('settings.users.label') }}</span>
Expand Down
Loading