2 <div class="search-bar">
3 <label for="search" class="search-label"></label>
8 @input="search($event.target.value)"
9 @keyup.enter.exact="open()"
10 @keyup.alt.enter="open('_blank')"
26 this._keyListener = function (event) {
27 if (event.key === this.hotkey) {
28 event.preventDefault();
31 if (event.key === "Escape") {
35 document.addEventListener("keydown", this._keyListener.bind(this));
37 // fill search from get parameter.
38 const search = new URLSearchParams(window.location.search).get("search");
40 this.$refs.search.value = search;
46 open: function (target = null) {
47 if (!this.$refs.search.value) {
50 this.$emit("search-open", target);
53 this.$emit("search-focus");
54 this.$nextTick(() => {
55 this.$refs.search.focus();
58 setSearchURL: function (value) {
59 const url = new URL(window.location);
61 url.searchParams.delete("search");
63 url.searchParams.set("search", value);
65 window.history.replaceState("search", null, url);
68 this.setSearchURL("");
69 this.$refs.search.value = "";
70 this.$refs.search.blur();
71 this.$emit("search-cancel");
73 search: function (value) {
74 this.setSearchURL(value);
75 this.$emit("input", value.toLowerCase());
79 document.removeEventListener("keydown", this._keyListener);
84 <style lang="scss" scoped></style>