2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-12 09:51:58 +00:00
|
|
|
<div id="searchForm" class="side search" role="search">
|
2022-04-15 14:24:30 +00:00
|
|
|
<input
|
2022-04-24 20:23:20 +00:00
|
|
|
ref="input"
|
|
|
|
v-model="q"
|
2022-04-15 14:24:30 +00:00
|
|
|
:class="{ dirty: q }"
|
|
|
|
autocorrect="false"
|
2022-04-24 20:23:20 +00:00
|
|
|
name="q"
|
2022-04-15 14:24:30 +00:00
|
|
|
placeholder="Press F to search"
|
|
|
|
spellcheck="false"
|
2022-04-24 20:23:20 +00:00
|
|
|
type="search"
|
|
|
|
@focus="goToSearchScreen"
|
|
|
|
@input="onInput"
|
2022-04-15 14:24:30 +00:00
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { ref } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { debounce } from 'lodash'
|
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import router from '@/router'
|
|
|
|
|
2022-04-24 20:23:20 +00:00
|
|
|
const input = ref<HTMLInputElement>()
|
2022-04-15 17:00:08 +00:00
|
|
|
const q = ref('')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-05-15 20:44:19 +00:00
|
|
|
let onInput = () => {
|
2022-04-15 17:00:08 +00:00
|
|
|
const _q = q.value.trim()
|
|
|
|
_q && eventBus.emit('SEARCH_KEYWORDS_CHANGED', _q)
|
2022-05-15 20:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'test') {
|
|
|
|
onInput = debounce(onInput, 500)
|
|
|
|
}
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-05-12 09:51:58 +00:00
|
|
|
const goToSearchScreen = () => router.go('search')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
eventBus.on({
|
|
|
|
FOCUS_SEARCH_FIELD () {
|
2022-04-24 20:23:20 +00:00
|
|
|
input.value?.focus()
|
|
|
|
input.value?.select()
|
2022-04-15 14:24:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
#searchForm {
|
|
|
|
@include vertical-center();
|
|
|
|
flex: 0 0 256px;
|
|
|
|
order: -1;
|
|
|
|
|
|
|
|
input[type="search"] {
|
|
|
|
width: 218px;
|
|
|
|
margin-top: 0;
|
|
|
|
}
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
@media only screen and (max-width: 667px) {
|
2022-05-07 08:12:16 +00:00
|
|
|
z-index: 100;
|
2022-04-15 14:24:30 +00:00
|
|
|
position: absolute;
|
|
|
|
left: 0;
|
|
|
|
background: var(--color-bg-primary);
|
|
|
|
width: 100%;
|
|
|
|
padding: 12px;
|
2022-05-07 08:12:16 +00:00
|
|
|
top: var(--header-height);
|
|
|
|
border-bottom: 1px solid rgba(255, 255, 255, .1);
|
2022-04-15 14:24:30 +00:00
|
|
|
|
|
|
|
input[type="search"] {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.desktop & {
|
|
|
|
justify-content: flex-end;
|
|
|
|
|
|
|
|
input[type="search"] {
|
|
|
|
width: 160px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|