fix(i18n): keep root links in the active locale and fix switcher a11y
PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / Lint + typecheck (pull_request) Successful in 1m7s
PR Check / Secret scan (gitleaks) (pull_request) Successful in 6s
PR Check / Dependency audit (pull_request) Successful in 9s
PR Check / Dockerfile lint (droast) (pull_request) Successful in 5s
PR Check / AI code review (opencode) (pull_request) Successful in 55s

AppNav, AppLogo and AppBottomNav used NuxtLink to "/", which resolves to the English root under prefix_except_default; they now use NuxtLinkLocale and drop the hardcoded aria-current. Bottom-nav labels go through $t as well. The switcher's accessible name now contains the visible locale code, aria-haspopup is gone in favour of a plain disclosure with aria-controls, and Escape returns focus to the trigger.
This commit is contained in:
Noel Sabia committed 2026-10-23 22:34:09 +02:00
1 parent 078a49d14e
commit e4b30ad944
4 files changed
+22 -15

No files matched your search

+5 -6
View File
@@ -4,27 +4,26 @@
class="fixed bottom-0 left-0 w-full z-50 flex md:hidden bg-surface-container-low/90 backdrop-blur-xl shadow-[0_-1px_12px_rgba(0,0,0,0.3)]" class="fixed bottom-0 left-0 w-full z-50 flex md:hidden bg-surface-container-low/90 backdrop-blur-xl shadow-[0_-1px_12px_rgba(0,0,0,0.3)]"
> >
<div class="w-full h-16 px-space-xs flex items-center justify-around"> <div class="w-full h-16 px-space-xs flex items-center justify-around">
<NuxtLink <NuxtLinkLocale
to="/" to="/"
aria-current="page"
class="w-16 h-12 flex flex-col items-center justify-center text-primary font-semibold transition-colors" class="w-16 h-12 flex flex-col items-center justify-center text-primary font-semibold transition-colors"
> >
<Icon name="material-symbols:badge" aria-hidden="true" class="text-[22px]" /> <Icon name="material-symbols:badge" aria-hidden="true" class="text-[22px]" />
<span class="font-label-mono text-label-mono">Overview</span> <span class="font-label-mono text-label-mono">{{ $t('nav.overview') }}</span>
</NuxtLink> </NuxtLinkLocale>
<a <a
href="#" href="#"
class="w-16 h-12 flex flex-col items-center justify-center text-on-surface-variant hover:text-primary transition-colors" class="w-16 h-12 flex flex-col items-center justify-center text-on-surface-variant hover:text-primary transition-colors"
> >
<Icon name="material-symbols:timeline" aria-hidden="true" class="text-[22px]" /> <Icon name="material-symbols:timeline" aria-hidden="true" class="text-[22px]" />
<span class="font-label-mono text-label-mono">Life Map</span> <span class="font-label-mono text-label-mono">{{ $t('nav.lifeMap') }}</span>
</a> </a>
<a <a
href="#" href="#"
class="w-16 h-12 flex flex-col items-center justify-center text-on-surface-variant hover:text-primary transition-colors" class="w-16 h-12 flex flex-col items-center justify-center text-on-surface-variant hover:text-primary transition-colors"
> >
<Icon name="material-symbols:code" aria-hidden="true" class="text-[22px]" /> <Icon name="material-symbols:code" aria-hidden="true" class="text-[22px]" />
<span class="font-label-mono text-label-mono">Dev View</span> <span class="font-label-mono text-label-mono">{{ $t('nav.devView') }}</span>
</a> </a>
</div> </div>
</nav> </nav>
+13 -4
View File
@@ -1,8 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
const { locales, locale, setLocale } = useI18n() const { locales, locale, setLocale, t } = useI18n()
const open = ref(false) const open = ref(false)
const root = ref<HTMLElement | null>(null) const root = ref<HTMLElement | null>(null)
const trigger = ref<HTMLButtonElement | null>(null)
const menuId = useId()
// The accessible name has to contain the visible text (WCAG 2.5.3).
const triggerLabel = computed(() => `${t('switcher.label')}: ${locale.value.toUpperCase()}`)
function closeOnOutside(event: MouseEvent) { function closeOnOutside(event: MouseEvent) {
if (!root.value?.contains(event.target as Node)) { if (!root.value?.contains(event.target as Node)) {
@@ -11,8 +16,10 @@ function closeOnOutside(event: MouseEvent) {
} }
function closeOnEscape(event: KeyboardEvent) { function closeOnEscape(event: KeyboardEvent) {
if (event.key === 'Escape') { if (event.key === 'Escape' && open.value) {
open.value = false open.value = false
// Focus would otherwise stay on a list item that just left the DOM.
trigger.value?.focus()
} }
} }
@@ -35,11 +42,12 @@ async function choose(code: Parameters<typeof setLocale>[0]) {
<template> <template>
<div ref="root" class="relative flex shrink-0 items-center font-label-mono text-label-mono"> <div ref="root" class="relative flex shrink-0 items-center font-label-mono text-label-mono">
<button <button
ref="trigger"
type="button" type="button"
class="flex items-center gap-1.5 uppercase tracking-wider text-on-surface-variant transition-colors hover:text-on-surface" class="flex items-center gap-1.5 uppercase tracking-wider text-on-surface-variant transition-colors hover:text-on-surface"
aria-haspopup="true"
:aria-expanded="open" :aria-expanded="open"
:aria-label="$t('switcher.label')" :aria-controls="menuId"
:aria-label="triggerLabel"
@click="open = !open" @click="open = !open"
> >
<span class="h-3.5 w-5 overflow-hidden rounded-[2px]"> <span class="h-3.5 w-5 overflow-hidden rounded-[2px]">
@@ -51,6 +59,7 @@ async function choose(code: Parameters<typeof setLocale>[0]) {
<ul <ul
v-if="open" v-if="open"
:id="menuId"
class="absolute right-0 top-full z-10 mt-2 min-w-48 rounded-lg border border-outline-variant/30 bg-surface-container-high p-1 shadow-lg" class="absolute right-0 top-full z-10 mt-2 min-w-48 rounded-lg border border-outline-variant/30 bg-surface-container-high p-1 shadow-lg"
> >
<li v-for="language in locales" :key="language.code"> <li v-for="language in locales" :key="language.code">
+2 -2
View File
@@ -9,7 +9,7 @@ const flat = AVATAR_SPRITE
</script> </script>
<template> <template>
<NuxtLink to="/" class="group flex items-center gap-3"> <NuxtLinkLocale to="/" class="group flex items-center gap-3">
<span class="flex items-center justify-center w-8 h-8 rounded bg-surface-container-high transition-colors"> <span class="flex items-center justify-center w-8 h-8 rounded bg-surface-container-high transition-colors">
<span class="pixel-avatar" aria-hidden="true"> <span class="pixel-avatar" aria-hidden="true">
<span <span
@@ -24,7 +24,7 @@ const flat = AVATAR_SPRITE
<span class="font-headline-sm text-headline-sm tracking-tight text-on-surface font-medium">Noel Sabia</span> <span class="font-headline-sm text-headline-sm tracking-tight text-on-surface font-medium">Noel Sabia</span>
<span class="font-label-mono text-label-mono text-on-surface-variant tracking-wider uppercase text-[0.625rem]">Im using Arch btw</span> <span class="font-label-mono text-label-mono text-on-surface-variant tracking-wider uppercase text-[0.625rem]">Im using Arch btw</span>
</div> </div>
</NuxtLink> </NuxtLinkLocale>
</template> </template>
<style scoped> <style scoped>
+2 -3
View File
@@ -1,12 +1,11 @@
<template> <template>
<nav class="hidden lg:flex items-center gap-1.5"> <nav class="hidden lg:flex items-center gap-1.5">
<NuxtLink <NuxtLinkLocale
to="/" to="/"
aria-current="page"
class="px-3 py-1.5 transition-colors bg-primary-container text-on-primary-container font-medium rounded font-body-sm text-body-sm" class="px-3 py-1.5 transition-colors bg-primary-container text-on-primary-container font-medium rounded font-body-sm text-body-sm"
> >
{{ $t('nav.overview') }} {{ $t('nav.overview') }}
</NuxtLink> </NuxtLinkLocale>
<a <a
href="#" href="#"
class="px-3 py-1.5 text-on-surface-variant hover:text-on-surface hover:bg-surface-container-high transition-colors font-body-sm text-body-sm" class="px-3 py-1.5 text-on-surface-variant hover:text-on-surface hover:bg-surface-container-high transition-colors font-body-sm text-body-sm"