Describe the bug
When using the key_up event to dynamically update the choices of a gr.Dropdown (e.g., for a search/autocomplete feature), the component exhibits unstable behavior. Specifically:
The current value (the text the user is typing) is often cleared/reset automatically after the backend returns the new choices.
Even when explicitly returning the current value in gr.update(choices=..., value=...), it can trigger an unwanted change event, leading to infinite loops or redundant logic.
If the Dropdown is placed inside a gr.Group, the UI flickering and value-clearing issues become more severe.
This makes it nearly impossible to implement a standard "Search-as-you-type" dropdown without breaking the user's input flow.
Have you searched existing issues? 🔎
Reproduction
import gradio as gr
def dynamic_search(val):
# Simulate fetching new options based on input
new_choices = [f"{val} item 1", f"{val} item 2", f"{val} item 3"]
# Issue: If we don't return 'value', the textbox often clears.
# Issue: If we DO return 'value', it triggers the 'change' event unexpectedly.
return gr.update(choices=new_choices)
with gr.Blocks() as demo:
gr.Markdown("### Dropdown key_up Issue")
with gr.Group():
dropdown = gr.Dropdown(
label="Search Here (Inside Group)",
choices=[],
allow_custom_value=True,
interactive=True
)
status = gr.Textbox(label="Change Event Tracker")
# Triggered on every keystroke
dropdown.key_up(
fn=dynamic_search,
inputs=dropdown,
outputs=dropdown,
queue=False
)
# This should only trigger on selection, but often triggers during key_up updates
dropdown.change(lambda: "Change event fired!", outputs=status)
demo.launch()
Screenshot
No response
Logs
System Info
Operating System: macOS (M1/M2/Intel)
Python Version: 3.10+
Gradio Version: 6.0.0+ (Tested on latest 6.x)
Severity
Blocking usage of gradio
Describe the bug
When using the key_up event to dynamically update the choices of a gr.Dropdown (e.g., for a search/autocomplete feature), the component exhibits unstable behavior. Specifically:
The current value (the text the user is typing) is often cleared/reset automatically after the backend returns the new choices.
Even when explicitly returning the current value in gr.update(choices=..., value=...), it can trigger an unwanted change event, leading to infinite loops or redundant logic.
If the Dropdown is placed inside a gr.Group, the UI flickering and value-clearing issues become more severe.
This makes it nearly impossible to implement a standard "Search-as-you-type" dropdown without breaking the user's input flow.
Have you searched existing issues? 🔎
Reproduction
Screenshot
No response
Logs
System Info
Severity
Blocking usage of gradio