Skip to content

Commit

Permalink
Merge pull request #53 from squidit/feature/SQ-63298-limitar-disparo-…
Browse files Browse the repository at this point in the history
…search-change

feature/SQ-63298-limitar-disparo-search-change
  • Loading branch information
JonasPeres committed Mar 25, 2024
2 parents 90ea42d + da04dd1 commit 86ade02
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ export class SqSelectMultiTagsComponent implements OnChanges {
*/
@Input() labelColor = ''

/**
* Minimum number of characters to perform the searchChange.
*/
@Input() minCharactersToSearch = 0

/**
* The time interval for input timeout in ms.
*/
@Input() timeToChange = 800

/**
* Options available for selection.
*/
Expand Down Expand Up @@ -223,16 +233,6 @@ export class SqSelectMultiTagsComponent implements OnChanges {
*/
nativeElement: ElementRef

/**
* Timeout for input changes.
*/
timeoutInput!: ReturnType<typeof setTimeout>

/**
* Time in milliseconds before triggering input timeout.
*/
timeToChange = 800

/**
* Control pagination for options
*/
Expand Down Expand Up @@ -263,6 +263,11 @@ export class SqSelectMultiTagsComponent implements OnChanges {
*/
isMaxTags = false

/**
* Timeout for input changes.
*/
timeoutInput!: ReturnType<typeof setTimeout>

/**
* Constructs a new SqSelectMultiTagsComponent.
*
Expand Down Expand Up @@ -463,12 +468,14 @@ export class SqSelectMultiTagsComponent implements OnChanges {
* Change searchtext with timeout and detect detectChanges
*/
async modelChange(event: any) {
clearTimeout(this.timeoutInput)
this.searchText = await new Promise<string>(resolve => this.timeoutInput = setTimeout(() => {
resolve(event)
}, this.timeToChange)) || ''
this.searchChange.emit(event)
this.changeDetector.detectChanges()
if (!this.minCharactersToSearch || !event.length || event.length >= this.minCharactersToSearch) {
clearTimeout(this.timeoutInput)
this.searchText = await new Promise<string>(resolve => this.timeoutInput = setTimeout(() => {
resolve(event)
}, this.timeToChange)) || ''
this.searchChange.emit(event)
this.changeDetector.detectChanges()
}
}

/**
Expand Down
28 changes: 15 additions & 13 deletions src/components/sq-select-search/sq-select-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ export class SqSelectSearchComponent implements OnChanges {
*/
@Input() errorSpan = true

/**
* Minimum number of characters to perform the searchChange.
*/
@Input() minCharactersToSearch = 0

/**
* The time interval for input timeout in ms.
*/
Expand Down Expand Up @@ -165,11 +170,6 @@ export class SqSelectSearchComponent implements OnChanges {
*/
error: boolean | string = ''

/**
* Timeout duration for input changes.
*/
timeOutInputTime = 800

/**
* Native element reference.
*/
Expand Down Expand Up @@ -215,10 +215,10 @@ export class SqSelectSearchComponent implements OnChanges {
*/
limit = this.quantity

/**
/**
* Timeout for input changes.
*/
timeoutInput!: ReturnType<typeof setTimeout>
timeoutInput!: ReturnType<typeof setTimeout>

/**
* Constructs a new SqSelectSearchComponent.
Expand Down Expand Up @@ -311,12 +311,14 @@ export class SqSelectSearchComponent implements OnChanges {
* @param {string} event - The search input value.
*/
async onTipSearchChange(event: string) {
clearTimeout(this.timeoutInput)
this.searchText = await new Promise<string>(resolve => this.timeoutInput = setTimeout(() => {
resolve(event)
}, this.timeToChange)) || ''
this.searchChange.emit(event)
this.changeDetector.detectChanges()
if (!this.minCharactersToSearch || !event.length || event.length >= this.minCharactersToSearch) {
clearTimeout(this.timeoutInput)
this.searchText = await new Promise<string>(resolve => this.timeoutInput = setTimeout(() => {
resolve(event)
}, this.timeToChange)) || ''
this.searchChange.emit(event)
this.changeDetector.detectChanges()
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@squidit/ngx-css",
"version": "1.3.25",
"version": "1.3.26",
"peerDependencies": {
"@angular/common": ">=15.0.0",
"@angular/core": ">=15.0.0",
Expand Down

0 comments on commit 86ade02

Please sign in to comment.