From 2dc2c34a74e77960b1f98ebeba1c1131f7ca5f1c Mon Sep 17 00:00:00 2001 From: userquin Date: Fri, 5 Apr 2024 21:57:18 +0200 Subject: [PATCH] fix(a11y): settings items without href --- components/settings/SettingsItem.vue | 27 ++++++++++++++++++++++++--- pages/settings/about/index.vue | 11 +++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/components/settings/SettingsItem.vue b/components/settings/SettingsItem.vue index 324a752b..ed8223a0 100644 --- a/components/settings/SettingsItem.vue +++ b/components/settings/SettingsItem.vue @@ -11,11 +11,28 @@ const props = defineProps<{ large?: true match?: boolean target?: string + button?: boolean }>() +defineEmits<{ + (event: 'click'): void +}>() + +const vm = getCurrentInstance() const router = useRouter() const scrollOnClick = computed(() => props.to && !(props.target === '_blank' || props.external)) +function focus() { + setTimeout(() => { + if (props.button) + vm?.vnode.el?.querySelector('button')?.focus() + else + vm?.vnode.el?.focus() + }, 100) +} + +defineExpose({ focus }) + useCommand({ scope: 'Settings', @@ -45,13 +62,17 @@ useCommand({ exact-active-class="text-primary" :class="disabled ? 'op25 pointer-events-none ' : match ? 'text-primary' : ''" block w-full group focus:outline-none - :tabindex="disabled ? -1 : null" + :tabindex="!button && disabled ? -1 : undefined" + :custom="button" @click="scrollOnClick ? $scrollToTop() : undefined" > -

-
+ diff --git a/pages/settings/about/index.vue b/pages/settings/about/index.vue index d025514a..85d7ddb2 100644 --- a/pages/settings/about/index.vue +++ b/pages/settings/about/index.vue @@ -6,12 +6,14 @@ useHydratedHead({ title: () => `${t('settings.about.label')} | ${t('nav.settings')}`, }) +const commitRef = ref() const showCommit = ref(buildInfo.env !== 'release' && buildInfo.env !== 'dev') const builtTime = useFormattedDateTime(buildInfo.time) function handleShowCommit() { setTimeout(() => { showCommit.value = true + nextTick(() => commitRef.value?.focus()) }, 50) } @@ -33,9 +35,12 @@ function handleShowCommit() {