diff --git a/client/src/components/Form/SearchForm.vue b/client/src/components/Form/SearchForm.vue index 27a4d99..fafe4bb 100644 --- a/client/src/components/Form/SearchForm.vue +++ b/client/src/components/Form/SearchForm.vue @@ -1,6 +1,5 @@ @@ -151,16 +152,17 @@ export default { if (!this.summoner.length) { this.summoner = this.$route.params.name } - }, - - mounted() { window.addEventListener('mousedown', this.globalClick) window.addEventListener('blur', this.windowBlur) + document.addEventListener('click', this.clickOutsideRegionDropdown) + document.addEventListener('keydown', this.handleEscape) }, beforeDestroy() { window.removeEventListener('mousedown', this.globalClick) window.removeEventListener('blur', this.windowBlur) + document.removeEventListener('click', this.clickOutsideRegionDropdown) + document.removeEventListener('keydown', this.handleEscape) }, methods: { @@ -170,6 +172,13 @@ export default { 'rounded-b': index === this.regions.length - 1 } }, + clickOutsideRegionDropdown(e) { + e.stopPropagation() + if (e.target === this.$refs['region-dropdown'] || this.$refs['region-dropdown'].contains(e.target)) { + return + } + this.dropdown = false + }, formSubmit() { const search = this.summoner.split(' ').join('') if (search.length) { @@ -183,6 +192,12 @@ export default { } this.clickDropdown = false }, + handleEscape(e) { + if (e.key === 'Esc' || e.key === 'Escape') { + this.dropdown = false + this.selected = false + } + }, windowBlur() { this.selected = false },