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(theme): search box configuration loses responsiveness (when switching between multiple languages) #3096

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 15 additions & 3 deletions src/client/theme-default/components/VPNavBarSearchButton.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import type { ButtonTranslations } from '../../../../types/local-search'
import { useData } from '../composables/data'
import { computed } from 'vue'
import { createTranslate } from '../support/translation'

const { theme } = useData()
Expand All @@ -13,11 +14,22 @@ const defaultTranslations: { button: ButtonTranslations } = {
}
}

const $t = createTranslate(theme.value.search?.options, defaultTranslations)
// Use the following order to get the text
// 1. locale
// 2. translation
// 3. default
const searchButton = computed<{ hint: string, aria: string }>(() => {
const $t = createTranslate(theme.value.search?.options, defaultTranslations)

return {
hint: $t('button.buttonText'),
aria: $t('button.buttonAriaLabel')
}
})
</script>

<template>
<button type="button" class="DocSearch DocSearch-Button" :aria-label="$t('button.buttonAriaLabel')">
<button type="button" class="DocSearch DocSearch-Button" :aria-label="searchButton.aria">
<span class="DocSearch-Button-Container">
<svg
class="DocSearch-Search-Icon"
Expand All @@ -35,7 +47,7 @@ const $t = createTranslate(theme.value.search?.options, defaultTranslations)
stroke-linejoin="round"
/>
</svg>
<span class="DocSearch-Button-Placeholder">{{ $t('button.buttonText') }}</span>
<span class="DocSearch-Button-Placeholder">{{ searchButton.hint }}</span>
</span>
<span class="DocSearch-Button-Keys">
<kbd class="DocSearch-Button-Key"></kbd>
Expand Down
2 changes: 2 additions & 0 deletions src/client/theme-default/support/translation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useData } from '../composables/data'

/**
* The value returned by the helper function returned by this function is not responsive,
* to get responsiveness call inside computed or translate again in onUpdated to update the value.
* @param themeObject Can be an object with `translations` and `locales` properties
*/
export function createTranslate(
Expand Down