Auto-expand first active filter panel or default to first
This commit is contained in:
committed by
Aditya Chandel
parent
7053cfa963
commit
68dce9bd23
@@ -635,6 +635,7 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
|
||||
|
||||
this.selectedFilter.next(parsedFilters);
|
||||
this.bookFilterComponent.setFilters?.(parsedFilters);
|
||||
this.bookFilterComponent.onFiltersChanged?.();
|
||||
|
||||
const firstFilter = filterParams.split(',')[0];
|
||||
const [key, ...values] = firstFilter.split(':');
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
allowEmpty="false"
|
||||
styleClass="h-8"></p-selectButton>
|
||||
</div>
|
||||
<p-accordion [value]="0">
|
||||
<p-accordion [value]="expandedPanels">
|
||||
@for (filterType of filterTypes; track filterType; let i = $index) {
|
||||
<p-accordion-panel [value]="i">
|
||||
<p-accordion-header>
|
||||
|
||||
+14
-2
@@ -135,7 +135,7 @@ export class BookFilterComponent implements OnInit {
|
||||
{label: 'OR', value: 'or'}
|
||||
];
|
||||
private _selectedFilterMode: 'and' | 'or' = 'and';
|
||||
|
||||
expandedPanels: number = 0;
|
||||
readonly filterLabels: Record<string, string> = {
|
||||
author: 'Author',
|
||||
category: 'Category',
|
||||
@@ -175,6 +175,8 @@ export class BookFilterComponent implements OnInit {
|
||||
if (this.resetFilter$) {
|
||||
this.resetFilter$.subscribe(() => this.clearActiveFilter());
|
||||
}
|
||||
|
||||
this.setExpandedPanels();
|
||||
}
|
||||
|
||||
private getFilterStream<T>(
|
||||
@@ -255,7 +257,6 @@ export class BookFilterComponent implements OnInit {
|
||||
this.activeFilters[key] = [value];
|
||||
}
|
||||
}
|
||||
|
||||
this.filterSelected.emit({...this.activeFilters});
|
||||
}
|
||||
|
||||
@@ -263,4 +264,15 @@ export class BookFilterComponent implements OnInit {
|
||||
this.activeFilters = {};
|
||||
this.filterSelected.emit(null);
|
||||
}
|
||||
|
||||
setExpandedPanels(): void {
|
||||
const firstActiveIndex = this.filterTypes.findIndex(
|
||||
type => this.activeFilters[type]?.length
|
||||
);
|
||||
this.expandedPanels = firstActiveIndex !== -1 ? firstActiveIndex : 0;
|
||||
}
|
||||
|
||||
onFiltersChanged(): void {
|
||||
this.setExpandedPanels();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user