@@ -86,7 +86,7 @@ const _defaults: AutocompleteOptions = {
8686 onSearch : ( text : string , autocomplete : Autocomplete ) => {
8787 const normSearch = text . toLocaleLowerCase ( ) ;
8888 autocomplete . setMenuItems (
89- autocomplete . options . data . filter (
89+ autocomplete . data . filter (
9090 ( option ) =>
9191 option . id . toString ( ) . toLocaleLowerCase ( ) . includes ( normSearch ) ||
9292 option . text ?. toLocaleLowerCase ( ) . includes ( normSearch )
@@ -95,7 +95,7 @@ const _defaults: AutocompleteOptions = {
9595 } ,
9696 maxDropDownHeight : '300px' ,
9797 allowUnsafeHTML : false ,
98- selected : [ ]
98+ selected : [ ] ,
9999} ;
100100
101101export class Autocomplete extends Component < AutocompleteOptions > {
@@ -115,6 +115,7 @@ export class Autocomplete extends Component<AutocompleteOptions> {
115115 static _keydown : boolean ;
116116 selectedValues : AutocompleteData [ ] ;
117117 menuItems : AutocompleteData [ ] ;
118+ data : AutocompleteData [ ] ;
118119
119120 constructor ( el : HTMLInputElement , options : Partial < AutocompleteOptions > ) {
120121 super ( el , options , Autocomplete ) ;
@@ -131,9 +132,10 @@ export class Autocomplete extends Component<AutocompleteOptions> {
131132 this . oldVal = '' ;
132133 this . selectedValues =
133134 this . selectedValues ||
134- this . options . selected . map ( ( value ) => < AutocompleteData > { id : value } ) ||
135+ this . options . selected . map ( ( value : number | string ) => < AutocompleteData > { id : value } ) ||
135136 [ ] ;
136137 this . menuItems = this . options . data || [ ] ;
138+ this . data = this . options . data || [ ] ;
137139 this . $active = null ;
138140 this . _mousedown = false ;
139141 this . _setupDropdown ( ) ;
@@ -535,23 +537,26 @@ export class Autocomplete extends Component<AutocompleteOptions> {
535537 * @param menuItems Items to be available.
536538 * @param selected Selected item ids
537539 * @param open Option to conditionally open dropdown
540+ * @param initial Condition to set initial data
538541 */
539542 setMenuItems (
540543 menuItems : AutocompleteData [ ] ,
541544 selected : number [ ] | string [ ] = null ,
542- open : boolean = true
545+ open : boolean = true ,
546+ initial : boolean = false ,
543547 ) {
544548 this . menuItems = menuItems ;
545549 this . options . data = menuItems ;
550+ if ( initial ) {
551+ this . data = menuItems ;
552+ }
546553 if ( selected ) {
547554 this . selectedValues = this . menuItems . filter (
548555 ( item ) => ! ( selected . indexOf ( < never > item . id ) === - 1 )
549556 ) ;
550557 }
551558 if ( this . options . isMultiSelect ) {
552559 this . _renderDropdown ( ) ;
553- } else {
554- this . _refreshInputText ( ) ;
555560 }
556561 if ( open ) this . open ( ) ;
557562 this . _updateSelectedInfo ( ) ;
0 commit comments