+
+ this.bookSearchInput.addEventListener('input', event => {
+ this.filterBooksByName(this.bookSearchInput.value);
+ });
+ }
+
+ /**
+ * @param {String} filterVal
+ */
+ filterBooksByName(filterVal) {
+
+ // Set height on first search, if not already set, to prevent the distraction
+ // of the list height jumping around
+ if (!this.allBookList.style.height) {
+ this.allBookList.style.height = this.allBookList.getBoundingClientRect().height + 'px';
+ }
+
+ const books = this.allBookList.children;
+ const lowerFilter = filterVal.trim().toLowerCase();
+
+ for (const bookEl of books) {
+ const show = !filterVal || bookEl.textContent.toLowerCase().includes(lowerFilter);
+ bookEl.style.display = show ? null : 'none';
+ }