| 
									
										
										
										
											2020-05-25 15:07:03 -07:00
										 |  |  | <template> | 
					
						
							|  |  |  |   <div class="search-bar"> | 
					
						
							|  |  |  |     <label for="search" class="search-label"></label> | 
					
						
							|  |  |  |     <input | 
					
						
							|  |  |  |       type="text" | 
					
						
							|  |  |  |       ref="search" | 
					
						
							|  |  |  |       :value="value" | 
					
						
							|  |  |  |       @input="$emit('input', $event.target.value.toLowerCase())" | 
					
						
							| 
									
										
										
										
											2020-10-23 15:24:16 -07:00
										 |  |  |       @keyup.enter.exact="$emit('search-open')" | 
					
						
							|  |  |  |       @keyup.alt.enter="$emit('search-open', '_blank')" | 
					
						
							| 
									
										
										
										
											2020-05-25 15:07:03 -07:00
										 |  |  |     /> | 
					
						
							|  |  |  |   </div> | 
					
						
							|  |  |  | </template> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | export default { | 
					
						
							|  |  |  |   name: "SearchInput", | 
					
						
							|  |  |  |   props: ["value"], | 
					
						
							|  |  |  |   mounted() { | 
					
						
							|  |  |  |     this._keyListener = function (event) { | 
					
						
							|  |  |  |       if (event.key === "/") { | 
					
						
							|  |  |  |         event.preventDefault(); | 
					
						
							| 
									
										
										
										
											2020-10-23 15:24:16 -07:00
										 |  |  |         this.$emit("search-focus"); | 
					
						
							| 
									
										
										
										
											2020-05-25 15:07:03 -07:00
										 |  |  |         this.$nextTick(() => { | 
					
						
							|  |  |  |           this.$refs.search.focus(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (event.key === "Escape") { | 
					
						
							|  |  |  |         this.$refs.search.value = ""; | 
					
						
							|  |  |  |         this.$refs.search.blur(); | 
					
						
							| 
									
										
										
										
											2020-10-23 15:24:16 -07:00
										 |  |  |         this.$emit("search-cancel"); | 
					
						
							| 
									
										
										
										
											2020-05-25 15:07:03 -07:00
										 |  |  |       } | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     document.addEventListener("keydown", this._keyListener.bind(this)); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  |   beforeDestroy() { | 
					
						
							|  |  |  |     document.removeEventListener("keydown", this._keyListener); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <style lang="scss" scoped></style> |