Skip to content

feat(plugin-slimsearch): improve a11y, close #411 #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/plugins/search/slimsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,16 @@ Options used to create index per locale, the object keys should be the locale pa
*/
search: string

/**
* Clear search text
*/
clear: string

/**
* Remove current item
*/
remove: string

/**
* Searching text
*/
Expand Down
12 changes: 11 additions & 1 deletion docs/zh/plugins/search/slimsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ export default defineUserConfig({
*/
search: string

/**
* 清除搜索文字
*/
clear: string

/**
* 删除当前项目
*/
remove: string

/**
* 搜索中文字
*/
Expand Down Expand Up @@ -470,7 +480,7 @@ export default defineUserConfig({
如果你想要访问搜索 API,你可以从 `@vuepress/plugin-slimsearch/client` 中导入 `createSearchWorker` 来获取搜索结果:

```ts
import { createSearchWorker } from 'vuepress-plugin-search-pro/client'
import { createSearchWorker } from '@vuepress/plugin-slimsearch/client'

const { all, suggest, search, terminate } = createSearchWorker()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
import { locales, options } from '../define.js'
import { useSearchOptions } from '../helpers/index.js'
import { CLOSE_ICON } from '../icons/index.js'
import { defaultQuerySplitter } from '../utils/index.js'
import SearchKeyHints from './SearchKeyHints.js'
import { SearchLoading } from './SearchLoading.js'
import { SearchIcon } from './icons.js'
Expand Down Expand Up @@ -109,9 +110,9 @@ export default defineComponent({
() =>
(
searchOptions.value.querySplitter?.(input.value) ??
Promise.resolve(input.value.split(' '))
Promise.resolve(defaultQuerySplitter(input.value))
).then((result) => {
queries.value = result
queries.value = result.filter((item) => item.length)
}),
Math.min(options.searchDelay, options.suggestDelay),
),
Expand Down Expand Up @@ -148,14 +149,18 @@ export default defineComponent({
h('form', [
h(
'label',
{ 'for': 'search-pro', 'aria-label': locale.value.search },
{
'id': 'slimsearch-label',
'for': 'slimsearch-input',
'aria-label': locale.value.search,
},
h(SearchIcon),
),
h('input', {
'ref': inputElement,
'type': 'search',
'class': 'slimsearch-input',
'id': 'search-pro',
'id': 'slimsearch-input',
'placeholder': locale.value.placeholder,
'spellcheck': 'false',
'autocapitalize': 'off',
Expand Down
Loading
Loading