@@ -86,7 +86,7 @@ const _defaults: AutocompleteOptions = {
86
86
onSearch : ( text : string , autocomplete : Autocomplete ) => {
87
87
const normSearch = text . toLocaleLowerCase ( ) ;
88
88
autocomplete . setMenuItems (
89
- autocomplete . options . data . filter (
89
+ autocomplete . data . filter (
90
90
( option ) =>
91
91
option . id . toString ( ) . toLocaleLowerCase ( ) . includes ( normSearch ) ||
92
92
option . text ?. toLocaleLowerCase ( ) . includes ( normSearch )
@@ -95,7 +95,7 @@ const _defaults: AutocompleteOptions = {
95
95
} ,
96
96
maxDropDownHeight : '300px' ,
97
97
allowUnsafeHTML : false ,
98
- selected : [ ]
98
+ selected : [ ] ,
99
99
} ;
100
100
101
101
export class Autocomplete extends Component < AutocompleteOptions > {
@@ -115,6 +115,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
115
115
static _keydown : boolean ;
116
116
selectedValues : AutocompleteData [ ] ;
117
117
menuItems : AutocompleteData [ ] ;
118
+ data : AutocompleteData [ ] ;
118
119
119
120
constructor ( el : HTMLInputElement , options : Partial < AutocompleteOptions > ) {
120
121
super ( el , options , Autocomplete ) ;
@@ -131,9 +132,10 @@ export class Autocomplete extends Component<AutocompleteOptions> {
131
132
this . oldVal = '' ;
132
133
this . selectedValues =
133
134
this . selectedValues ||
134
- this . options . selected . map ( ( value ) => < AutocompleteData > { id : value } ) ||
135
+ this . options . selected . map ( ( value : number | string ) => < AutocompleteData > { id : value } ) ||
135
136
[ ] ;
136
137
this . menuItems = this . options . data || [ ] ;
138
+ this . data = this . options . data || [ ] ;
137
139
this . $active = null ;
138
140
this . _mousedown = false ;
139
141
this . _setupDropdown ( ) ;
@@ -535,23 +537,26 @@ export class Autocomplete extends Component<AutocompleteOptions> {
535
537
* @param menuItems Items to be available.
536
538
* @param selected Selected item ids
537
539
* @param open Option to conditionally open dropdown
540
+ * @param initial Condition to set initial data
538
541
*/
539
542
setMenuItems (
540
543
menuItems : AutocompleteData [ ] ,
541
544
selected : number [ ] | string [ ] = null ,
542
- open : boolean = true
545
+ open : boolean = true ,
546
+ initial : boolean = false ,
543
547
) {
544
548
this . menuItems = menuItems ;
545
549
this . options . data = menuItems ;
550
+ if ( initial ) {
551
+ this . data = menuItems ;
552
+ }
546
553
if ( selected ) {
547
554
this . selectedValues = this . menuItems . filter (
548
555
( item ) => ! ( selected . indexOf ( < never > item . id ) === - 1 )
549
556
) ;
550
557
}
551
558
if ( this . options . isMultiSelect ) {
552
559
this . _renderDropdown ( ) ;
553
- } else {
554
- this . _refreshInputText ( ) ;
555
560
}
556
561
if ( open ) this . open ( ) ;
557
562
this . _updateSelectedInfo ( ) ;
0 commit comments