diff --git a/src/components/input-field/input-field.tsx b/src/components/input-field/input-field.tsx index 71f9e49380..276d37c43f 100644 --- a/src/components/input-field/input-field.tsx +++ b/src/components/input-field/input-field.tsx @@ -37,7 +37,8 @@ interface LinkProperties { target?: string; } -const DEBOUNCE_TIMEOUT = 300; +const CHANGE_EVENT_DEBOUNCE_TIMEOUT = 300; +const RESIZE_HANDLER_DEBOUNCE_TIMEOUT = 100; /** * @exampleComponent limel-example-input-field-text @@ -280,6 +281,7 @@ export class InputField { this.mdcTextField.destroy(); } + this.restyleCompletionsDropDown.cancel(); window.removeEventListener('resize', this.layout); this.limelInputField.removeEventListener('focus', this.setFocus); } @@ -492,8 +494,17 @@ export class InputField { private layout = () => { this.mdcTextField?.layout(); + this.restyleCompletionsDropDown(); }; + private restyleCompletionsDropDown = debounce(() => { + const stateOfShowCompletions = this.showCompletions; + this.showCompletions = false; + requestAnimationFrame(() => { + this.showCompletions = stateOfShowCompletions; + }); + }, RESIZE_HANDLER_DEBOUNCE_TIMEOUT); + private getAdditionalProps = () => { const props: any = {}; @@ -974,7 +985,7 @@ export class InputField { private changeEmitter = debounce((value: string) => { this.change.emit(value); this.changeWaiting = false; - }, DEBOUNCE_TIMEOUT); + }, CHANGE_EVENT_DEBOUNCE_TIMEOUT); private handleChange = (event: Event) => { event.stopPropagation(); diff --git a/src/components/menu-surface/menu-surface.tsx b/src/components/menu-surface/menu-surface.tsx index 3c72d82e1c..6c074e579b 100644 --- a/src/components/menu-surface/menu-surface.tsx +++ b/src/components/menu-surface/menu-surface.tsx @@ -90,9 +90,6 @@ export class MenuSurface { capture: true, }); this.host.addEventListener('keydown', this.handleKeyDown); - window.addEventListener('resize', this.handleResize, { - passive: true, - }); }; private teardown = () => { @@ -101,7 +98,6 @@ export class MenuSurface { capture: true, }); this.host.removeEventListener('keydown', this.handleKeyDown); - window.removeEventListener('resize', this.handleResize); }; private handleDocumentClick = (event) => { @@ -129,12 +125,6 @@ export class MenuSurface { this.preventClickEventPropagation(); }; - private handleResize = () => { - if (this.open) { - this.dismiss.emit(); - } - }; - private preventClickEventPropagation = () => { // When the menu surface is open, we want to stop the `click` event from propagating // when clicking outside the surface itself. This is to prevent any dialog that might