fix: hide show-more button when description fits without truncation (#2766)

This commit is contained in:
ACX
2026-02-15 11:57:56 -07:00
committed by GitHub
parent 2c391cb1f4
commit 1cc30af7d9
4 changed files with 26 additions and 9 deletions
@@ -77,13 +77,12 @@
<!-- DESCRIPTION -->
<div class="description-box">
<div [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }"
<div #descriptionContent [ngClass]="{ 'line-clamp-5': !isExpanded, 'line-clamp-none': isExpanded }"
class="description-container">
<div class="readonly-editor"
[innerHTML]="(firstDescription$ | async) || t('noDescription')"></div>
</div>
@let desc = firstDescription$ | async;
@if ((desc?.length ?? 0) > 500) {
@if (isExpanded || isOverflowing) {
<p-button [label]="isExpanded ? t('showLess') : t('showMore')"
[icon]="isExpanded ? 'pi pi-chevron-up' : 'pi pi-chevron-down'" iconPos="right" size="small" text
(click)="toggleExpand()">
@@ -27,7 +27,7 @@ import {TranslocoDirective, TranslocoService} from '@jsverse/transloco';
import {Tooltip} from "primeng/tooltip";
import {Divider} from "primeng/divider";
import {animate, style, transition, trigger} from "@angular/animations";
import {Component, inject, OnDestroy} from '@angular/core';
import {AfterViewChecked, Component, ElementRef, inject, OnDestroy, ViewChild} from '@angular/core';
import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overlay-preference.service';
@Component({
@@ -68,7 +68,7 @@ import {BookCardOverlayPreferenceService} from '../book-browser/book-card-overla
])
]
})
export class SeriesPageComponent implements OnDestroy {
export class SeriesPageComponent implements OnDestroy, AfterViewChecked {
private route = inject(ActivatedRoute);
private bookService = inject(BookService);
@@ -88,8 +88,10 @@ export class SeriesPageComponent implements OnDestroy {
protected appSettingsService = inject(AppSettingsService);
private readonly t = inject(TranslocoService);
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
tab: string = "view";
isExpanded = false;
isOverflowing = false;
// Selection state
selectedBooks = new Set<number>();
@@ -268,6 +270,13 @@ export class SeriesPageComponent implements OnDestroy {
}
}
ngAfterViewChecked(): void {
if (!this.isExpanded && this.descriptionContentRef) {
const el = this.descriptionContentRef.nativeElement;
this.isOverflowing = el.scrollHeight > el.clientHeight;
}
}
toggleExpand(): void {
this.isExpanded = !this.isExpanded;
}