Skip to content

Commit 7bb55ba

Browse files
committed
fix(tabs): corrige emissão de evento p-click
Corrige a emissão do Output p-click para disparar corretamente. fixes DTHFUI-9176
1 parent 310d407 commit 7bb55ba

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('PoTabsComponent:', () => {
6161

6262
component['tabsService'].triggerActiveOnChanges(tabMock);
6363

64-
expect(component.onTabActiveByDropdown).toHaveBeenCalledWith(tabMock);
64+
expect(component.onTabActiveByDropdown).toHaveBeenCalledWith(tabMock, false);
6565
});
6666

6767
it('ngOnInit: should unsubscribe', () => {
@@ -518,6 +518,7 @@ describe('PoTabsComponent:', () => {
518518

519519
it('onTabActiveByDropdown: should correctly call methods and update styles when called', () => {
520520
const tabMock = jasmine.createSpyObj('PoTabComponent', ['id'], { id: 'tab-id' });
521+
tabMock.click = { emit: () => {} };
521522
component.defaultLastTabWidth = 100;
522523

523524
const nativeElementMock = { style: { width: '' }, getBoundingClientRect: () => ({ width: 100 }) };
@@ -531,10 +532,12 @@ describe('PoTabsComponent:', () => {
531532
component.tabsDefault = [tabMock];
532533
component.tabsDropdown = [tabMock];
533534

535+
spyOn(tabMock.click, 'emit');
534536
spyOn(component, 'handleKeyboardNavigationTab');
535537

536538
component.onTabActiveByDropdown(tabMock);
537539

540+
expect(tabMock.click.emit).toHaveBeenCalledWith(tabMock);
538541
expect(component.tabButton.last.nativeElement.style.width).toBe('100px');
539542
expect(component.handleKeyboardNavigationTab).toHaveBeenCalled();
540543
expect(component.tabsDefault.includes(tabMock)).toBe(true);
@@ -543,6 +546,7 @@ describe('PoTabsComponent:', () => {
543546

544547
it('reorderTabs: should reorder tabs if tabIndex is not -1', () => {
545548
const tabMock = jasmine.createSpyObj('PoTabComponent', ['id'], { id: 'tab4', widthButton: '130' });
549+
tabMock.click = { emit: () => {} };
546550
const tabsArrayMock = [
547551
jasmine.createSpyObj('PoTabComponent', ['id'], { id: 'tab1', widthButton: '100' }),
548552
jasmine.createSpyObj('PoTabComponent', ['id'], { id: 'tab2', widthButton: '110' }),
@@ -556,6 +560,7 @@ describe('PoTabsComponent:', () => {
556560

557561
component.quantityTabsButton = 3;
558562

563+
spyOn(tabMock.click, 'emit');
559564
spyOn(component, <any>'changeTabPositionByDropdown').and.callFake((tab: PoTabComponent) => {
560565
const tabIndex = component.tabsChildren.toArray().indexOf(tab);
561566
if (tabIndex !== -1) {
@@ -572,6 +577,7 @@ describe('PoTabsComponent:', () => {
572577

573578
const reorderedTabs = component.tabsChildren.toArray();
574579

580+
expect(tabMock.click.emit).toHaveBeenCalledWith(tabMock);
575581
expect(reorderedTabs.map(tab => tab.id)).toEqual(['tab1', 'tab2', 'tab4', 'tab3']);
576582
expect(component.tabButton.last.nativeElement.style.width).toBe('130px');
577583
});

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class PoTabsComponent extends PoTabsBaseComponent implements OnInit, Afte
112112
this.subscriptionTabActive = this.tabsService.triggerActiveOnChanges$.subscribe(tab => {
113113
const isTabInDropdown = this.tabsDropdown.some(t => t.id === tab.id);
114114
if (isTabInDropdown) {
115-
this.onTabActiveByDropdown(tab);
115+
this.onTabActiveByDropdown(tab, false);
116116
}
117117
});
118118
}
@@ -166,7 +166,7 @@ export class PoTabsComponent extends PoTabsBaseComponent implements OnInit, Afte
166166
return !tab.hide;
167167
}
168168

169-
onTabActiveByDropdown(tab: PoTabComponent): void {
169+
onTabActiveByDropdown(tab: PoTabComponent, eventEmitter = true): void {
170170
this.changeTabPositionByDropdown(tab);
171171
const lastTabWidth =
172172
this.defaultLastTabWidth > 0
@@ -177,6 +177,10 @@ export class PoTabsComponent extends PoTabsBaseComponent implements OnInit, Afte
177177
tab.widthButton = lastTabWidth;
178178
this.tabButton.last.nativeElement.style.width = `${lastTabWidth}px`;
179179
this.handleKeyboardNavigationTab();
180+
181+
if (eventEmitter) {
182+
tab.click.emit(tab);
183+
}
180184
}
181185

182186
// Função disparada quando alguma tab ficar ativa

0 commit comments

Comments
 (0)