Skip to content

Commit 2dc2c34

Browse files
committed
fix(a11y): settings items without href
1 parent 25fb7c1 commit 2dc2c34

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

components/settings/SettingsItem.vue

+24-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@ const props = defineProps<{
1111
large?: true
1212
match?: boolean
1313
target?: string
14+
button?: boolean
1415
}>()
1516
17+
defineEmits<{
18+
(event: 'click'): void
19+
}>()
20+
21+
const vm = getCurrentInstance()
1622
const router = useRouter()
1723
const scrollOnClick = computed(() => props.to && !(props.target === '_blank' || props.external))
1824
25+
function focus() {
26+
setTimeout(() => {
27+
if (props.button)
28+
vm?.vnode.el?.querySelector('button')?.focus()
29+
else
30+
vm?.vnode.el?.focus()
31+
}, 100)
32+
}
33+
34+
defineExpose({ focus })
35+
1936
useCommand({
2037
scope: 'Settings',
2138
@@ -45,13 +62,17 @@ useCommand({
4562
exact-active-class="text-primary"
4663
:class="disabled ? 'op25 pointer-events-none ' : match ? 'text-primary' : ''"
4764
block w-full group focus:outline-none
48-
:tabindex="disabled ? -1 : null"
65+
:tabindex="!button && disabled ? -1 : undefined"
66+
:custom="button"
4967
@click="scrollOnClick ? $scrollToTop() : undefined"
5068
>
51-
<div
69+
<component
70+
:is="button ? 'button' : 'div'"
5271
w-full flex px5 py3 md:gap2 gap4 items-center
5372
transition-250 group-hover:bg-active
5473
group-focus-visible:ring="2 current"
74+
:disabled="button ? disabled : undefined"
75+
@click="button && !disabled && $emit('click')"
5576
>
5677
<div flex-1 flex items-center md:gap2 gap4>
5778
<div
@@ -85,6 +106,6 @@ useCommand({
85106
</slot>
86107
</p>
87108
<div v-if="to" :class="!external ? 'i-ri:arrow-right-s-line' : 'i-ri:external-link-line'" text-xl text-secondary-light class="rtl-flip" />
88-
</div>
109+
</component>
89110
</NuxtLink>
90111
</template>

pages/settings/about/index.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ useHydratedHead({
66
title: () => `${t('settings.about.label')} | ${t('nav.settings')}`,
77
})
88
9+
const commitRef = ref()
910
const showCommit = ref(buildInfo.env !== 'release' && buildInfo.env !== 'dev')
1011
const builtTime = useFormattedDateTime(buildInfo.time)
1112
1213
function handleShowCommit() {
1314
setTimeout(() => {
1415
showCommit.value = true
16+
nextTick(() => commitRef.value?.focus())
1517
}, 50)
1618
}
1719
</script>
@@ -33,9 +35,12 @@ function handleShowCommit() {
3335

3436
<template v-if="isHydrated">
3537
<SettingsItem
38+
ref="commitRef"
3639
:text="$t('settings.about.version')"
3740
:to="showCommit ? `https://github.com/elk-zone/elk/commit/${buildInfo.commit}` : undefined"
38-
external target="_blank"
41+
external
42+
target="_blank"
43+
:button="!showCommit"
3944
@click="handleShowCommit"
4045
>
4146
<template #content>
@@ -54,7 +59,9 @@ function handleShowCommit() {
5459
<SettingsItem
5560
:text="$t('nav.show_intro')"
5661
icon="i-ri:article-line"
57-
cursor-pointer large
62+
cursor-pointer
63+
large
64+
button
5865
@click="openPreviewHelp"
5966
/>
6067

0 commit comments

Comments
 (0)