Skip to content

Commit

Permalink
perf: 优化侧边栏交互
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Dec 22, 2023
1 parent 1b7d3da commit 92fb84d
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/theme/src/client/components/SidebarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ const classes = computed(() => [
{ 'has-active': hasActiveLink.value },
])
function onItemClick() {
function onItemInteraction(e: MouseEvent | Event) {
if ('key' in e && e.key !== 'Enter') {
return
}
!props.item.link && toggle()
}
Expand All @@ -55,10 +58,19 @@ function onCaretClick() {

<template>
<Component :is="sectionTag" class="sidebar-item" :class="classes">
<div v-if="item.text" class="item" :role="itemRole" @click="onItemClick">
<div
v-if="item.text"
class="item"
:role="itemRole"
:tabindex="item.items && 0"
v-on="item.items
? { click: onItemInteraction, keydown: onItemInteraction }
: {}
"
>
<div class="indicator" />

<AutoLink :tag="linkTag" class="link" :href="item.link">
<AutoLink v-if="item.link" :tag="linkTag" class="link" :href="item.link">
<!-- eslint-disable vue/no-v-text-v-html-on-component -->
<!-- eslint-disable-next-line vue/no-v-html -->
<Component :is="textTag" class="text" v-html="item.text" />
Expand All @@ -68,7 +80,10 @@ function onCaretClick() {
v-if="item.collapsed != null"
class="caret"
role="button"
aria-label="toggle section"
tabindex="0"
@click="onCaretClick"
@keydown.enter="onCaretClick"
>
<IconChevronRight class="caret-icon" />
</div>
Expand Down

0 comments on commit 92fb84d

Please sign in to comment.