- sortItemClick(sortItem) {
- const lists = this.elem.querySelectorAll('.scroll-box');
- const newList = Array.from(lists).filter(list => sortItem.parentElement !== list);
- if (newList.length > 0) {
- newList[0].appendChild(sortItem);
+ 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';