From 1799493ed78ef0e24530260127de99df5ba29a28 Mon Sep 17 00:00:00 2001 From: Sergio Visinoni Date: Sun, 29 Mar 2026 19:14:46 +0200 Subject: [PATCH] fix: fix text overflow with attach-to-book flow when dealing with long titles (#265) * Measure the actual rendered pixel width of the autocomplete wrapper div * Use the calculated measure to style the component, overriding the PrimeNG default styles * Add CSS attributes to ensure long titles are truncated with ellipses if they overflow --- .../book-file-attacher.component.html | 175 ++++++++---------- .../book-file-attacher.component.scss | 12 +- .../book-file-attacher.component.ts | 20 +- 3 files changed, 103 insertions(+), 104 deletions(-) diff --git a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.html b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.html index ce52f0e86..8c12ca262 100644 --- a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.html +++ b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.html @@ -1,118 +1,95 @@ -
-
-
- +
+
+
+ +
+
+

{{ isBulkMode ? t('titleBulk') : t('title') }}

+

{{ isBulkMode ? t('descriptionBulk') : t('description') }}

+
+ +
-
-

{{ isBulkMode ? t('titleBulk') : t('title') }}

-

{{ isBulkMode ? t('descriptionBulk') : t('description') }}

-
- - -
-
- -
-

{{ isBulkMode ? t('sourceBooksLabel', { count: sourceBooks.length }) : t('sourceBookLabel', { count: sourceBooks.length }) }}

-
- @for (book of sourceBooks; track book.id) { +
+ +
+

{{ isBulkMode ? t('sourceBooksLabel', { count: sourceBooks.length }) : + t('sourceBookLabel', { count: sourceBooks.length }) }}

+
+ @for (book of sourceBooks; track book.id) {
{{ book.metadata?.title || t('unknownTitle') }}
@if (book.metadata?.authors?.length) { -
{{ book.metadata?.authors?.join(', ') }}
+
{{ book.metadata?.authors?.join(', ') }}
}
{{ getSourceFileInfo(book) }}
- } + } +
-
- -
-

{{ t('selectTargetBook') }}

- - -
-
{{ book.metadata?.title || t('unknownTitle') }}
- @if (book.metadata?.authors?.length) { + +
+

{{ t('selectTargetBook') }}

+ + +
+
{{ book.metadata?.title || t('unknownTitle') }}
+ @if (book.metadata?.authors?.length) {
{{ book.metadata.authors.join(', ') }}
- } - @if (book.primaryFile) { -
{{ book.primaryFile.extension?.toUpperCase() || book.primaryFile.bookType }}
- } -
-
- - {{ getBookDisplayName(book) }} - -
-
- - -
- - - -
- - -
- -
- @if (moveFiles) { -

{{ isBulkMode ? t('warningMoveBulk') : t('warningMove') }}

- } @else { -

{{ isBulkMode ? t('warningNoMoveBulk') : t('warningNoMove') }}

- } -

{{ isBulkMode ? t('warningDeleteBulk') : t('warningDelete') }}

+ } + @if (book.primaryFile) { +
{{ book.primaryFile.extension?.toUpperCase() || book.primaryFile.bookType + }}
+ } +
+ + + {{ getBookDisplayName(book) }} + +
-
- -
- - - - + +
+ + + +
+ + +
+ +
+ @if (moveFiles) { +

{{ isBulkMode ? t('warningMoveBulk') : t('warningMove') }}

+ } @else { +

{{ isBulkMode ? t('warningNoMoveBulk') : t('warningNoMove') }}

+ } +

{{ isBulkMode ? t('warningDeleteBulk') : t('warningDelete') }}

+
+
+ + +
+ + + + +
-
- + \ No newline at end of file diff --git a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.scss b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.scss index 7a9183101..0c81e82d4 100644 --- a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.scss +++ b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.scss @@ -100,15 +100,22 @@ .book-suggestion { padding: 0.25rem 0; + overflow: hidden; .suggestion-title { font-weight: 500; margin-bottom: 0.125rem; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } .suggestion-authors { font-size: 0.875rem; color: var(--p-text-muted-color); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } .suggestion-format { @@ -116,6 +123,9 @@ color: var(--p-primary-color); font-weight: 600; margin-top: 0.25rem; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } } @@ -178,4 +188,4 @@ gap: 0.75rem; margin-top: auto; padding-top: 0.5rem; -} +} \ No newline at end of file diff --git a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.ts b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.ts index 1646c3b8b..4d5b92fdf 100644 --- a/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.ts +++ b/frontend/src/app/features/book/components/book-file-attacher/book-file-attacher.component.ts @@ -1,4 +1,4 @@ -import { Component, computed, inject, OnInit, OnDestroy, Signal, signal } from '@angular/core'; +import { Component, computed, inject, OnInit, OnDestroy, AfterViewInit, ElementRef, ViewChild, Signal, signal } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { DynamicDialogRef, DynamicDialogConfig } from 'primeng/dynamicdialog'; import { AutoComplete, AutoCompleteSelectEvent } from 'primeng/autocomplete'; @@ -8,7 +8,7 @@ import { Subject, takeUntil } from 'rxjs'; import { BookService } from '../../service/book.service'; import { BookFileService } from '../../service/book-file.service'; import { Book } from '../../model/book.model'; -import {MessageService, PrimeTemplate} from 'primeng/api'; +import { MessageService, PrimeTemplate } from 'primeng/api'; import { TranslocoDirective, TranslocoPipe, TranslocoService } from '@jsverse/transloco'; import { AppSettingsService } from '../../../../shared/service/app-settings.service'; @@ -27,13 +27,16 @@ import { AppSettingsService } from '../../../../shared/service/app-settings.serv templateUrl: './book-file-attacher.component.html', styleUrls: ['./book-file-attacher.component.scss'] }) -export class BookFileAttacherComponent implements OnInit, OnDestroy { +export class BookFileAttacherComponent implements OnInit, AfterViewInit, OnDestroy { + @ViewChild('autocompleteWrapper') autocompleteWrapper!: ElementRef; + sourceBooks: Book[] = []; targetBook: Book | null = null; moveFiles = false; isAttaching = false; searchQuery = ''; filteredBooks: Book[] = []; + autocomplePanelStyle: Record = {}; private destroy$ = new Subject(); private allBooks: Signal = signal([]); @@ -46,6 +49,15 @@ export class BookFileAttacherComponent implements OnInit, OnDestroy { private bookFileService = inject(BookFileService); private messageService = inject(MessageService); + ngAfterViewInit(): void { + setTimeout(() => { + const width = this.autocompleteWrapper?.nativeElement?.offsetWidth; + if (width) { + this.autocomplePanelStyle = { 'width': `${width}px`, 'max-width': `${width}px` }; + } + }); + } + ngOnInit(): void { // Support both single book and multiple books if (this.config.data.sourceBook) { @@ -86,7 +98,7 @@ export class BookFileAttacherComponent implements OnInit, OnDestroy { return this.sourceBooks.length > 1; } - filterBooks(event: { query: string }): void { + filterBooks(event: { query: string; }): void { const query = event.query.toLowerCase().trim(); const books = this.allBooks(); if (!query) {