Skip to content

Commit b5f3108

Browse files
committed
fix(search): handle back docsearch properly
Fix #965
1 parent e1ed5c8 commit b5f3108

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

.starters/default/nuxt.config.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,17 @@ export default defineNuxtConfig({
77
'@nuxtjs/plausible',
88
// https://github.com/nuxt/devtools
99
'@nuxt/devtools'
10-
]
10+
],
11+
runtimeConfig: {
12+
public: {
13+
algolia: {
14+
applicationId: 'Q46Q8609QS',
15+
apiKey: '1661c72375532f074aedd9452a1270be',
16+
langAttribute: 'lang',
17+
docSearch: {
18+
indexName: 'content-nuxtjs'
19+
}
20+
}
21+
}
22+
}
1123
})

components/app/AppDocSearch.vue

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script setup lang="ts">
2+
const { element } = useDocSearch()
3+
4+
const onClick = () => element.value.querySelector('button').click()
5+
</script>
6+
7+
<template>
8+
<button
9+
type="button"
10+
aria-label="Search"
11+
@click="onClick"
12+
>
13+
<span class="content">
14+
<Icon name="heroicons-outline:search" />
15+
<span>Search</span>
16+
<span>
17+
<kbd>⌘</kbd>
18+
<kbd>K</kbd>
19+
</span>
20+
</span>
21+
</button>
22+
</template>
23+
24+
<style scoped lang="ts">
25+
css({
26+
button: {
27+
padding: '{space.2} {space.2}',
28+
'.content': {
29+
borderRadius: '{radii.md}',
30+
display: 'flex',
31+
alignItems: 'center',
32+
color: '{color.gray.500}',
33+
borderStyle: 'solid',
34+
borderWidth: '1px',
35+
borderColor: '{color.gray.100}',
36+
fontSize: '{fontSize.xs}',
37+
gap: '{space.2}',
38+
padding: '{space.rem.375}',
39+
'@dark': {
40+
color: '{color.gray.400}',
41+
borderColor: '{color.gray.900}',
42+
},
43+
'&:hover': {
44+
color: '{color.gray.700}',
45+
borderColor: '{color.gray.400}',
46+
'@dark': {
47+
color: '{color.gray.200}',
48+
borderColor: '{color.gray.700}',
49+
}
50+
},
51+
span: {
52+
flex: 'none',
53+
display: 'none',
54+
fontSize: '{fontSize.xs}',
55+
'@lg': {
56+
display: 'block'
57+
}
58+
}
59+
}
60+
},
61+
})
62+
</style>

components/app/AppHeader.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defineProps({
1111
</script>
1212

1313
<template>
14-
<header :class="{ 'has-dialog': hasDialog, 'has-doc-search': hasDocSearch }">
14+
<header :class="{ 'has-dialog': hasDialog }">
1515
<Container :fluid="config?.header?.fluid ">
1616
<div class="section left">
1717
<AppHeaderDialog v-if="hasDialog" />
@@ -24,7 +24,9 @@ defineProps({
2424
</div>
2525

2626
<div class="section right">
27+
<AppDocSearch v-if="hasDocSearch" />
2728
<AppSearch
29+
v-else
2830
:fuse="config.fuse"
2931
/>
3032
<ThemeSelect />

0 commit comments

Comments
 (0)