From a176be3e7478adb96b4615bd1250fc49f1fd1290 Mon Sep 17 00:00:00 2001 From: brios <127139797+balazs-szucs@users.noreply.github.com> Date: Sat, 4 Apr 2026 09:17:30 +0200 Subject: [PATCH] fix(search): replace dropdown with popover for search results and improve visibility handling (#355) * fix(search): replace dropdown with popover for search results and improve visibility handling * fix(search): improve search results popover styling and transition effects --- .../book-searcher.component.html | 7 +-- .../book-searcher.component.scss | 63 +++++++++---------- .../book-searcher/book-searcher.component.ts | 20 +++++- .../cbx-reader/cbx-reader.component.scss | 5 -- frontend/src/styles.scss | 31 +++++++++ 5 files changed, 83 insertions(+), 43 deletions(-) diff --git a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html index e4f3699cd..4c7f7f7f1 100644 --- a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html +++ b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.html @@ -24,10 +24,9 @@ } - @if (books.length > 0 || searchQuery) { +
@if (isLoading) { @for (i of [1,2,3]; track i) { @@ -88,6 +87,6 @@
} - } +
diff --git a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.scss b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.scss index e0cd98186..bffb699c1 100644 --- a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.scss +++ b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.scss @@ -6,27 +6,30 @@ @media (width >= 768px) { margin-left: 1.25rem; - max-width: 315px; - transition: max-width 0.3s ease; - } - - &:has(.search-iconfield.focused), - &:has(.search-iconfield.has-results) { - @media (width >= 768px) { - max-width: 100%; - } + width: var(--app-search-width-desktop); + max-width: 100%; + transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); } } +// Popover styles moved to global src/styles.scss due to appendTo="body" + .search-iconfield { width: 100%; + transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); + border-radius: 8px; @media (width >= 640px) { display: flex; } - @media (width >= 768px) { - transition: all 0.3s ease; + &.focused { + background: color-mix(in srgb, var(--primary-color) 5%, transparent); + box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 20%, transparent); + + .search-input { + border-color: var(--primary-color); + } } } @@ -36,6 +39,14 @@ height: 2.5rem; line-height: 2.5rem; font-size: 1rem; + background: var(--surface-800) !important; + border: 1px solid var(--surface-600); + transition: all 0.2s ease; + + &:hover { + border-color: var(--surface-500); + background: var(--surface-700) !important; + } } .clear-search-btn { @@ -51,24 +62,14 @@ } .search-dropdown { - position: absolute; - top: calc(100% + 0.5rem); - left: 0; width: 100%; - max-width: 600px; - background-color: var(--card-background); - border: 1px solid var(--border-color); + background: transparent; // Glassmorphism handled by parent .search-results-popover + border: none; border-radius: 8px; - box-shadow: 0 4px 6px -1px rgb(0 0 0 / 10%), - 0 2px 4px -1px rgb(0 0 0 / 6%), - 0 10px 15px -3px rgb(0 0 0 / 10%); - z-index: 1000; max-height: min(70vh, calc(100dvh - 4rem)); overflow-y: auto; - opacity: 0; - height: 0; - transform: translateY(-10px); - transition: opacity 0.2s ease, transform 0.2s ease, height 0.2s ease; + + // Desktop width constraints moved to src/styles.scss for body-appended elements &::-webkit-scrollbar { width: 8px; @@ -88,11 +89,7 @@ } } -.search-dropdown.show { - opacity: 1; - height: auto; - transform: translateY(0); -} +// .show class no longer needed as popover handles visibility .search-dropdown-item { display: flex; @@ -160,12 +157,12 @@ font-weight: 600; font-size: 0.95rem; line-height: 1.4; - color: var(--text-color); - overflow: hidden; - text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; + line-clamp: 2; -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; overflow-wrap: anywhere; margin: 0; } diff --git a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts index cc91989dd..6d76908cd 100644 --- a/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts +++ b/frontend/src/app/features/book/components/book-searcher/book-searcher.component.ts @@ -1,4 +1,4 @@ -import {Component, ElementRef, HostListener, computed, inject, signal} from '@angular/core'; +import {Component, ElementRef, HostListener, computed, inject, signal, ViewChild} from '@angular/core'; import {toObservable, toSignal} from '@angular/core/rxjs-interop'; import {debounceTime, distinctUntilChanged} from 'rxjs/operators'; import {Book} from '../../model/book.model'; @@ -15,6 +15,7 @@ import {IconField} from 'primeng/iconfield'; import {InputIcon} from 'primeng/inputicon'; import {filterBooksBySearchTerm} from '../book-browser/filters/HeaderFilter'; import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; +import {Popover} from 'primeng/popover'; @Component({ selector: 'app-book-searcher', @@ -29,6 +30,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; InputIcon, TranslocoDirective, CoverPlaceholderComponent, + Popover, ], styleUrls: ['./book-searcher.component.scss'], standalone: true @@ -61,6 +63,8 @@ export class BookSearcherComponent { private readonly t = inject(TranslocoService); private elRef = inject(ElementRef); + @ViewChild('resultsPopover') resultsPopover?: Popover; + get books(): Book[] { return this.filteredBooks(); } @@ -91,6 +95,19 @@ export class BookSearcherComponent { onSearchInputChange(): void { this.searchTerm.set(this.searchQuery.trim()); this.activeIndex = -1; + + if (this.isDropdownOpen) { + setTimeout(() => this.showPopover()); + } else { + this.resultsPopover?.hide(); + } + } + + private showPopover(): void { + if (this.resultsPopover) { + const inputElement = this.elRef.nativeElement.querySelector('.search-input'); + this.resultsPopover.show(null, inputElement); + } } onBookClick(book: Book): void { @@ -104,6 +121,7 @@ export class BookSearcherComponent { this.searchQuery = ''; this.searchTerm.set(''); this.activeIndex = -1; + this.resultsPopover?.hide(); } get isDropdownOpen(): boolean { diff --git a/frontend/src/app/features/readers/cbx-reader/cbx-reader.component.scss b/frontend/src/app/features/readers/cbx-reader/cbx-reader.component.scss index d203571ee..cc38a5961 100644 --- a/frontend/src/app/features/readers/cbx-reader/cbx-reader.component.scss +++ b/frontend/src/app/features/readers/cbx-reader/cbx-reader.component.scss @@ -19,7 +19,6 @@ // RTL reading mode - reverse page order in two-page view &.rtl-reading { .two-page-view { - .pages-wrapper, .previous-page-layer, .current-page-layer { @@ -190,7 +189,6 @@ } &.fit-width { - .pages-wrapper, .previous-page-layer, .current-page-layer { @@ -208,7 +206,6 @@ } &.two-page-view { - .pages-wrapper, .previous-page-layer, .current-page-layer { @@ -225,7 +222,6 @@ } &.fit-height { - .pages-wrapper, .previous-page-layer, .current-page-layer { @@ -660,7 +656,6 @@ // Emulate book mode spine shadow in two-page view .image-container.emulate-book { - .pages-wrapper, .current-page-layer { position: relative; diff --git a/frontend/src/styles.scss b/frontend/src/styles.scss index e5eec291b..4d0bcf612 100644 --- a/frontend/src/styles.scss +++ b/frontend/src/styles.scss @@ -24,6 +24,9 @@ html { --book-type-m4a-color: #f43f5e; --book-type-opus-color: #06b6d4; --book-type-physical-color: #8b5cf6; + + // Search Context + --app-search-width-desktop: 450px; } * { @@ -84,3 +87,31 @@ html { top: auto !important; bottom: 0; } + +// Global Search Results Popover (Appended to Body) +.p-popover.search-results-popover { + padding: 0; + background: var(--card-background); + border-radius: 8px; + box-shadow: 0 10px 40px -10px rgb(0 0 0 / 50%); + border: 1px solid var(--border-color); + overflow: hidden; + + @media (width >= 768px) { + width: var(--app-search-width-desktop) !important; // Match the search input exactly + } + + .p-popover-content { + padding: 0; + background: transparent; + border: none; + } + + .search-dropdown { + width: 100%; + + @media (width >= 768px) { + width: var(--app-search-width-desktop); + } + } +}