]> git.immae.eu Git - github/bastienwirtz/homer.git/blobdiff - src/components/SearchInput.vue
Initial Emby service commit
[github/bastienwirtz/homer.git] / src / components / SearchInput.vue
index eb9c97860f24af0521621b2a3bdd073a2f2069a3..165c99299a552b7a893db4339aca64150805ac7d 100644 (file)
@@ -6,8 +6,8 @@
       ref="search"
       :value="value"
       @input="search($event.target.value)"
-      @keyup.enter.exact="$emit('search-open')"
-      @keyup.alt.enter="$emit('search-open', '_blank')"
+      @keyup.enter.exact="open()"
+      @keyup.alt.enter="open('_blank')"
     />
   </div>
 </template>
 <script>
 export default {
   name: "SearchInput",
-  props: ["value"],
+  props: {
+    value: String,
+    hotkey: {
+      type: String,
+      default: "/",
+    },
+  },
   mounted() {
     this._keyListener = function (event) {
-      if (event.key === "/") {
+      if (event.key === this.hotkey) {
         event.preventDefault();
         this.focus();
       }
@@ -28,7 +34,7 @@ export default {
     };
     document.addEventListener("keydown", this._keyListener.bind(this));
 
-    // fill seach from get parameter.
+    // fill search from get parameter.
     const search = new URLSearchParams(window.location.search).get("search");
     if (search) {
       this.$refs.search.value = search;
@@ -37,6 +43,12 @@ export default {
     }
   },
   methods: {
+    open: function (target = null) {
+      if (!this.$refs.search.value) {
+        return;
+      }
+      this.$emit("search-open", target);
+    },
     focus: function () {
       this.$emit("search-focus");
       this.$nextTick(() => {