File tree Expand file tree Collapse file tree
packages/autocomplete-js/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ export interface AutocompleteApi<TItem> extends AutocompleteSetters<TItem> {
6464 * Triggers a search to refresh the state.
6565 */
6666 refresh ( ) : Promise < void > ;
67+ /**
68+ * Cleans up the DOM mutations and event listeners.
69+ */
70+ destroy ( ) : void ;
6771}
6872
6973export function autocomplete < TItem > ( {
@@ -235,6 +239,10 @@ export function autocomplete<TItem>({
235239 root . appendChild ( dropdown ) ;
236240 containerElement . appendChild ( root ) ;
237241
242+ function destroy ( ) {
243+ containerElement . innerHTML = '' ;
244+ }
245+
238246 return {
239247 setHighlightedIndex : autocomplete . setHighlightedIndex ,
240248 setQuery : autocomplete . setQuery ,
@@ -243,5 +251,6 @@ export function autocomplete<TItem>({
243251 setStatus : autocomplete . setStatus ,
244252 setContext : autocomplete . setContext ,
245253 refresh : autocomplete . refresh ,
254+ destroy,
246255 } ;
247256}
You can’t perform that action at this time.
0 commit comments