@@ -5,7 +5,7 @@ import {Ion} from '../ion';
5
5
import { Config } from '../../config/config' ;
6
6
import { Icon } from '../icon/icon' ;
7
7
import { Button } from '../button/button' ;
8
- import { isDefined } from '../../util/util' ;
8
+ import { isDefined , debounce } from '../../util/util' ;
9
9
10
10
11
11
/**
@@ -20,14 +20,12 @@ export class SearchbarInput {
20
20
* @private
21
21
* Don't send the input's input event
22
22
*/
23
- private stopInput ( event ) {
24
- event . preventDefault ( ) ;
25
- event . stopPropagation ( ) ;
23
+ private stopInput ( ev ) {
24
+ ev . preventDefault ( ) ;
25
+ ev . stopPropagation ( ) ;
26
26
}
27
27
28
- constructor ( private _elementRef : ElementRef ) {
29
-
30
- }
28
+ constructor ( private _elementRef : ElementRef ) { }
31
29
}
32
30
33
31
@@ -69,6 +67,8 @@ export class SearchbarInput {
69
67
directives : [ FORM_DIRECTIVES , NgIf , NgClass , Icon , Button , SearchbarInput ]
70
68
} )
71
69
export class Searchbar extends Ion {
70
+ private _tmr : number ;
71
+
72
72
/**
73
73
* @private
74
74
*/
@@ -84,6 +84,11 @@ export class Searchbar extends Ion {
84
84
*/
85
85
@Input ( ) hideCancelButton : any ;
86
86
87
+ /**
88
+ * @input {number} How long, in milliseconds, to wait to trigger the `input` event after each keystroke. Default `250`.
89
+ */
90
+ @Input ( ) debounce : number = 250 ;
91
+
87
92
/**
88
93
* @input {string} Sets input placeholder to the value passed in
89
94
*/
@@ -253,9 +258,14 @@ export class Searchbar extends Ion {
253
258
* Update the Searchbar input value when the input changes
254
259
*/
255
260
inputChanged ( ev ) {
256
- this . value = ev . target . value ;
257
- this . onChange ( this . value ) ;
258
- this . input . emit ( this ) ;
261
+ let value = ev . target . value ;
262
+
263
+ clearTimeout ( this . _tmr ) ;
264
+ this . _tmr = setTimeout ( ( ) => {
265
+ this . value = value ;
266
+ this . onChange ( value ) ;
267
+ this . input . emit ( this ) ;
268
+ } , Math . round ( this . debounce ) ) ;
259
269
}
260
270
261
271
/**
0 commit comments