]> BookStack Code Mirror - bookstack/blobdiff - resources/js/components/auto-suggest.js
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / resources / js / components / auto-suggest.js
index 2ebf59f5dbf5ae08112d27384f96728b44fb3250..0b828e71bd1ea35976f348d02fd1c31dca2c5de6 100644 (file)
@@ -1,7 +1,7 @@
-import {escapeHtml} from "../services/util";
-import {onChildEvent} from "../services/dom";
-import {Component} from "./component";
-import {KeyboardNavigationHandler} from "../services/keyboard-navigation";
+import {escapeHtml} from '../services/util.ts';
+import {onChildEvent} from '../services/dom.ts';
+import {Component} from './component';
+import {KeyboardNavigationHandler} from '../services/keyboard-navigation.ts';
 
 const ajaxCache = {};
 
@@ -9,6 +9,7 @@ const ajaxCache = {};
  * AutoSuggest
  */
 export class AutoSuggest extends Component {
+
     setup() {
         this.parent = this.$el.parentElement;
         this.container = this.$el;
@@ -24,13 +25,16 @@ export class AutoSuggest extends Component {
     setupListeners() {
         const navHandler = new KeyboardNavigationHandler(
             this.list,
-            event => {
+            () => {
                 this.input.focus();
                 setTimeout(() => this.hideSuggestions(), 1);
             },
             event => {
                 event.preventDefault();
-                this.selectSuggestion(event.target.textContent);
+                const selectionValue = event.target.textContent;
+                if (selectionValue) {
+                    this.selectSuggestion(selectionValue);
+                }
             },
         );
         navHandler.shareHandlingToEl(this.input);
@@ -67,9 +71,7 @@ export class AutoSuggest extends Component {
         const search = this.input.value.toLowerCase();
         const suggestions = await this.loadSuggestions(search, nameFilter);
 
-        const toShow = suggestions.filter(val => {
-            return search === '' || val.toLowerCase().startsWith(search);
-        }).slice(0, 10);
+        const toShow = suggestions.filter(val => search === '' || val.toLowerCase().startsWith(search)).slice(0, 10);
 
         this.displaySuggestions(toShow);
     }
@@ -105,7 +107,8 @@ export class AutoSuggest extends Component {
      */
     displaySuggestions(suggestions) {
         if (suggestions.length === 0) {
-            return this.hideSuggestions();
+            this.hideSuggestions();
+            return;
         }
 
         // This used to use <button>s but was changed to div elements since Safari would not focus on buttons
@@ -126,4 +129,5 @@ export class AutoSuggest extends Component {
             this.hideSuggestions();
         }
     }
-}
\ No newline at end of file
+
+}