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 dropdown blur bug when values are provided as tuples #6694

Merged
merged 3 commits into from Dec 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/small-crabs-take.md
@@ -0,0 +1,6 @@
---
"@gradio/dropdown": patch
"gradio": patch
---

fix:Fix dropdown blur bug when values are provided as tuples
37 changes: 37 additions & 0 deletions js/dropdown/dropdown.test.ts
Expand Up @@ -370,4 +370,41 @@ describe("Dropdown", () => {
options = getAllByTestId("dropdown-option");
expect(options[0]).toHaveClass("selected");
});

test("blurring a dropdown should set the input text to the previously selected value", async () => {
const { getByLabelText, getAllByTestId, component } = await render(
Dropdown,
{
show_label: true,
loading_status,
value: "",
allow_custom_value: false,
label: "Dropdown",
choices: [
["apple", "apple_internal_value"],
["zebra", "zebra_internal_value"],
["pony", "pony_internal_value"]
],
filterable: true,
interactive: true
}
);

const item: HTMLInputElement = getByLabelText(
"Dropdown"
) as HTMLInputElement;

expect(item.value).toBe("apple");
await item.focus();
let options = getAllByTestId("dropdown-option");
expect(options[0]).toHaveClass("selected");
await item.blur();
expect(item.value).toBe("apple");

await item.focus();
await event.keyboard("z");
expect(item.value).toBe("applez");
await item.blur();
expect(item.value).toBe("apple");
});
});
3 changes: 2 additions & 1 deletion js/dropdown/shared/Dropdown.svelte
Expand Up @@ -140,8 +140,9 @@
function handle_blur(): void {
if (!allow_custom_value) {
input_text = choices_names[choices_values.indexOf(value as string)];
} else {
value = input_text;
}
value = input_text;
show_options = false;
active_index = null;
dispatch("blur");
Expand Down
140 changes: 25 additions & 115 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.