Skip to content

Commit 05aade8

Browse files
committed
fix(input-field): resize completions dropdown when viewport is resized
fix: Lundalogik/crm-feature#4408
1 parent c428aea commit 05aade8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/components/input-field/input-field.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ interface LinkProperties {
3737
target?: string;
3838
}
3939

40-
const DEBOUNCE_TIMEOUT = 300;
40+
const CHANGE_EVENT_DEBOUNCE_TIMEOUT = 300;
41+
const RESIZE_HANDLER_DEBOUNCE_TIMEOUT = 100;
4142

4243
/**
4344
* @exampleComponent limel-example-input-field-text
@@ -280,6 +281,7 @@ export class InputField {
280281
this.mdcTextField.destroy();
281282
}
282283

284+
this.restyleCompletionsDropDown.cancel();
283285
window.removeEventListener('resize', this.layout);
284286
this.limelInputField.removeEventListener('focus', this.setFocus);
285287
}
@@ -492,8 +494,17 @@ export class InputField {
492494

493495
private layout = () => {
494496
this.mdcTextField?.layout();
497+
this.restyleCompletionsDropDown();
495498
};
496499

500+
private restyleCompletionsDropDown = debounce(() => {
501+
const stateOfShowCompletions = this.showCompletions;
502+
this.showCompletions = false;
503+
requestAnimationFrame(() => {
504+
this.showCompletions = stateOfShowCompletions;
505+
});
506+
}, RESIZE_HANDLER_DEBOUNCE_TIMEOUT);
507+
497508
private getAdditionalProps = () => {
498509
const props: any = {};
499510

@@ -974,7 +985,7 @@ export class InputField {
974985
private changeEmitter = debounce((value: string) => {
975986
this.change.emit(value);
976987
this.changeWaiting = false;
977-
}, DEBOUNCE_TIMEOUT);
988+
}, CHANGE_EVENT_DEBOUNCE_TIMEOUT);
978989

979990
private handleChange = (event: Event) => {
980991
event.stopPropagation();

0 commit comments

Comments
 (0)