Skip to content

Commit a5ebc3b

Browse files
Samir Hassan Ayoubalinelariguet
authored andcommitted
fix(modal): corrige fechamento da modal ao selecionar opção no combo
Adicionado stopPropagation ao selecionar uma opção do combo e definido evento mousedown para fechamento da modal Fixes DTHFUI-1421
1 parent ef47ca8 commit a5ebc3b

File tree

5 files changed

+48
-10
lines changed

5 files changed

+48
-10
lines changed

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<ul #contentElement class="po-combo-container-content">
5959
<li *ngFor="let option of visibleOptions"
6060
[class.po-combo-item-selected]="compareObjects(selectedView, option)"
61-
(click)="onOptionClick(option)">
61+
(click)="onOptionClick(option, $event)">
6262
<a class="po-combo-item" [innerHTML]="getLabelFormatted(option?.label)"></a>
6363
</li>
6464
</ul>

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,14 @@ describe('PoComboComponent:', () => {
466466

467467
describe('Methods:', () => {
468468

469+
const fakeEvent = {
470+
target: {
471+
value: 'ab'
472+
},
473+
preventDefault: () => {},
474+
stopPropagation: () => {}
475+
};
476+
469477
describe('onKeyUp:', () => {
470478

471479
function fakeKeypressEvent(code: number, target: any = 1) {
@@ -682,13 +690,6 @@ describe('PoComboComponent:', () => {
682690
});
683691

684692
describe('onKeyDown: ', () => {
685-
const fakeEvent = {
686-
target: {
687-
value: 'ab'
688-
},
689-
preventDefault: () => {},
690-
stopPropagation: () => {}
691-
};
692693

693694
it('should call `selectPreviousOption` and not call `selectNextOption`', () => {
694695
component.comboOpen = true;
@@ -913,6 +914,26 @@ describe('PoComboComponent:', () => {
913914

914915
});
915916

917+
it('onOptionClick: should call `stopPropagation` if has an event parameter', () => {
918+
const option: PoComboOption = { value: 'value', label: 'label' };
919+
920+
spyOn(fakeEvent, 'stopPropagation');
921+
922+
component.onOptionClick(option, fakeEvent);
923+
924+
expect(fakeEvent.stopPropagation).toHaveBeenCalled();
925+
});
926+
927+
it('onOptionClick: shouldn`t call `stopPropagation` if doesn`t have an event parameter', () => {
928+
const option: PoComboOption = { value: 'value', label: 'label' };
929+
930+
spyOn(fakeEvent, 'stopPropagation');
931+
932+
component.onOptionClick(option);
933+
934+
expect(fakeEvent.stopPropagation).not.toHaveBeenCalled();
935+
});
936+
916937
it('onOptionClick: should call `updateSelectedValue` and `updateComboList` when `option.value` different than `selectedValue`', () => {
917938
const option: PoComboOption = { value: 'value', label: 'label' };
918939
component.selectedValue = 'different value';

projects/ui/src/lib/components/po-field/po-combo/po-combo.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,14 @@ export class PoComboComponent extends PoComboBaseComponent implements DoCheck, O
395395
toOpen ? this.open() : this.close();
396396
}
397397

398-
onOptionClick(option: PoComboOption) {
398+
onOptionClick(option: PoComboOption, event?: any) {
399399
const inputValue = this.getInputValue();
400400
const isUpdateModel = (option.value !== this.selectedValue) || !!(this.selectedView && inputValue !== this.selectedView.label);
401401

402+
if (event) {
403+
event.stopPropagation();
404+
}
405+
402406
this.updateSelectedValue(option, isUpdateModel);
403407
this.controlComboVisibility(false);
404408
this.updateComboList([{ ...this.selectedView }]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
(keydown.esc)="closeModalOnEscapeKey($event)">
55

66
<div class="po-modal-overlay">
7-
<div class="po-modal-container po-pb-2 po-pt-2" (click)="onClickOut($event)">
7+
<div class="po-modal-container po-pb-2 po-pt-2" (mousedown)="onClickOut($event)">
88

99
<div class="po-modal-vertical-align">
1010
<div #modalContent

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,19 @@ describe('PoModalComponent:', () => {
507507
expect(getModalActionDisabled()).toBeTruthy();
508508
expect(getModalActionIconLoading()).toBeTruthy();
509509
});
510+
511+
it('should call `onClickOut` on mousedown', () => {
512+
component.open();
513+
fixture.detectChanges();
514+
515+
const containerElement = fixture.debugElement.query(By.css('.po-modal-container')).nativeElement;
516+
517+
spyOn(component, 'onClickOut');
518+
519+
containerElement.dispatchEvent(new Event('mousedown'));
520+
521+
expect(component.onClickOut).toHaveBeenCalled();
522+
});
510523
});
511524

512525
});

0 commit comments

Comments
 (0)