Skip to content

Commit

Permalink
Reset the dropdown filter on blur
Browse files Browse the repository at this point in the history
  • Loading branch information
deckar01 committed Aug 29, 2023
1 parent 1dc797a commit 8c706b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
24 changes: 24 additions & 0 deletions js/dropdown/dropdown.test.ts
Expand Up @@ -87,6 +87,30 @@ describe("Dropdown", () => {
expect(options[0]).toContainHTML("zebra");
});

test("blurring the textbox should cancel the filter", async () => {
const { getByLabelText, listen } = await render(Dropdown, {
show_label: true,
loading_status,
value: "default",
label: "Dropdown",
choices: ["default", "other"]
});

const item: HTMLInputElement = getByLabelText(
"Dropdown"
) as HTMLInputElement;
const change_event = listen("change");
const select_event = listen("select");

await item.focus();
await event.keyboard("other");
await item.blur();

assert.equal(item.value, "default");
assert.equal(change_event.callCount, 0);
assert.equal(select_event.callCount, 0);
});

test("deselecting and reselcting a filtered dropdown should show all options again", async () => {
const { getByLabelText, getAllByTestId, debug } = await render(Dropdown, {
show_label: true,
Expand Down
9 changes: 1 addition & 8 deletions js/dropdown/shared/Dropdown.svelte
Expand Up @@ -105,14 +105,7 @@
if (multiselect) {
inputValue = "";
} else if (!allow_custom_value) {
if (value !== inputValue) {
if (typeof value === "string" && inputValue == "") {
inputValue = value;
} else {
value = undefined;
inputValue = "";
}
}
inputValue = value as string | undefined;
}
showOptions = false;
dispatch("blur");
Expand Down

0 comments on commit 8c706b0

Please sign in to comment.