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
@@ -670,10 +670,10 @@
<span>{{ t('synopsisTitle') }}</span>
</div>
<div class="description-body">
<div [ngClass]="{ 'line-clamp-7': !isExpanded }" class="description-content">
<div #descriptionContent [ngClass]="{ 'line-clamp-7': !isExpanded }" class="description-content">
<div class="description-html" [innerHTML]="book.metadata!.description"></div>
</div>
@if (book.metadata!.description && book.metadata!.description.length > 500) {
@if (isExpanded || isOverflowing) {
<button class="expand-toggle" (click)="toggleExpand()">
{{ isExpanded ? t('showLess') : t('showMore') }}
<i class="pi" [ngClass]="isExpanded ? 'pi-chevron-up' : 'pi-chevron-down'"></i>
@@ -1,4 +1,4 @@
import {Component, DestroyRef, inject, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {AfterViewChecked, Component, DestroyRef, ElementRef, inject, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import {Button} from 'primeng/button';
import {AsyncPipe, DecimalPipe, NgClass} from '@angular/common';
import {combineLatest, Observable} from 'rxjs';
@@ -44,7 +44,7 @@ import {TranslocoDirective, TranslocoPipe, TranslocoService} from '@jsverse/tran
styleUrl: './metadata-viewer.component.scss',
imports: [Button, AsyncPipe, Rating, FormsModule, SplitButton, NgClass, Tooltip, DecimalPipe, ProgressBar, Menu, DatePicker, ProgressSpinner, TieredMenu, Image, TagComponent, MetadataTabsComponent, TranslocoDirective, TranslocoPipe]
})
export class MetadataViewerComponent implements OnInit, OnChanges {
export class MetadataViewerComponent implements OnInit, OnChanges, AfterViewChecked {
@Input() book$!: Observable<Book | null>;
@Input() recommendedBooks: BookRecommendation[] = [];
private originalRecommendedBooks: BookRecommendation[] = [];
@@ -70,7 +70,9 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
otherItems$!: Observable<MenuItem[]>;
downloadMenuItems$!: Observable<MenuItem[]>;
bookInSeries: Book[] = [];
@ViewChild('descriptionContent') descriptionContentRef?: ElementRef<HTMLElement>;
isExpanded = false;
isOverflowing = false;
isComicSectionExpanded = true;
isAudiobookSectionExpanded = true;
showFilePath = false;
@@ -460,6 +462,13 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
);
}
ngAfterViewChecked(): void {
if (!this.isExpanded && this.descriptionContentRef) {
const el = this.descriptionContentRef.nativeElement;
this.isOverflowing = el.scrollHeight > el.clientHeight;
}
}
toggleExpand(): void {
this.isExpanded = !this.isExpanded;
}