Skip to content

Commit

Permalink
fix(input-field): resize completions dropdown when viewport is resized
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianschmidt committed Nov 13, 2024
1 parent 2ef5d8c commit 5d66f16
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/input-field/input-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -280,6 +281,7 @@ export class InputField {
this.mdcTextField.destroy();
}

this.restyleCompletionsDropDown.cancel();
window.removeEventListener('resize', this.layout);
this.limelInputField.removeEventListener('focus', this.setFocus);
}
Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 5d66f16

Please sign in to comment.