Skip to content

Commit c08bd46

Browse files
authored
fix(theme): search's configuration about buttonAriaLabel doesn't work (#3070)
1 parent d65afc2 commit c08bd46

File tree

3 files changed

+32
-29
lines changed

3 files changed

+32
-29
lines changed

Diff for: src/client/theme-default/components/VPLocalSearchBox.vue

+12-6
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ import { pathToFile } from '../../app/utils'
3131
import { useData } from '../composables/data'
3232
import { createTranslate } from '../support/translation'
3333
34-
defineProps<{
35-
placeholder: string
36-
}>()
37-
3834
const emit = defineEmits<{
3935
(e: 'close'): void
4036
}>()
@@ -115,6 +111,16 @@ const disableDetailedView = computed(() => {
115111
)
116112
})
117113
114+
const buttonText = computed(() => {
115+
const options = theme.value.search?.options ?? theme.value.algolia
116+
117+
return (
118+
options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
119+
options?.translations?.button?.buttonText ||
120+
'Search'
121+
)
122+
})
123+
118124
watchEffect(() => {
119125
if (disableDetailedView.value) {
120126
showDetailedList.value = false
@@ -414,7 +420,7 @@ function formMarkRegex(terms: Set<string>) {
414420
@submit.prevent=""
415421
>
416422
<label
417-
:title="placeholder"
423+
:title="buttonText"
418424
id="localsearch-label"
419425
for="localsearch-input"
420426
>
@@ -463,7 +469,7 @@ function formMarkRegex(terms: Set<string>) {
463469
<input
464470
ref="searchInput"
465471
v-model="filterText"
466-
:placeholder="placeholder"
472+
:placeholder="buttonText"
467473
id="localsearch-input"
468474
aria-labelledby="localsearch-label"
469475
class="search-input"

Diff for: src/client/theme-default/components/VPNavBarSearch.vue

+3-18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import '@docsearch/css'
33
import { onKeyStroke } from '@vueuse/core'
44
import {
5-
computed,
65
defineAsyncComponent,
76
onMounted,
87
onUnmounted,
@@ -20,24 +19,14 @@ const VPAlgoliaSearchBox = __ALGOLIA__
2019
? defineAsyncComponent(() => import('./VPAlgoliaSearchBox.vue'))
2120
: () => null
2221
23-
const { theme, localeIndex } = useData()
22+
const { theme } = useData()
2423
2524
// to avoid loading the docsearch js upfront (which is more than 1/3 of the
2625
// payload), we delay initializing it until the user has actually clicked or
2726
// hit the hotkey to invoke it.
2827
const loaded = ref(false)
2928
const actuallyLoaded = ref(false)
3029
31-
const buttonText = computed(() => {
32-
const options = theme.value.search?.options ?? theme.value.algolia
33-
34-
return (
35-
options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
36-
options?.translations?.button?.buttonText ||
37-
'Search'
38-
)
39-
})
40-
4130
const preconnect = () => {
4231
const id = 'VPAlgoliaPreconnect'
4332
@@ -145,15 +134,11 @@ const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
145134
<template v-if="provider === 'local'">
146135
<VPLocalSearchBox
147136
v-if="showSearch"
148-
:placeholder="buttonText"
149137
@close="showSearch = false"
150138
/>
151139

152140
<div id="local-search">
153-
<VPNavBarSearchButton
154-
:placeholder="buttonText"
155-
@click="showSearch = true"
156-
/>
141+
<VPNavBarSearchButton @click="showSearch = true" />
157142
</div>
158143
</template>
159144

@@ -165,7 +150,7 @@ const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
165150
/>
166151

167152
<div v-if="!actuallyLoaded" id="docsearch">
168-
<VPNavBarSearchButton :placeholder="buttonText" @click="load" />
153+
<VPNavBarSearchButton @click="load" />
169154
</div>
170155
</template>
171156
</div>

Diff for: src/client/theme-default/components/VPNavBarSearchButton.vue

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
<script lang="ts" setup>
2-
defineProps<{
3-
placeholder: string
4-
}>()
2+
import type { ButtonTranslations } from '../../../../types/local-search'
3+
import { useData } from '../composables/data'
4+
import { createTranslate } from '../support/translation'
5+
6+
const { theme } = useData()
7+
8+
// Button-Translations
9+
const defaultTranslations: { button: ButtonTranslations } = {
10+
button: {
11+
buttonText: 'Search',
12+
buttonAriaLabel: 'Search',
13+
}
14+
}
15+
16+
const $t = createTranslate(theme.value.search?.options, defaultTranslations)
517
</script>
618

719
<template>
8-
<button type="button" class="DocSearch DocSearch-Button" aria-label="Search">
20+
<button type="button" class="DocSearch DocSearch-Button" :aria-label="$t('button.buttonAriaLabel')">
921
<span class="DocSearch-Button-Container">
1022
<svg
1123
class="DocSearch-Search-Icon"
@@ -23,7 +35,7 @@ defineProps<{
2335
stroke-linejoin="round"
2436
/>
2537
</svg>
26-
<span class="DocSearch-Button-Placeholder">{{ placeholder }}</span>
38+
<span class="DocSearch-Button-Placeholder">{{ $t('button.buttonText') }}</span>
2739
</span>
2840
<span class="DocSearch-Button-Keys">
2941
<kbd class="DocSearch-Button-Key"></kbd>

0 commit comments

Comments
 (0)