From 787737c80d8b815209539f159449efee677bd5d9 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 13:18:36 -0400 Subject: [PATCH] hide results on outside click --- package.json | 1 + .../user_autosuggest/user_autosuggest.js | 14 ++++++++++++-- .../user_autosuggest/user_autosuggest.vue | 4 ++-- src/main.js | 2 ++ yarn.lock | 4 ++++ 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index c80e0f63..14937673 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "popper.js": "^1.14.7", "sanitize-html": "^1.13.0", "sass-loader": "^4.0.2", + "v-click-outside": "^2.1.1", "vue": "^2.5.13", "vue-chat-scroll": "^1.2.1", "vue-compose": "^0.7.1", diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index eff6ef75..b99f61cc 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -11,7 +11,8 @@ export default { return { query: '', results: [], - timeout: null + timeout: null, + resultsVisible: false } }, watch: { @@ -26,9 +27,18 @@ export default { this.results = [] if (query) { userSearchApi.search({query, store: this.$store}) - .then((data) => { this.results = data }) + .then((data) => { + this.results = data + this.resultsVisible = true + }) } }, debounceMilliseconds) + }, + onInputClick () { + this.resultsVisible = true + }, + onClickOutside () { + this.resultsVisible = false } } } diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 743d9eaf..eb5aa41b 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,7 +1,7 @@