@@ -71,8 +71,8 @@ import {
71
71
} from './select-errors' ;
72
72
73
73
74
- /** The debounce interval when typing letters to select an option. */
75
- const LETTER_KEY_DEBOUNCE_INTERVAL = 200 ;
74
+ /** Default debounce interval when typing letters to select an option. */
75
+ const DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL = 200 ;
76
76
77
77
describe ( 'MatSelect' , ( ) => {
78
78
let overlayContainer : OverlayContainer ;
@@ -469,20 +469,42 @@ describe('MatSelect', () => {
469
469
expect ( formControl . value ) . toBeFalsy ( 'Expected no initial value.' ) ;
470
470
471
471
dispatchEvent ( select , createKeyboardEvent ( 'keydown' , 80 , undefined , 'p' ) ) ;
472
- tick ( 200 ) ;
472
+ tick ( DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL ) ;
473
473
474
474
expect ( options [ 1 ] . selected ) . toBe ( true , 'Expected second option to be selected.' ) ;
475
475
expect ( formControl . value ) . toBe ( options [ 1 ] . value ,
476
476
'Expected value from second option to have been set on the model.' ) ;
477
477
478
478
dispatchEvent ( select , createKeyboardEvent ( 'keydown' , 69 , undefined , 'e' ) ) ;
479
- tick ( 200 ) ;
479
+ tick ( DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL ) ;
480
480
481
481
expect ( options [ 5 ] . selected ) . toBe ( true , 'Expected sixth option to be selected.' ) ;
482
482
expect ( formControl . value ) . toBe ( options [ 5 ] . value ,
483
483
'Expected value from sixth option to have been set on the model.' ) ;
484
484
} ) ) ;
485
485
486
+ it ( 'should be able to customize the typeahead debounce interval' , fakeAsync ( ( ) => {
487
+ const formControl = fixture . componentInstance . control ;
488
+ const options = fixture . componentInstance . options . toArray ( ) ;
489
+
490
+ fixture . componentInstance . typeaheadDebounceInterval = 1337 ;
491
+ fixture . detectChanges ( ) ;
492
+
493
+ expect ( formControl . value ) . toBeFalsy ( 'Expected no initial value.' ) ;
494
+
495
+ dispatchEvent ( select , createKeyboardEvent ( 'keydown' , 80 , undefined , 'p' ) ) ;
496
+ tick ( DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL ) ;
497
+
498
+ expect ( formControl . value ) . toBeFalsy ( 'Expected no value after a bit of time has passed.' ) ;
499
+
500
+ tick ( 1337 ) ;
501
+
502
+ expect ( options [ 1 ] . selected )
503
+ . toBe ( true , 'Expected second option to be selected after all the time has passed.' ) ;
504
+ expect ( formControl . value ) . toBe ( options [ 1 ] . value ,
505
+ 'Expected value from second option to have been set on the model.' ) ;
506
+ } ) ) ;
507
+
486
508
it ( 'should open the panel when pressing a vertical arrow key on a closed multiple select' ,
487
509
fakeAsync ( ( ) => {
488
510
fixture . destroy ( ) ;
@@ -1969,7 +1991,7 @@ describe('MatSelect', () => {
1969
1991
// Press the letter 'o' 15 times since all the options are named 'Option <index>'
1970
1992
dispatchEvent ( host , createKeyboardEvent ( 'keydown' , 79 , undefined , 'o' ) ) ;
1971
1993
fixture . detectChanges ( ) ;
1972
- tick ( LETTER_KEY_DEBOUNCE_INTERVAL ) ;
1994
+ tick ( DEFAULT_TYPEAHEAD_DEBOUNCE_INTERVAL ) ;
1973
1995
}
1974
1996
flush ( ) ;
1975
1997
@@ -4275,7 +4297,8 @@ describe('MatSelect', () => {
4275
4297
<mat-form-field>
4276
4298
<mat-select placeholder="Food" [formControl]="control" [required]="isRequired"
4277
4299
[tabIndex]="tabIndexOverride" [aria-label]="ariaLabel" [aria-labelledby]="ariaLabelledby"
4278
- [panelClass]="panelClass" [disableRipple]="disableRipple">
4300
+ [panelClass]="panelClass" [disableRipple]="disableRipple"
4301
+ [typeaheadDebounceInterval]="typeaheadDebounceInterval">
4279
4302
<mat-option *ngFor="let food of foods" [value]="food.value" [disabled]="food.disabled">
4280
4303
{{ food.viewValue }}
4281
4304
</mat-option>
@@ -4304,6 +4327,7 @@ class BasicSelect {
4304
4327
ariaLabelledby : string ;
4305
4328
panelClass = [ 'custom-one' , 'custom-two' ] ;
4306
4329
disableRipple : boolean ;
4330
+ typeaheadDebounceInterval : number ;
4307
4331
4308
4332
@ViewChild ( MatSelect , { static : true } ) select : MatSelect ;
4309
4333
@ViewChildren ( MatOption ) options : QueryList < MatOption > ;
0 commit comments