thelounge/client/components/MessageSearchForm.vue

73 lines
1.3 KiB
Vue
Raw Normal View History

2019-12-31 16:21:34 +00:00
<template>
<form :class="['message-search', {opened: searchOpened}]" @submit.prevent="searchMessages">
<div class="input-wrapper">
<input
ref="searchInputField"
type="text"
name="search"
class="input"
placeholder="Search messages..."
@input="setSearchInput"
@blur="closeSearch"
/>
</div>
<button
class="search"
type="button"
aria-label="Search messages in this channel"
2020-01-04 18:03:56 +00:00
@mousedown.prevent="toggleSearch"
2019-12-31 16:21:34 +00:00
/>
</form>
</template>
<script>
export default {
name: "MessageSearchForm",
props: {
network: Object,
channel: Object,
},
data() {
return {
searchOpened: false,
searchInput: "",
};
},
methods: {
setSearchInput(event) {
this.searchInput = event.target.value;
},
closeSearch() {
this.searchOpened = false;
},
2020-01-04 18:03:56 +00:00
toggleSearch() {
2019-12-31 16:21:34 +00:00
if (this.searchOpened) {
2020-01-04 18:03:56 +00:00
this.$refs.searchInputField.blur();
return;
2019-12-31 16:21:34 +00:00
}
2020-01-04 18:03:56 +00:00
this.searchOpened = true;
this.$refs.searchInputField.focus();
2019-12-31 16:21:34 +00:00
},
searchMessages(event) {
event.preventDefault();
if (!this.searchInput) {
return;
}
this.searchOpened = false;
this.$router.push({
name: "SearchResults",
params: {
uuid: this.network.uuid,
target: this.channel.name,
term: this.searchInput,
},
});
},
},
};
</script>