Skip to content

Commit

Permalink
Quick fix: custom dropdown value (#7567)
Browse files Browse the repository at this point in the history
* fix

* add changeset

* fix

* revert

* add test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
dawoodkhan82 and gradio-pr-bot committed Mar 5, 2024
1 parent 26356a6 commit e340894
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/whole-houses-try.md
@@ -0,0 +1,6 @@
---
"@gradio/dropdown": patch
"gradio": patch
---

fix:Quick fix: custom dropdown value
20 changes: 20 additions & 0 deletions js/dropdown/dropdown.test.ts
Expand Up @@ -492,4 +492,24 @@ describe("Dropdown", () => {
) as HTMLInputElement;
await expect(item.value).toBe("");
});

test("ensure dropdown works when initial value is undefined and allow custom value is set", async () => {
const { getByLabelText } = await render(Dropdown, {
show_label: true,
loading_status,
value: undefined,
allow_custom_value: true,
label: "Dropdown",
choices: [
["apple_choice", "apple_internal_value"],
["zebra_choice", "zebra_internal_value"]
],
filterable: true,
interactive: true
});
const item: HTMLInputElement = getByLabelText(
"Dropdown"
) as HTMLInputElement;
await expect(item.value).toBe("");
});
});
2 changes: 1 addition & 1 deletion js/dropdown/shared/Dropdown.svelte
Expand Up @@ -123,7 +123,7 @@
function set_input_text(): void {
set_choice_names_values();
if (value === undefined) {
if (value === undefined || (Array.isArray(value) && value.length === 0)) {
input_text = "";
selected_index = null;
} else if (choices_values.includes(value as string)) {
Expand Down

0 comments on commit e340894

Please sign in to comment.