Skip to content

Commit

Permalink
feat(theme): 添加搜索功能和无障碍支持
Browse files Browse the repository at this point in the history
为主题添加了搜索功能和无障碍支持,包括搜索输入框的 ARIA 标签和搜索按钮的 ARIA 标签。还模拟了搜索结果的列表,并提供了键盘导航的提示。

Closes project-trans#123
  • Loading branch information
Leetfs committed Sep 8, 2024
1 parent b92cfb6 commit fc95d1d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<template>
<div>
<!-- 为输入框强制添加 ARIA 标签,确保无障碍访问 -->
<!-- 这里的 ARIA 标签应与 config.ts 的 buttonAriaLabel 对应 -->
<input
type="text"
aria-label="搜索文档"
placeholder="请输入搜索内容"
/>

<!-- 强制为搜索按钮添加 ARIA 标签 -->
<!-- 与 config.ts 中的 buttonAriaLabel 保持一致 -->
<button
aria-label="搜索文档"
>
搜索
</button>

<!-- 模拟搜索结果的列表,添加 ARIA 标签 -->
<ul>
<li v-for="(result, index) in results" :key="index" :id="'result' + index" :aria-labelledby="'result' + index">
{{ result }}
</li>
</ul>

<!-- 提示用户使用键盘导航 -->
<div aria-live="polite">
使用 <kbd>上箭头</kbd> 和 <kbd>下箭头</kbd> 键进行切换,按 <kbd>回车</kbd> 进行选择,按 <kbd>Esc</kbd> 退出。
</div>
</div>
</template>

<script>
export default {
data() {
return {
results: ['搜索结果 1', '搜索结果 2', '搜索结果 3'] // 模拟搜索结果
};
},
mounted() {
// 确保在挂载后 ARIA 标签和键盘事件生效
}
};
</script>

<style scoped>
/* 可选:如果有需要,可以添加样式 */
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ArticlesMenu from './ArticlesMenu.vue'
import CopyrightInfo from './CopyrightInfo.vue'
import HomeContent from './HomeContent.vue'
import PageInfo from './PageInfo.vue'
import SearchWithAria from './SearchWithAria.vue'


export {
Expand All @@ -14,5 +15,6 @@ export {
ArticlesMenu,
CopyrightInfo,
HomeContent,
PageInfo
PageInfo,
SearchWithAria
}

0 comments on commit fc95d1d

Please sign in to comment.