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:
+3
-4
@@ -24,10 +24,9 @@
|
||||
}
|
||||
</p-iconfield>
|
||||
|
||||
@if (books.length > 0 || searchQuery) {
|
||||
<p-popover #resultsPopover [appendTo]="'body'" [styleClass]="'search-results-popover'">
|
||||
<div
|
||||
class="search-dropdown layout-menu"
|
||||
[class.show]="isDropdownOpen"
|
||||
class="search-dropdown layout-menu show"
|
||||
>
|
||||
@if (isLoading) {
|
||||
@for (i of [1,2,3]; track i) {
|
||||
@@ -88,6 +87,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</p-popover>
|
||||
</div>
|
||||
</ng-container>
|
||||
|
||||
+30
-33
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user