Quick fix: custom dropdown value (#7567)

* fix

* add changeset

* fix

* revert

* add test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Dawood Khan 2024-03-05 18:21:30 -05:00 committed by GitHub
parent 26356a623c
commit e340894b1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,6 @@
---
"@gradio/dropdown": patch
"gradio": patch
---
fix:Quick fix: custom dropdown value

View File

@ -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("");
});
});

View File

@ -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)) {