Skip to content

Commit 1a2ded4

Browse files
committed
search suggestions position tweak
1 parent 2b9b711 commit 1a2ded4

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/default-theme/SearchBox.vue

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@keyup.down="onDown">
1111
<ul class="suggestions"
1212
v-if="showSuggestions"
13+
:class="{ 'align-right': alignRight }"
1314
@mouseleave="unfocus">
1415
<li class="suggestion" v-for="(s, i) in suggestions"
1516
:class="{ focused: i === focusIndex }"
@@ -73,6 +74,12 @@ export default {
7374
}
7475
}
7576
return res
77+
},
78+
// make suggestions align right when there are not enough items
79+
alignRight () {
80+
const navCount = (this.$site.themeConfig.nav || []).length
81+
const repo = this.$site.repo ? 1 : 0
82+
return navCount + repo <= 2
7683
}
7784
},
7885
methods: {
@@ -145,6 +152,8 @@ export default {
145152
border-radius 6px
146153
padding 0.4rem
147154
list-style-type none
155+
&.align-right
156+
right 0
148157
.suggestion
149158
line-height 1.4
150159
padding 0.4rem 0.6rem
@@ -168,12 +177,16 @@ export default {
168177
position relative
169178
left 1rem
170179
&:focus
171-
left 0.5rem
180+
left 0
172181
width 10rem
173182
174183
@media (max-width: $MQMobile)
175184
.search-box
176185
margin-right 0
177186
.suggestions
178-
right -0.5rem
187+
right 0
188+
189+
@media (max-width: $MQMobileNarrow)
190+
.search-box .suggestions
191+
width calc(100vw - 4rem)
179192
</style>

0 commit comments

Comments
 (0)