@teamwork/autocomplete-core
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -188,2 +188,7 @@ import { EmitterInterface, TypedEventEmitter } from '@syncot/events'; | ||
accept?: Accept; | ||
/** | ||
* Determines if `Autocomplete#clear` should be called automatically on selection change. | ||
* Defaults to `true`. | ||
*/ | ||
clearOnSelectionChange?: boolean; | ||
} | ||
@@ -193,2 +198,2 @@ /** | ||
*/ | ||
export declare function createAutocomplete({ editorAdapter, match, load, accept, }: CreateAutocompleteOptions): Autocomplete; | ||
export declare function createAutocomplete({ editorAdapter, match, load, accept, clearOnSelectionChange, }: CreateAutocompleteOptions): Autocomplete; |
@@ -18,7 +18,7 @@ import { TypedEventEmitter } from '@syncot/events'; | ||
*/ | ||
export function createAutocomplete({ editorAdapter, match = defaultMatch, load = defaultLoad, accept = defaultAccept, }) { | ||
return new AutocompleteClass(editorAdapter, match, load, accept); | ||
export function createAutocomplete({ editorAdapter, match = defaultMatch, load = defaultLoad, accept = defaultAccept, clearOnSelectionChange = true, }) { | ||
return new AutocompleteClass(editorAdapter, match, load, accept, clearOnSelectionChange); | ||
} | ||
class AutocompleteClass extends TypedEventEmitter { | ||
constructor(editorAdapter, _match, _load, _accept) { | ||
constructor(editorAdapter, _match, _load, _accept, _clearOnSelectionChange) { | ||
super(); | ||
@@ -29,2 +29,3 @@ this.editorAdapter = editorAdapter; | ||
this._accept = _accept; | ||
this._clearOnSelectionChange = _clearOnSelectionChange; | ||
this._items = defaultItems; | ||
@@ -51,3 +52,3 @@ this._selectedIndex = defaultSelectedIndex; | ||
this.onSelectionChange = () => { | ||
if (this.pending !== 'matchNow') { | ||
if (this._clearOnSelectionChange && this.pending !== 'matchNow') { | ||
this.clear(); | ||
@@ -54,0 +55,0 @@ } |
{ | ||
"name": "@teamwork/autocomplete-core", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "The core autocomplete components.", | ||
@@ -29,3 +29,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "41dc055efcab5ec37ce184fac0ad84837df4b813" | ||
"gitHead": "2915eeff90dd850779603ac5b11425b67d8d4744" | ||
} |
20815
9
578