Skip to content
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

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

Merged
merged 1 commit into from
Oct 12, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/client/theme-default/components/VPLocalSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ import { pathToFile } from '../../app/utils'
import { useData } from '../composables/data'
import { createTranslate } from '../support/translation'

defineProps<{
placeholder: string
}>()

const emit = defineEmits<{
(e: 'close'): void
}>()
Expand Down Expand Up @@ -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(() => {
if (disableDetailedView.value) {
showDetailedList.value = false
Expand Down Expand Up @@ -414,7 +420,7 @@ function formMarkRegex(terms: Set<string>) {
@submit.prevent=""
>
<label
:title="placeholder"
:title="buttonText"
id="localsearch-label"
for="localsearch-input"
>
Expand Down Expand Up @@ -463,7 +469,7 @@ function formMarkRegex(terms: Set<string>) {
<input
ref="searchInput"
v-model="filterText"
:placeholder="placeholder"
:placeholder="buttonText"
id="localsearch-input"
aria-labelledby="localsearch-label"
class="search-input"
Expand Down
21 changes: 3 additions & 18 deletions src/client/theme-default/components/VPNavBarSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import '@docsearch/css'
import { onKeyStroke } from '@vueuse/core'
import {
computed,
defineAsyncComponent,
onMounted,
onUnmounted,
Expand All @@ -20,24 +19,14 @@ const VPAlgoliaSearchBox = __ALGOLIA__
? defineAsyncComponent(() => import('./VPAlgoliaSearchBox.vue'))
: () => null

const { theme, localeIndex } = useData()
const { theme } = useData()

// 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
// hit the hotkey to invoke it.
const loaded = 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 id = 'VPAlgoliaPreconnect'

Expand Down Expand Up @@ -145,15 +134,11 @@ const provider = __ALGOLIA__ ? 'algolia' : __VP_LOCAL_SEARCH__ ? 'local' : ''
<template v-if="provider === 'local'">
<VPLocalSearchBox
v-if="showSearch"
:placeholder="buttonText"
@close="showSearch = false"
/>

<div id="local-search">
<VPNavBarSearchButton
:placeholder="buttonText"
@click="showSearch = true"
/>
<VPNavBarSearchButton @click="showSearch = true" />
</div>
</template>

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

<div v-if="!actuallyLoaded" id="docsearch">
<VPNavBarSearchButton :placeholder="buttonText" @click="load" />
<VPNavBarSearchButton @click="load" />
</div>
</template>
</div>
Expand Down
22 changes: 17 additions & 5 deletions src/client/theme-default/components/VPNavBarSearchButton.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<script lang="ts" setup>
defineProps<{
placeholder: string
}>()
import type { ButtonTranslations } from '../../../../types/local-search'
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>

<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">
<svg
class="DocSearch-Search-Icon"
Expand All @@ -23,7 +35,7 @@ defineProps<{
stroke-linejoin="round"
/>
</svg>
<span class="DocSearch-Button-Placeholder">{{ placeholder }}</span>
<span class="DocSearch-Button-Placeholder">{{ $t('button.buttonText') }}</span>
</span>
<span class="DocSearch-Button-Keys">
<kbd class="DocSearch-Button-Key"></kbd>
Expand Down