Skip to content

Commit ddfda4b

Browse files
fix(table): corrige truncamento e tooltip duplicado em colunas label
A coluna com tipo 'label' respeita o tamanho natural do componente 'po-tag' evitando truncamento do conteúdo e previne tooltip duplicado. Fixes DTHFUI-11180
1 parent c59c5f4 commit ddfda4b

6 files changed

Lines changed: 97 additions & 3 deletions

File tree

projects/ui/src/lib/components/po-table/interfaces/po-table-column.interface.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ export interface PoTableColumn {
274274
* - para colunas com 2 das propriedades (property, [p-draggable] e [p-sort]) : 96px
275275
* - para colunas com 3 propriedades (property, [p-draggable] e [p-sort]) : 144px
276276
*
277+
* Colunas do `type: 'label'` com `width` definido respeitam o tamanho natural do componente `po-tag`
278+
* (máximo de 240px), evitando truncamento do conteúdo. O `width` especificado funciona como
279+
* largura mínima, mas a coluna pode expandir até o limite do `po-tag` se o texto precisar de mais espaço.
277280
*/
278281
width?: string;
279282

projects/ui/src/lib/components/po-table/po-table.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@
382382
@for (column of mainColumns; track trackBy(columnIndex); let columnIndex = $index) {
383383
<td
384384
[style.width]="column.width"
385-
[style.max-width]="column.width"
385+
[style.max-width]="getColumnMaxWidth(column)"
386386
[style.min-width]="column.width"
387387
[class.po-table-column]="column.type !== 'icon'"
388388
[class.po-table-column-right]="column.type === 'currency' || column.type === 'number'"

projects/ui/src/lib/components/po-table/po-table.component.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,60 @@ describe('PoTableComponent:', () => {
12991299
expect(component.tooltipText).toBeUndefined();
13001300
});
13011301

1302+
it(`tooltipMouseEnter: should not set tooltipText for type 'label' even with overflow`, () => {
1303+
const fakeEvent = {
1304+
target: {
1305+
offsetWidth: 30,
1306+
scrollWidth: 43,
1307+
innerText: 'truncated label'
1308+
}
1309+
};
1310+
const column = { type: 'label', property: 'status', labels: [] };
1311+
1312+
component.tooltipMouseEnter(fakeEvent, column);
1313+
1314+
expect(component.tooltipText).toBeUndefined();
1315+
});
1316+
1317+
it(`tooltipMouseEnter: should set tooltipText for non-label types with overflow`, () => {
1318+
const fakeEvent = {
1319+
target: {
1320+
offsetWidth: 30,
1321+
scrollWidth: 43,
1322+
innerText: 'truncated text'
1323+
}
1324+
};
1325+
const column = { type: 'text', property: 'description' };
1326+
1327+
component.tooltipMouseEnter(fakeEvent, column);
1328+
1329+
expect(component.tooltipText).toBe('truncated text');
1330+
});
1331+
1332+
it(`getColumnMaxWidth: should return null for label columns with width`, () => {
1333+
const column = { type: 'label', width: '200px' };
1334+
1335+
const result = component.getColumnMaxWidth(column);
1336+
1337+
expect(result).toBeNull();
1338+
});
1339+
1340+
it(`getColumnMaxWidth: should return width for non-label columns`, () => {
1341+
const column = { type: 'text', width: '150px' };
1342+
1343+
const result = component.getColumnMaxWidth(column);
1344+
1345+
expect(result).toBe('150px');
1346+
});
1347+
1348+
it(`getColumnMaxWidth: should return width for label columns without width`, () => {
1349+
const column = { type: 'label' };
1350+
1351+
const result = component.getColumnMaxWidth(column);
1352+
1353+
expect(result).toBeUndefined();
1354+
});
1355+
13021356
it(`onOpenColumnManager: should update 'lastVisibleColumnsSelected' 'this.columns`, () => {
13031357
component.columns = columns;
13041358

projects/ui/src/lib/components/po-table/po-table.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,11 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
591591
tooltipMouseEnter(event: any, column?: PoTableColumn, row?: any) {
592592
this.tooltipText = undefined;
593593

594-
if (event.target.offsetWidth < event.target.scrollWidth && event.target.innerText.trim()) {
594+
if (
595+
column?.type !== 'label' &&
596+
event.target.offsetWidth < event.target.scrollWidth &&
597+
event.target.innerText.trim()
598+
) {
595599
return (this.tooltipText = event.target.innerText);
596600
}
597601

@@ -611,6 +615,13 @@ export class PoTableComponent extends PoTableBaseComponent implements AfterViewI
611615
this.poPopupComponent.toggle(row);
612616
}
613617

618+
getColumnMaxWidth(column: PoTableColumn): string {
619+
if (column.type === 'label' && column.width) {
620+
return null;
621+
}
622+
return column.width;
623+
}
624+
614625
trackBy(index: number) {
615626
return index;
616627
}

projects/ui/src/lib/components/po-tag/po-tag.component.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,31 @@ describe('PoTagComponent:', () => {
191191
component.value = 'Label';
192192
expect(component.setAriaLabel()).toContain('Label Remove');
193193
});
194+
195+
describe('getWidthTag:', () => {
196+
it('should return true when span scrollWidth is greater than container offsetWidth', () => {
197+
const mockSpan = { scrollWidth: 200 };
198+
const mockContainer = { firstElementChild: mockSpan, offsetWidth: 100 };
199+
component.tagContainer = { nativeElement: mockContainer } as any;
200+
201+
expect(component.getWidthTag()).toBe(true);
202+
});
203+
204+
it('should return false when span scrollWidth is less than or equal to container offsetWidth', () => {
205+
const mockSpan = { scrollWidth: 50 };
206+
const mockContainer = { firstElementChild: mockSpan, offsetWidth: 100 };
207+
component.tagContainer = { nativeElement: mockContainer } as any;
208+
209+
expect(component.getWidthTag()).toBe(false);
210+
});
211+
212+
it('should return false when firstElementChild is null', () => {
213+
const mockContainer = { firstElementChild: null, offsetWidth: 100 };
214+
component.tagContainer = { nativeElement: mockContainer } as any;
215+
216+
expect(component.getWidthTag()).toBe(false);
217+
});
218+
});
194219
});
195220

196221
describe('Templates:', () => {

projects/ui/src/lib/components/po-tag/po-tag.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ export class PoTagComponent extends PoTagBaseComponent implements OnInit {
151151
};
152152

153153
getWidthTag() {
154-
return this.tagContainer.nativeElement.offsetWidth > 155;
154+
const span = this.tagContainer.nativeElement.firstElementChild;
155+
return span ? span.scrollWidth > this.tagContainer.nativeElement.offsetWidth : false;
155156
}
156157

157158
setAriaLabel() {

0 commit comments

Comments
 (0)