Skip to content

Commit bac330f

Browse files
fix(dropdown): corrige fluxo de encerramento e restaura foco
Evita chamadas indevidas de close no popup e garante que o foco retorne ao elemento do dropdown após o fechamento. Torna o método `hideDropdown` acessível a subclasses e adiciona listener de fechamento `(p-close)="hideDropdown()"` no template para manter o estado consistente. Fixes DTHFUI-11656
1 parent 772cb7f commit bac330f

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
[p-custom-positions]="['bottom-left', 'top-left']"
2727
[p-size]="size"
2828
[p-target]="dropdownRef"
29+
(p-close)="hideDropdown()"
2930
>
3031
</po-popup>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,13 @@ describe('PoDropdownComponent: ', () => {
129129
icon: undefined,
130130
removeListeners: jasmine.createSpy('removeListeners'),
131131
popupRef: {
132-
close: jasmine.createSpy('close')
132+
close: jasmine.createSpy('close'),
133+
showPopup: true
134+
},
135+
dropdownRef: {
136+
nativeElement: {
137+
focus: jasmine.createSpy('focus')
138+
}
133139
},
134140
open: undefined,
135141
changeDetector: {
@@ -142,6 +148,7 @@ describe('PoDropdownComponent: ', () => {
142148
expect(fakeThis.icon).toBe('ICON_ARROW_DOWN');
143149
expect(fakeThis.removeListeners).toHaveBeenCalled();
144150
expect(fakeThis.popupRef.close).toHaveBeenCalled();
151+
expect(fakeThis.dropdownRef.nativeElement.focus).toHaveBeenCalled();
145152
expect(fakeThis.open).toBe(false);
146153
expect(fakeThis.changeDetector.detectChanges).toHaveBeenCalled();
147154
});

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ export class PoDropdownComponent extends PoDropdownBaseComponent {
6060
return this.dropdownRef && this.dropdownRef.nativeElement.contains(event.target);
6161
}
6262

63-
private hideDropdown() {
63+
protected hideDropdown() {
6464
this.icon = 'ICON_ARROW_DOWN';
6565
this.removeListeners();
66-
this.popupRef.close();
66+
if (this.popupRef.showPopup) {
67+
this.popupRef.close();
68+
}
69+
this.dropdownRef.nativeElement.focus();
6770
this.open = false;
6871
this.changeDetector.detectChanges();
6972
}

0 commit comments

Comments
 (0)