diff options
Diffstat (limited to 'src/components/search_bar/search_bar.js')
| -rw-r--r-- | src/components/search_bar/search_bar.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/components/search_bar/search_bar.js b/src/components/search_bar/search_bar.js new file mode 100644 index 00000000..d7d85676 --- /dev/null +++ b/src/components/search_bar/search_bar.js @@ -0,0 +1,32 @@ +const SearchBar = { + data: () => ({ + searchTerm: undefined, + hidden: true, + error: false, + loading: false + }), + watch: { + '$route': function (route) { + if (route.name === 'search') { + this.searchTerm = route.query.query + } + } + }, + methods: { + find (searchTerm) { + this.$router.push({ name: 'search', query: { query: searchTerm } }) + this.$refs.searchInput.focus() + }, + toggleHidden () { + this.hidden = !this.hidden + this.$emit('toggled', this.hidden) + this.$nextTick(() => { + if (!this.hidden) { + this.$refs.searchInput.focus() + } + }) + } + } +} + +export default SearchBar |
