Skip to content

Commit

Permalink
feat(search): inclusão do listbox ao fazer o search
Browse files Browse the repository at this point in the history
Implementação da propriedade 't-show-listbox'.
Com essa propriedade ativa, sempre ira mostrar uma listbox das opções informadas, quando
houver mudança no input. ela também obedece a regra do filterKeys

fixes DTHFUI-7812
  • Loading branch information
bruno-severino authored and anderson-gregorio-totvs committed Apr 22, 2024
1 parent f80d1b7 commit 60711b3
Show file tree
Hide file tree
Showing 11 changed files with 861 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @usedBy PoSearchComponent
*
* @description
*
* Interface que define as opções que serão exibidas na lista ao procurar do `po-search`.
*/
export interface PoSearchOption {
/**
* @optional
*
* @description
*
* Descrição exibida nas opções da lista.
*
* > Caso não seja definida será assumido o valor definido na propriedade `value`.
*/
label?: string;

/** Valor do objeto que será atribuído ao *model*. */
value: string | number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@ export class PoSearchBaseComponent {
*/
@Input('p-filter-type') filterType: PoSearchFilterMode = PoSearchFilterMode.startsWith;

/**
* @optional
*
* @description
*
* Exibe uma lista (auto-complete) com as opções definidas no `p-filter-keys` enquanto realiza uma busca,
* respeitando o `p-filter-type` como modo de pesquisa.
*
* @default `false`
*/
@Input('p-show-listbox') showListbox: boolean = false;

/**
* @optional
*
Expand Down Expand Up @@ -226,6 +238,15 @@ export class PoSearchBaseComponent {
*/
@Output('p-filter') filter: EventEmitter<any> = new EventEmitter<any>();

/**
* @optional
*
* @description
*
* Pode ser informada uma função que será disparada quando houver click no listbox.
*/
@Output('p-listbox-onclick') listboxOnClick = new EventEmitter<any>();

constructor(languageService: PoLanguageService) {
this.language = languageService.getShortLanguage();
}
Expand Down
31 changes: 27 additions & 4 deletions projects/ui/src/lib/components/po-search/po-search.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@
[class.po-search-input-trigger]="type === 'trigger'"
[disabled]="disabled"
[placeholder]="literals.search"
(input)="onSearchChange($event.target.value, type === 'action' ? true : false)"
(keyup.enter)="onSearchChange($event.target.value, type === 'trigger' ? true : false)"
(input)="
onSearchChange($event.target.value, false); onSearchChange($event.target.value, type === 'action' ? true : false)
"
(keyup.enter)="
listboxOpen ? closeListbox() : onSearchChange($event.target.value, type === 'trigger' ? true : false, true);
closeListbox()
"
(keydown)="onKeyDown($event)"
(blur)="onBlur()"
/>

<div class="po-search-buttons">
Expand All @@ -33,11 +40,27 @@
class="po-search-button po-search-button-trigger"
type="button"
[ariaLabel]="literals.search"
(click)="onSearchChange(poSearchInput.value, true)"
(keydown.enter)="onSearchChange(poSearchInput.value, true)"
(click)="onSearchChange(poSearchInput.value, true, true)"
(keydown.enter)="onSearchChange(poSearchInput.value, true, true)"
[disabled]="disabled"
>
<po-icon [p-icon]="icon ? icon : 'po-icon-search'"> </po-icon>
</button>
</div>
</div>

<div #poListboxContainerElement class="po-search-listbox-container" [hidden]="!listboxOpen">
<po-listbox
#poListbox
#poListboxElement
p-type="option"
[p-items]="listboxFilteredItems"
(p-selectcombo-item)="onListboxClick($event, $event.event)"
[p-visible]="listboxOpen"
[p-filter-mode]="filterType"
[p-should-mark-letter]="shouldMarkLetters"
[p-filtering]="isFiltering"
[p-search-value]="getInputValue()"
(p-close)="onCloseListbox()"
></po-listbox>
</div>
Loading

0 comments on commit 60711b3

Please sign in to comment.