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')"
20 this._keyListener = function (event) {
21 if (event.key === "/") {
22 event.preventDefault();
25 if (event.key === "Escape") {
29 document.addEventListener("keydown", this._keyListener.bind(this));
31 // fill seach from get parameter.
32 const search = new URLSearchParams(window.location.search).get("search");
34 this.$refs.search.value = search;
40 open: function (target = null) {
41 if (!this.$refs.search.value) {
44 this.$emit("search-open", target);
47 this.$emit("search-focus");
48 this.$nextTick(() => {
49 this.$refs.search.focus();
52 setSearchURL: function (value) {
53 const url = new URL(window.location);
55 url.searchParams.delete("search");
57 url.searchParams.set("search", value);
59 window.history.replaceState("search", null, url);
62 this.setSearchURL("");
63 this.$refs.search.value = "";
64 this.$refs.search.blur();
65 this.$emit("search-cancel");
67 search: function (value) {
68 this.setSearchURL(value);
69 this.$emit("input", value.toLowerCase());
73 document.removeEventListener("keydown", this._keyListener);
78 <style lang="scss" scoped></style>