Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 7511454

Browse files
committed
Allow the consumer to override the default debounce
On one particular page, we're getting a request to extend the debounce time before performing a search. Instead of necessarily changing this across the board, I'm just going to give us the ability to pass in a custom debounce time. If present, this should always be used.
1 parent 440b6c4 commit 7511454

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

bootstrapper/inputs/inputsNg2.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ <h3><a href="https://github.com/SamGraber/TypeScript-Angular-Components/blob/mas
4444
<template let-option>Value - {{option.value}}</template>
4545
</rlTypeahead>
4646
<rlTypeahead [(value)]="typeaheadSelection" prefix="Search for a" label="Typeahead with create" [getItems]="getOptions" clientSearch="true" transform="value" [create]="createOption" allowCollapse="true"></rlTypeahead>
47+
<rlTypeahead [(value)]="typeaheadSelection" prefix="Search for a" label="Typeahead long debounce" [getItems]="searchOptions" transform="value" allowCollapse="true" [debounce]="10000"></rlTypeahead>
4748
</div>
4849
<div>
4950
<rlTypeaheadList [(value)]="selections" label="Typeahead list" [getItems]="getOptions" clientSearch="true" transform="value"></rlTypeaheadList>

source/components/inputs/typeahead/typeahead.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export class TypeaheadComponent<T> extends ValidatedInputComponent<T> implements
4141
@Input() allowCollapse: boolean;
4242
@Input() create: { (value: string): T };
4343
@Input() caseSensitiveSearching: boolean;
44+
@Input() debounce: number;
4445
@Output() selector: EventEmitter<T> = new EventEmitter<T>();
4546

4647

@@ -158,7 +159,12 @@ export class TypeaheadComponent<T> extends ValidatedInputComponent<T> implements
158159
ngOnInit(): void {
159160
super.ngOnInit();
160161

161-
this.loadDelay = this.clientSearch ? DEFAULT_CLIENT_SEARCH_DEBOUNCE : DEFAULT_SERVER_SEARCH_DEBOUNCE;
162+
if (this.debounce) {
163+
this.loadDelay = this.debounce;
164+
} else {
165+
this.loadDelay = this.clientSearch ? DEFAULT_CLIENT_SEARCH_DEBOUNCE : DEFAULT_SERVER_SEARCH_DEBOUNCE;
166+
}
167+
162168
this.prefix = this.prefix || 'Search for';
163169
this.placeholder = this.label != null ? this.prefix + ' ' + this.label.toLowerCase() : 'Search';
164170

0 commit comments

Comments
 (0)