diff --git a/.changeset/major-years-burn.md b/.changeset/major-years-burn.md new file mode 100644 index 0000000000000..ccc2ee80f0fd3 --- /dev/null +++ b/.changeset/major-years-burn.md @@ -0,0 +1,6 @@ +--- +"@gradio/dropdown": patch +"gradio": patch +--- + +fix:Ensure `gr.Dropdown` can have an empty initial value diff --git a/js/dropdown/Dropdown.stories.svelte b/js/dropdown/Dropdown.stories.svelte index 7d17f974cf012..29873aead23e2 100644 --- a/js/dropdown/Dropdown.stories.svelte +++ b/js/dropdown/Dropdown.stories.svelte @@ -45,3 +45,16 @@ label: "Single-select Dropdown" }} /> + + diff --git a/js/dropdown/Index.svelte b/js/dropdown/Index.svelte index 38183149343ec..a8d9c0b2fcae9 100644 --- a/js/dropdown/Index.svelte +++ b/js/dropdown/Index.svelte @@ -17,7 +17,7 @@ export let elem_id = ""; export let elem_classes: string[] = []; export let visible = true; - export let value: string | string[]; + export let value: string | string[] | undefined = undefined; export let value_is_output = false; export let multiselect = false; export let max_choices: number | null = null; diff --git a/js/dropdown/dropdown.test.ts b/js/dropdown/dropdown.test.ts index 0d1ef9788f0e2..1810f903aec69 100644 --- a/js/dropdown/dropdown.test.ts +++ b/js/dropdown/dropdown.test.ts @@ -442,4 +442,25 @@ describe("Dropdown", () => { await item.blur(); await expect(item.value).toBe("apple_new_choice"); }); + + test("ensure dropdown can have an empty value", async () => { + const { getByLabelText } = await render(Dropdown, { + show_label: true, + loading_status, + allow_custom_value: false, + 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(""); + }); }); diff --git a/js/dropdown/shared/Dropdown.svelte b/js/dropdown/shared/Dropdown.svelte index 08f29c87eeb6c..254c2b222656e 100644 --- a/js/dropdown/shared/Dropdown.svelte +++ b/js/dropdown/shared/Dropdown.svelte @@ -8,9 +8,8 @@ export let label: string; export let info: string | undefined = undefined; - export let value: string | number | (string | number)[] | undefined = - undefined; - let old_value: string | number | (string | number)[] | undefined = undefined; + export let value: string | number | (string | number)[] | undefined = []; + let old_value: string | number | (string | number)[] | undefined = []; export let value_is_output = false; export let choices: [string, string | number][]; let old_choices: [string, string | number][];