Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improved timing for creating a new option #1803

Merged
merged 4 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe("BasicAutocompleteComponent", () => {

component.autocompleteForm.setValue("Non existent");
component.onFocusOut({} as any);
tick();
tick(200);

expect(component.value).toBe(undefined);
flush();
Expand Down Expand Up @@ -150,7 +150,7 @@ describe("BasicAutocompleteComponent", () => {
expect(component.value).toEqual([0, 2]);
});

it("should clear the input when focusing in multi select mode", () => {
it("should clear the input when focusing in multi select mode", fakeAsync(() => {
component.multi = true;
component.options = ["some", "values", "and", "other", "options"];
component.value = ["some", "values"];
Expand All @@ -161,8 +161,10 @@ describe("BasicAutocompleteComponent", () => {
expect(component.autocompleteForm).toHaveValue("");

component.onFocusOut({} as any);
tick(200);

expect(component.autocompleteForm).toHaveValue("some, values");
});
}));

it("should update the error state if the form is invalid", () => {
testControl.setValidators([Validators.required]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,8 @@ export class BasicAutocompleteComponent<O, V = O>
if (
!this.elementRef.nativeElement.contains(event.relatedTarget as Element)
) {
if (!this.autocomplete.panelOpen) {
this.notifyFocusOut();
} else {
// trigger focus out once panel is closed
this.delayedBlur = setTimeout(() => this.notifyFocusOut(), 100);
}
// use short timeout in order for creating an option to work
this.delayedBlur = setTimeout(() => this.notifyFocusOut(), 200);
}
}

Expand Down