2019-04-03 17:29:03 +02:00
|
|
|
<template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<p label-for="navSearchField" class="-mt-2">
|
|
|
|
<input
|
2022-04-21 15:50:07 +02:00
|
|
|
:placeholder="defaultPlaceHolder"
|
|
|
|
type="search"
|
2020-06-11 11:45:52 +02:00
|
|
|
id="navSearchField"
|
2022-07-12 10:55:28 +02:00
|
|
|
icon="Magnify"
|
2022-04-21 15:50:07 +02:00
|
|
|
icon-clickable
|
2020-02-18 08:57:00 +01:00
|
|
|
rounded
|
2022-04-21 15:50:07 +02:00
|
|
|
custom-class="searchField"
|
2021-11-07 21:02:06 +01:00
|
|
|
dir="auto"
|
2020-08-05 14:39:17 +02:00
|
|
|
v-model="search"
|
2022-07-12 10:55:28 +02:00
|
|
|
@keyup.enter="enter"
|
|
|
|
/>
|
|
|
|
<label>
|
2022-04-21 15:50:07 +02:00
|
|
|
<span class="sr-only">{{ defaultPlaceHolder }}</span>
|
2022-07-12 10:55:28 +02:00
|
|
|
</label>
|
|
|
|
</p>
|
2019-04-03 17:29:03 +02:00
|
|
|
</template>
|
2022-07-12 10:55:28 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, ref } from "vue";
|
|
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
import { useRouter } from "vue-router";
|
2020-02-18 08:57:00 +01:00
|
|
|
import RouteName from "../router/name";
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const router = useRouter();
|
|
|
|
const { t } = useI18n({ useScope: "global" });
|
|
|
|
const emit = defineEmits(["navbar-search"]);
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
placeholder?: string;
|
|
|
|
}>();
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const search = ref("");
|
2019-04-03 17:29:03 +02:00
|
|
|
|
2022-07-12 10:55:28 +02:00
|
|
|
const enter = async (): Promise<void> => {
|
|
|
|
emit("navbar-search");
|
|
|
|
await router.push({
|
|
|
|
name: RouteName.SEARCH,
|
|
|
|
query: { term: search.value },
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultPlaceHolder = computed((): string => {
|
|
|
|
// We can't use "this" inside @Prop's default value.
|
|
|
|
return props.placeholder ?? t("Search");
|
|
|
|
});
|
2019-04-03 17:29:03 +02:00
|
|
|
</script>
|
2019-10-10 13:29:58 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
label span.visually-hidden {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
input.searchField {
|
|
|
|
box-shadow: none;
|
|
|
|
border-color: #b5b5b5;
|
2022-04-21 15:50:07 +02:00
|
|
|
border-radius: 9999px !important;
|
2019-11-05 15:09:40 +01:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
&::placeholder {
|
|
|
|
color: gray;
|
|
|
|
}
|
|
|
|
}
|
2019-11-05 15:09:40 +01:00
|
|
|
</style>
|