forked from project-trans/RLE-wiki
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
为主题添加了搜索功能和无障碍支持,包括搜索输入框的 ARIA 标签和搜索按钮的 ARIA 标签。还模拟了搜索结果的列表,并提供了键盘导航的提示。 Closes project-trans#123
- Loading branch information
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
packages/vitepress-theme-project-trans/src/components/SearchWithAria.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters