Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(listbox): corrige posicionamento #1839

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,20 @@ export abstract class PoComboBaseComponent implements ControlValueAccessor, OnIn
*/
@Input({ alias: 'p-cache', transform: convertToBoolean }) cache: boolean = true;

/**
* @optional
*
* @description
*
* Define que o dropdown do combo será incluido no body da página e não suspenso com a caixa de texto do componente.
* Opção necessária para o caso de uso do componente em páginas que necessitam renderizar o combo fora do conteúdo principal.
*
* > Obs: O uso dessa propriedade pode acarretar na perda sequencial da tabulação da página
*
* @default `false`
*/
@Input({ alias: 'p-append-in-body', transform: convertToBoolean }) appendBox?: boolean = false;

constructor(languageService: PoLanguageService) {
this.language = languageService.getShortLanguage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,46 @@
</div>
</div>

<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="true">
<div #containerElement class="po-combo-container" [hidden]="!comboOpen && !isServerSearching">
<po-listbox
#poListbox
#contentElement
p-type="option"
[p-items]="visibleOptions"
[p-field-value]="dynamicValue"
[p-field-label]="dynamicLabel"
[p-template]="comboOptionTemplate"
[p-search-value]="getInputValue()"
[p-infinite-loading]="infiniteLoading"
[p-infinite-scroll]="infiniteScroll"
[p-filtering]="isFiltering"
[p-cache]="cache"
(p-selectcombo-item)="onOptionClick($event, $event.event)"
[p-filter-mode]="filterMode"
[p-visible]="comboOpen"
[p-is-searching]="isServerSearching"
[p-should-mark-letter]="shouldMarkLetters"
[p-compare-cache]="compareObjects(cacheOptions, visibleOptions)"
[p-combo-service]="service"
[p-infinite-scroll-distance]="infiniteScrollDistance"
(p-update-infinite-scroll)="showMoreInfiniteScroll()"
(p-close)="onCloseCombo()"
></po-listbox>
</div>
<ng-container *ngIf="appendBox; then dropdownCDK; else dropdownDefault"> </ng-container>

<ng-template #dropdownDefault>
<ng-container *ngTemplateOutlet="dropdownListbox"> </ng-container>
</ng-template>

<ng-template #dropdownCDK>
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="true">
<ng-container *ngTemplateOutlet="dropdownListbox"></ng-container>
</ng-template>
</ng-template>

<po-field-container-bottom [p-help]="help" [p-disabled]="disabled"></po-field-container-bottom>
</po-field-container>

<ng-template #dropdownListbox>
<div #containerElement class="po-combo-container" [hidden]="!comboOpen && !isServerSearching">
<po-listbox
#poListbox
#contentElement
p-type="option"
[p-items]="visibleOptions"
[p-field-value]="dynamicValue"
[p-field-label]="dynamicLabel"
[p-template]="comboOptionTemplate"
[p-search-value]="getInputValue()"
[p-infinite-loading]="infiniteLoading"
[p-infinite-scroll]="infiniteScroll"
[p-filtering]="isFiltering"
[p-cache]="cache"
(p-selectcombo-item)="onOptionClick($event, $event.event)"
[p-filter-mode]="filterMode"
[p-visible]="comboOpen"
[p-is-searching]="isServerSearching"
[p-should-mark-letter]="shouldMarkLetters"
[p-compare-cache]="compareObjects(cacheOptions, visibleOptions)"
[p-combo-service]="service"
[p-infinite-scroll-distance]="infiniteScrollDistance"
(p-update-infinite-scroll)="showMoreInfiniteScroll()"
(p-close)="onCloseCombo()"
></po-listbox>
</div>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ export abstract class PoMultiselectBaseComponent implements ControlValueAccessor
*/
@Output('p-change') change: EventEmitter<any> = new EventEmitter<any>();

/**
* @optional
*
* @description
*
* Define que o dropdown do multiselect será incluido no body da página e não suspenso com a caixa de texto do componente.
* Opção necessária para o caso de uso do componente em páginas que necessitam renderizar o multiselect fora do conteúdo principal.
*
* > Obs: O uso dessa propriedade pode acarretar na perda sequencial da tabulação da página
*
* @default `false`
*/
@Input({ alias: 'p-append-in-body', transform: convertToBoolean }) appendBox?: boolean = false;

selectedOptions: Array<PoMultiselectOption | any> = [];
visibleOptionsDropdown: Array<PoMultiselectOption | any> = [];
visibleDisclaimers = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
[p-required]="required"
[p-show-required]="showRequired"
>
<div class="po-field-container-content" [class.po-multiselect-show]="dropdownOpen">
<div
cdkOverlayOrigin
#trigger="cdkOverlayOrigin"
class="po-field-container-content"
[class.po-multiselect-show]="dropdownOpen"
>
<div
#inputElement
[tabindex]="disabled ? -1 : 0"
Expand Down Expand Up @@ -47,6 +52,22 @@
</div>
</div>

<ng-container *ngIf="appendBox; then dropdownCDK; else dropdownDefault"> </ng-container>

<ng-template #dropdownDefault>
<ng-container *ngTemplateOutlet="dropdownListbox"> </ng-container>
</ng-template>

<ng-template #dropdownCDK>
<ng-template cdkConnectedOverlay [cdkConnectedOverlayOrigin]="trigger" [cdkConnectedOverlayOpen]="true">
<ng-container *ngTemplateOutlet="dropdownListbox"></ng-container>
</ng-template>
</ng-template>

<po-field-container-bottom [p-help]="help" [p-disabled]="disabled"></po-field-container-bottom>
</po-field-container>

<ng-template #dropdownListbox>
<po-multiselect-dropdown
#dropdownElement
[p-searching]="isServerSearching"
Expand All @@ -65,6 +86,4 @@
(p-close-dropdown)="controlDropdownVisibility(false)"
>
</po-multiselect-dropdown>

<po-field-container-bottom [p-help]="help" [p-disabled]="disabled"></po-field-container-bottom>
</po-field-container>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ComponentFixture, fakeAsync, flush, TestBed } from '@angular/core/testi
import { HttpClient, HttpHandler } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { Observable, of, throwError } from 'rxjs';
import { OverlayModule } from '@angular/cdk/overlay';

import * as UtilsFunction from '../../../utils/util';

Expand Down Expand Up @@ -37,7 +38,7 @@ describe('PoMultiselectComponent:', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
imports: [HttpClientTestingModule, OverlayModule],
declarations: [
PoDisclaimerComponent,
PoFieldContainerComponent,
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('PoMultiselectComponent:', () => {
});

it('should call function wasClickedOnToggle', () => {
fixture.detectChanges();
component.openDropdown(true);
const documentBody = document.body;
const event = document.createEvent('MouseEvents');
Expand Down Expand Up @@ -232,15 +234,15 @@ describe('PoMultiselectComponent:', () => {
{ label: 'label2', value: 2 }
];
component.selectedOptions = [{ label: 'label2', value: 2 }];

fixture.detectChanges();
spyOn(component.dropdown, 'scrollTo');
component.scrollToSelectedOptions();
expect(component.dropdown.scrollTo).toHaveBeenCalledWith(1);
});

it('shouldn`t call dropdown.scrollTo', () => {
component.selectedOptions = [];

fixture.detectChanges();
spyOn(component.dropdown, 'scrollTo');
component.scrollToSelectedOptions();
expect(component.dropdown.scrollTo).not.toHaveBeenCalled();
Expand Down Expand Up @@ -268,7 +270,7 @@ describe('PoMultiselectComponent:', () => {

it('should call controlDropdownVisibility in wasClickedOnToggle', () => {
component.dropdownOpen = true;

fixture.detectChanges();
const event = document.createEvent('MouseEvents');
event.initEvent('click', false, true);

Expand Down Expand Up @@ -765,7 +767,7 @@ describe('PoMultiselectComponent:', () => {
call 'dropdown.controlVisibility' with 'false', 'setVisibleOptionsDropdown' with 'options' and 'removeListeners'.`, () => {
component.dropdownIcon = undefined;
component.dropdownOpen = undefined;

fixture.detectChanges();
const controlVisibilitySpy = spyOn(component.dropdown, 'controlVisibility');
const setVisibleOptionsDropdownSpy = spyOn(component, 'setVisibleOptionsDropdown');
const removeListenersSpy = spyOn(component, <any>'removeListeners');
Expand Down Expand Up @@ -834,7 +836,7 @@ describe('PoMultiselectComponent:', () => {
'initializeListeners', 'scrollToSelectedOptions', 'changeDetector.detectChanges' and 'setPositionDropdown'.`, () => {
component.dropdownIcon = undefined;
component.dropdownOpen = undefined;

fixture.detectChanges();
const controlVisibilitySpy = spyOn(component.dropdown, 'controlVisibility');
const setVisibleOptionsDropdownSpy = spyOn(component, 'setVisibleOptionsDropdown');
const initializeListenersSpy = spyOn(component, <any>'initializeListeners');
Expand Down Expand Up @@ -873,7 +875,7 @@ describe('PoMultiselectComponent:', () => {
const customPositions = ['top', 'bottom'];
const isSetElementWidth = true;
const poMultiselectContainerOffset = 8;

fixture.detectChanges();
const setElementsSpy = spyOn(component['controlPosition'], 'setElements');
const adjustContainerPositionSpy = spyOn(component, <any>'adjustContainerPosition');

Expand Down Expand Up @@ -1025,7 +1027,7 @@ describe('PoMultiselectComponent:', () => {
const wasClickedOnToggleSpy = spyOn(component, 'wasClickedOnToggle');

clickOutEvent();

fixture.detectChanges();
expect(wasClickedOnToggleSpy).not.toHaveBeenCalled();

component['open']();
Expand All @@ -1052,6 +1054,7 @@ describe('PoMultiselectComponent:', () => {
});

it(`open: should call 'wasClickedOnToggle' if dropdown list is opened and click window.`, () => {
fixture.detectChanges();
const wasClickedOnToggleSpy = spyOn(component, 'wasClickedOnToggle');

component['open']();
Expand All @@ -1061,15 +1064,17 @@ describe('PoMultiselectComponent:', () => {
});

it(`open: should call 'updateVisibleItems' if dropdown list is opened and resize window.`, () => {
const updateVisibleItemsSpy = spyOn(component, 'updateVisibleItems');
fixture.detectChanges();

const updateVisibleItemsSpy = spyOn(component, 'updateVisibleItems');
component['open']();
newEvent('resize');

expect(updateVisibleItemsSpy).toHaveBeenCalled();
});

it(`open: should call 'adjustContainerPosition' if dropdown list is opened and scroll window.`, () => {
fixture.detectChanges();
const adjustContainerPositionSpy = spyOn(component, <any>'adjustContainerPosition');

component['open']();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ export class PoMultiselectComponent
@ContentChild(PoMultiselectOptionTemplateDirective, { static: true })
multiselectOptionTemplate: PoMultiselectOptionTemplateDirective;

@ViewChild('dropdownElement', { read: ElementRef, static: true }) dropdownElement: ElementRef;
@ViewChild('dropdownElement', { static: true }) dropdown;
@ViewChild('dropdownElement', { read: ElementRef }) dropdownElement: ElementRef;
@ViewChild('dropdownElement') dropdown;
@ViewChild('iconElement', { read: ElementRef, static: true }) iconElement: ElementRef;
@ViewChild('inputElement', { read: ElementRef, static: true }) inputElement: ElementRef;

Expand Down