mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-13 11:57:29 +08:00
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:
parent
26356a623c
commit
e340894b1c
6
.changeset/whole-houses-try.md
Normal file
6
.changeset/whole-houses-try.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/dropdown": patch
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Quick fix: custom dropdown value
|
@ -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("");
|
||||
});
|
||||
});
|
||||
|
@ -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)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user