Skip to content

Commit c6f1322

Browse files
boaz0kefranabg
authored andcommitted
Add search box placeholder setting to theme-config (#1834)
Signed-off-by: Boaz Shuster <[email protected]>
1 parent 696717b commit c6f1322

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

packages/@vuepress/plugin-search/SearchBox.vue

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
aria-label="Search"
66
:value="query"
77
:class="{ 'focused': focused }"
8+
:placeholder="placeholder"
89
autocomplete="off"
910
spellcheck="false"
1011
@focus="focused = true"
@@ -42,10 +43,14 @@ export default {
4243
return {
4344
query: '',
4445
focused: false,
45-
focusIndex: 0
46+
focusIndex: 0,
47+
placeholder: undefined
4648
}
4749
},
4850
51+
mounted () {
52+
this.placeholder = this.$site.themeConfig.searchPlaceholder || ''
53+
},
4954
computed: {
5055
showSuggestions () {
5156
return (

packages/@vuepress/theme-default/components/AlgoliaSearchBox.vue

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<input
88
id="algolia-search-input"
99
class="search-query"
10+
:placeholder="placeholder"
1011
>
1112
</form>
1213
</template>
@@ -15,8 +16,15 @@
1516
export default {
1617
props: ['options'],
1718
19+
data () {
20+
return {
21+
placeholder: undefined
22+
}
23+
},
24+
1825
mounted () {
1926
this.initialize(this.options, this.$lang)
27+
this.placeholder = this.$site.themeConfig.searchPlaceholder || ''
2028
},
2129
2230
methods: {

packages/docs/docs/theme/default-theme-config.md

+12
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,18 @@ Unlike the [built-in search](#built-in-search) engine which works out of the box
351351

352352
For more options, check out [Algolia DocSearch’s documentation](https://github.com/algolia/docsearch#docsearch-options).
353353

354+
### Search Placeholder
355+
356+
You can define a placeholder for the search box by adding the `searchPlaceholder` attribute:
357+
358+
``` js
359+
module.exports = {
360+
themeConfig: {
361+
searchPlaceholder: 'Search...'
362+
}
363+
}
364+
```
365+
354366
## Last Updated
355367

356368
The `themeConfig.lastUpdated` option allows you to get the UNIX timestamp(ms) of each file’s last `git` commit, and it will also display at the bottom of each page in an appropriate format:

0 commit comments

Comments
 (0)