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
This commit is contained in:
brios
2026-04-22 17:27:01 -04:00
committed by Zach Yale
parent 64083fe9b7
commit a176be3e74
5 changed files with 83 additions and 43 deletions
@@ -24,10 +24,9 @@
} }
</p-iconfield> </p-iconfield>
@if (books.length > 0 || searchQuery) { <p-popover #resultsPopover [appendTo]="'body'" [styleClass]="'search-results-popover'">
<div <div
class="search-dropdown layout-menu" class="search-dropdown layout-menu show"
[class.show]="isDropdownOpen"
> >
@if (isLoading) { @if (isLoading) {
@for (i of [1,2,3]; track i) { @for (i of [1,2,3]; track i) {
@@ -88,6 +87,6 @@
</div> </div>
} }
</div> </div>
} </p-popover>
</div> </div>
</ng-container> </ng-container>
@@ -6,27 +6,30 @@
@media (width >= 768px) { @media (width >= 768px) {
margin-left: 1.25rem; margin-left: 1.25rem;
max-width: 315px; width: var(--app-search-width-desktop);
transition: max-width 0.3s ease; max-width: 100%;
} transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
&:has(.search-iconfield.focused),
&:has(.search-iconfield.has-results) {
@media (width >= 768px) {
max-width: 100%;
}
} }
} }
// Popover styles moved to global src/styles.scss due to appendTo="body"
.search-iconfield { .search-iconfield {
width: 100%; width: 100%;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
border-radius: 8px;
@media (width >= 640px) { @media (width >= 640px) {
display: flex; display: flex;
} }
@media (width >= 768px) { &.focused {
transition: all 0.3s ease; 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; height: 2.5rem;
line-height: 2.5rem; line-height: 2.5rem;
font-size: 1rem; 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 { .clear-search-btn {
@@ -51,24 +62,14 @@
} }
.search-dropdown { .search-dropdown {
position: absolute;
top: calc(100% + 0.5rem);
left: 0;
width: 100%; width: 100%;
max-width: 600px; background: transparent; // Glassmorphism handled by parent .search-results-popover
background-color: var(--card-background); border: none;
border: 1px solid var(--border-color);
border-radius: 8px; 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)); max-height: min(70vh, calc(100dvh - 4rem));
overflow-y: auto; overflow-y: auto;
opacity: 0;
height: 0; // Desktop width constraints moved to src/styles.scss for body-appended elements
transform: translateY(-10px);
transition: opacity 0.2s ease, transform 0.2s ease, height 0.2s ease;
&::-webkit-scrollbar { &::-webkit-scrollbar {
width: 8px; width: 8px;
@@ -88,11 +89,7 @@
} }
} }
.search-dropdown.show { // .show class no longer needed as popover handles visibility
opacity: 1;
height: auto;
transform: translateY(0);
}
.search-dropdown-item { .search-dropdown-item {
display: flex; display: flex;
@@ -160,12 +157,12 @@
font-weight: 600; font-weight: 600;
font-size: 0.95rem; font-size: 0.95rem;
line-height: 1.4; line-height: 1.4;
color: var(--text-color);
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box; display: -webkit-box;
-webkit-line-clamp: 2; -webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical; -webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
overflow-wrap: anywhere; overflow-wrap: anywhere;
margin: 0; margin: 0;
} }
@@ -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 {toObservable, toSignal} from '@angular/core/rxjs-interop';
import {debounceTime, distinctUntilChanged} from 'rxjs/operators'; import {debounceTime, distinctUntilChanged} from 'rxjs/operators';
import {Book} from '../../model/book.model'; import {Book} from '../../model/book.model';
@@ -15,6 +15,7 @@ import {IconField} from 'primeng/iconfield';
import {InputIcon} from 'primeng/inputicon'; import {InputIcon} from 'primeng/inputicon';
import {filterBooksBySearchTerm} from '../book-browser/filters/HeaderFilter'; import {filterBooksBySearchTerm} from '../book-browser/filters/HeaderFilter';
import {TranslocoDirective, TranslocoService} from '@jsverse/transloco'; import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {Popover} from 'primeng/popover';
@Component({ @Component({
selector: 'app-book-searcher', selector: 'app-book-searcher',
@@ -29,6 +30,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
InputIcon, InputIcon,
TranslocoDirective, TranslocoDirective,
CoverPlaceholderComponent, CoverPlaceholderComponent,
Popover,
], ],
styleUrls: ['./book-searcher.component.scss'], styleUrls: ['./book-searcher.component.scss'],
standalone: true standalone: true
@@ -61,6 +63,8 @@ export class BookSearcherComponent {
private readonly t = inject(TranslocoService); private readonly t = inject(TranslocoService);
private elRef = inject(ElementRef); private elRef = inject(ElementRef);
@ViewChild('resultsPopover') resultsPopover?: Popover;
get books(): Book[] { get books(): Book[] {
return this.filteredBooks(); return this.filteredBooks();
} }
@@ -91,6 +95,19 @@ export class BookSearcherComponent {
onSearchInputChange(): void { onSearchInputChange(): void {
this.searchTerm.set(this.searchQuery.trim()); this.searchTerm.set(this.searchQuery.trim());
this.activeIndex = -1; 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 { onBookClick(book: Book): void {
@@ -104,6 +121,7 @@ export class BookSearcherComponent {
this.searchQuery = ''; this.searchQuery = '';
this.searchTerm.set(''); this.searchTerm.set('');
this.activeIndex = -1; this.activeIndex = -1;
this.resultsPopover?.hide();
} }
get isDropdownOpen(): boolean { get isDropdownOpen(): boolean {
@@ -19,7 +19,6 @@
// RTL reading mode - reverse page order in two-page view // RTL reading mode - reverse page order in two-page view
&.rtl-reading { &.rtl-reading {
.two-page-view { .two-page-view {
.pages-wrapper, .pages-wrapper,
.previous-page-layer, .previous-page-layer,
.current-page-layer { .current-page-layer {
@@ -190,7 +189,6 @@
} }
&.fit-width { &.fit-width {
.pages-wrapper, .pages-wrapper,
.previous-page-layer, .previous-page-layer,
.current-page-layer { .current-page-layer {
@@ -208,7 +206,6 @@
} }
&.two-page-view { &.two-page-view {
.pages-wrapper, .pages-wrapper,
.previous-page-layer, .previous-page-layer,
.current-page-layer { .current-page-layer {
@@ -225,7 +222,6 @@
} }
&.fit-height { &.fit-height {
.pages-wrapper, .pages-wrapper,
.previous-page-layer, .previous-page-layer,
.current-page-layer { .current-page-layer {
@@ -660,7 +656,6 @@
// Emulate book mode spine shadow in two-page view // Emulate book mode spine shadow in two-page view
.image-container.emulate-book { .image-container.emulate-book {
.pages-wrapper, .pages-wrapper,
.current-page-layer { .current-page-layer {
position: relative; position: relative;
+31
View File
@@ -24,6 +24,9 @@ html {
--book-type-m4a-color: #f43f5e; --book-type-m4a-color: #f43f5e;
--book-type-opus-color: #06b6d4; --book-type-opus-color: #06b6d4;
--book-type-physical-color: #8b5cf6; --book-type-physical-color: #8b5cf6;
// Search Context
--app-search-width-desktop: 450px;
} }
* { * {
@@ -84,3 +87,31 @@ html {
top: auto !important; top: auto !important;
bottom: 0; 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);
}
}
}