Fix autocomplete helper detach

This commit is contained in:
Eduard Kuzmenko 2021-06-22 18:44:10 +03:00
parent 80fa6909d9
commit 94f01ef560

View File

@ -21,6 +21,7 @@ export default class AutocompleteHelper extends EventListenerBase<{
protected container: HTMLElement; protected container: HTMLElement;
protected list: HTMLElement; protected list: HTMLElement;
protected resetTarget: () => void; protected resetTarget: () => void;
protected detach: () => void;
protected init?(): void; protected init?(): void;
protected controller: AutocompleteHelperController; protected controller: AutocompleteHelperController;
@ -28,6 +29,8 @@ export default class AutocompleteHelper extends EventListenerBase<{
protected onSelect: (target: Element) => boolean | void; protected onSelect: (target: Element) => boolean | void;
protected waitForKey?: string; protected waitForKey?: string;
protected navigationItem: NavigationItem;
constructor(options: { constructor(options: {
appendTo: HTMLElement, appendTo: HTMLElement,
controller: AutocompleteHelper['controller'], controller: AutocompleteHelper['controller'],
@ -50,6 +53,10 @@ export default class AutocompleteHelper extends EventListenerBase<{
} }
protected onVisible = () => { protected onVisible = () => {
if(this.detach) { // it can be so because 'visible' calls before animation's end
this.detach();
}
const list = this.list; const list = this.list;
const {detach, resetTarget} = attachListNavigation({ const {detach, resetTarget} = attachListNavigation({
list, list,
@ -59,16 +66,16 @@ export default class AutocompleteHelper extends EventListenerBase<{
waitForKey: this.waitForKey waitForKey: this.waitForKey
}); });
this.detach = detach;
this.resetTarget = resetTarget; this.resetTarget = resetTarget;
let navigationItem: NavigationItem; if(!isMobile && !this.navigationItem) {
if(!isMobile) { this.navigationItem = {
navigationItem = {
type: 'autocomplete-helper', type: 'autocomplete-helper',
onPop: () => this.toggle(true), onPop: () => this.toggle(true),
noBlurOnPop: true noBlurOnPop: true
}; };
appNavigationController.pushItem(navigationItem); appNavigationController.pushItem(this.navigationItem);
} }
this.addEventListener('hidden', () => { this.addEventListener('hidden', () => {
@ -76,8 +83,8 @@ export default class AutocompleteHelper extends EventListenerBase<{
list.innerHTML = ''; list.innerHTML = '';
detach(); detach();
if(navigationItem) { if(this.navigationItem) {
appNavigationController.removeItem(navigationItem); appNavigationController.removeItem(this.navigationItem);
} }
}, true); }, true);
}; };