diff --git a/.changeset/eight-humans-sniff.md b/.changeset/eight-humans-sniff.md new file mode 100644 index 000000000000..9e001c99d701 --- /dev/null +++ b/.changeset/eight-humans-sniff.md @@ -0,0 +1,6 @@ +--- +"@gradio/form": patch +"gradio": patch +--- + +fix:`gr.Dropdown` now has correct behavior in static mode as well as when an option is selected diff --git a/guides/03_building-with-blocks/01_blocks-and-event-listeners.md b/guides/03_building-with-blocks/01_blocks-and-event-listeners.md index 905994f71f94..51e8c076320f 100644 --- a/guides/03_building-with-blocks/01_blocks-and-event-listeners.md +++ b/guides/03_building-with-blocks/01_blocks-and-event-listeners.md @@ -15,12 +15,14 @@ $demo_hello_blocks ## Event Listeners and Interactivity -In the example above, you'll notice that you are able to edit Textbox `name`, but not Textbox `output`. This is because any Component that acts as an input to an event listener is made interactive. However, since Textbox `output` acts only as an output, it is not interactive. You can directly configure the interactivity of a Component with the `interactive=` keyword argument. +In the example above, you'll notice that you are able to edit Textbox `name`, but not Textbox `output`. This is because any Component that acts as an input to an event listener is made interactive. However, since Textbox `output` acts only as an output, Gradio determines that it should not be made interactive. You can override the default behavior and directly configure the interactivity of a Component with the boolean `interactive` keyword argument. ```python output = gr.Textbox(label="Output", interactive=True) ``` +_Note_: What happens if a Gradio component is neither an input nor an output? If a component is constructed with a default value, then it is presumed to be displaying content and is rendered non-interactive. Otherwise, it is rendered interactive. Again, this behavior can be overridden by specifying a value for the `interactive` argument. + ## Types of Event Listeners Take a look at the demo below: diff --git a/js/form/src/Dropdown.stories.svelte b/js/form/src/Dropdown.stories.svelte new file mode 100644 index 000000000000..909145f7b2c6 --- /dev/null +++ b/js/form/src/Dropdown.stories.svelte @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/js/form/src/Dropdown.svelte b/js/form/src/Dropdown.svelte index c56a8be2ff1b..bf7a0e42fe35 100644 --- a/js/form/src/Dropdown.svelte +++ b/js/form/src/Dropdown.svelte @@ -72,8 +72,11 @@ } function remove(option: string): void { - value = value as string[]; - value = value.filter((v: string) => v !== option); + if (!disabled) + { + value = value as string[]; + value = value.filter((v: string) => v !== option); + } dispatch("select", { index: choices.indexOf(option), value: option, @@ -87,7 +90,7 @@ e.preventDefault(); } - function handle_blur(e: FocusEvent) { + function handle_blur(e: FocusEvent): void { if (multiselect) { inputValue = ""; } else if (!allow_custom_value) { @@ -104,14 +107,10 @@ dispatch("blur"); } - function handle_focus(e: FocusEvent){ + function handle_focus(e: FocusEvent): void{ dispatch("focus"); - showOptions = !showOptions; - if (showOptions) { - filtered = choices; - } else { - filterInput.blur(); - } + showOptions = true; + filtered = choices; } function handleOptionMousedown(e: any): void { @@ -137,6 +136,7 @@ value: option, selected: true }); + filterInput.blur(); } } } @@ -154,6 +154,7 @@ } inputValue = activeOption; showOptions = false; + filterInput.blur(); } else if (multiselect && Array.isArray(value)) { value.includes(activeOption) ? remove(activeOption) : add(activeOption); inputValue = ""; @@ -209,13 +210,15 @@
remove(s)} class="token"> {s} + {#if !disabled}
- -
+ +
+ {/if} {/each} {/if}