fix(theme): search's configuration about buttonAriaLabel doesn't work (#3070)

pull/3079/head
烽宁 1 year ago committed by GitHub
parent d65afc2873
commit c08bd46aa7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -31,10 +31,6 @@ import { pathToFile } from '../../app/utils'
import { useData } from '../composables/data' import { useData } from '../composables/data'
import { createTranslate } from '../support/translation' import { createTranslate } from '../support/translation'
defineProps<{
placeholder: string
}>()
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'close'): void (e: 'close'): void
}>() }>()
@ -115,6 +111,16 @@ const disableDetailedView = computed(() => {
) )
}) })
const buttonText = computed(() => {
const options = theme.value.search?.options ?? theme.value.algolia
return (
options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
options?.translations?.button?.buttonText ||
'Search'
)
})
watchEffect(() => { watchEffect(() => {
if (disableDetailedView.value) { if (disableDetailedView.value) {
showDetailedList.value = false showDetailedList.value = false
@ -414,7 +420,7 @@ function formMarkRegex(terms: Set<string>) {
@submit.prevent="" @submit.prevent=""
> >
<label <label
:title="placeholder" :title="buttonText"
id="localsearch-label" id="localsearch-label"
for="localsearch-input" for="localsearch-input"
> >
@ -463,7 +469,7 @@ function formMarkRegex(terms: Set<string>) {
<input <input
ref="searchInput" ref="searchInput"
v-model="filterText" v-model="filterText"
:placeholder="placeholder" :placeholder="buttonText"
id="localsearch-input" id="localsearch-input"
aria-labelledby="localsearch-label" aria-labelledby="localsearch-label"
class="search-input" class="search-input"

@ -2,7 +2,6 @@
import '@docsearch/css' import '@docsearch/css'
import { onKeyStroke } from '@vueuse/core' import { onKeyStroke } from '@vueuse/core'
import { import {
computed,
defineAsyncComponent, defineAsyncComponent,
onMounted, onMounted,
onUnmounted, onUnmounted,
@ -20,7 +19,7 @@ const VPAlgoliaSearchBox = __ALGOLIA__
? defineAsyncComponent(() => import('./VPAlgoliaSearchBox.vue')) ? defineAsyncComponent(() => import('./VPAlgoliaSearchBox.vue'))
: () => null : () => null
const { theme, localeIndex } = useData() const { theme } = useData()
// to avoid loading the docsearch js upfront (which is more than 1/3 of the // to avoid loading the docsearch js upfront (which is more than 1/3 of the
// payload), we delay initializing it until the user has actually clicked or // payload), we delay initializing it until the user has actually clicked or
@ -28,16 +27,6 @@ const { theme, localeIndex } = useData()
const loaded = ref(false) const loaded = ref(false)
const actuallyLoaded = ref(false) const actuallyLoaded = ref(false)
const buttonText = computed(() => {
const options = theme.value.search?.options ?? theme.value.algolia
return (
options?.locales?.[localeIndex.value]?.translations?.button?.buttonText ||
options?.translations?.button?.buttonText ||
'Search'
)
})
const preconnect = () => { const preconnect = () => {
const id = 'VPAlgoliaPreconnect' const id = 'VPAlgoliaPreconnect'
@ -145,15 +134,11 @@ const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
<template v-if="provider === 'local'"> <template v-if="provider === 'local'">
<VPLocalSearchBox <VPLocalSearchBox
v-if="showSearch" v-if="showSearch"
:placeholder="buttonText"
@close="showSearch = false" @close="showSearch = false"
/> />
<div id="local-search"> <div id="local-search">
<VPNavBarSearchButton <VPNavBarSearchButton @click="showSearch = true" />
:placeholder="buttonText"
@click="showSearch = true"
/>
</div> </div>
</template> </template>
@ -165,7 +150,7 @@ const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
/> />
<div v-if="!actuallyLoaded" id="docsearch"> <div v-if="!actuallyLoaded" id="docsearch">
<VPNavBarSearchButton :placeholder="buttonText" @click="load" /> <VPNavBarSearchButton @click="load" />
</div> </div>
</template> </template>
</div> </div>

@ -1,11 +1,23 @@
<script lang="ts" setup> <script lang="ts" setup>
defineProps<{ import type { ButtonTranslations } from '../../../../types/local-search'
placeholder: string import { useData } from '../composables/data'
}>() import { createTranslate } from '../support/translation'
const { theme } = useData()
// Button-Translations
const defaultTranslations: { button: ButtonTranslations } = {
button: {
buttonText: 'Search',
buttonAriaLabel: 'Search',
}
}
const $t = createTranslate(theme.value.search?.options, defaultTranslations)
</script> </script>
<template> <template>
<button type="button" class="DocSearch DocSearch-Button" aria-label="Search"> <button type="button" class="DocSearch DocSearch-Button" :aria-label="$t('button.buttonAriaLabel')">
<span class="DocSearch-Button-Container"> <span class="DocSearch-Button-Container">
<svg <svg
class="DocSearch-Search-Icon" class="DocSearch-Search-Icon"
@ -23,7 +35,7 @@ defineProps<{
stroke-linejoin="round" stroke-linejoin="round"
/> />
</svg> </svg>
<span class="DocSearch-Button-Placeholder">{{ placeholder }}</span> <span class="DocSearch-Button-Placeholder">{{ $t('button.buttonText') }}</span>
</span> </span>
<span class="DocSearch-Button-Keys"> <span class="DocSearch-Button-Keys">
<kbd class="DocSearch-Button-Key"></kbd> <kbd class="DocSearch-Button-Key"></kbd>

Loading…
Cancel
Save