Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure input value saves on dropdown blur #5525

Merged
merged 15 commits into from Sep 13, 2023
Merged

Ensure input value saves on dropdown blur #5525

merged 15 commits into from Sep 13, 2023

Conversation

hannahblair
Copy link
Collaborator

@hannahblair hannahblair commented Sep 13, 2023

Description

We weren't saving the current input value of the dropdown on blur - this PR fixes that 🐛

Closes: #5515

🎯 PRs Should Target Issues

Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.

Not adhering to this guideline will result in the PR being closed.

Tests

  1. PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests: bash scripts/run_all_tests.sh

  2. You may need to run the linters: bash scripts/format_backend.sh and bash scripts/format_frontend.sh

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Sep 13, 2023

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
Visual tests all good! Build review
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/b9ca06a8aaff020f440be3026e510185fcc10911/gradio-3.44.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@b9ca06a8aaff020f440be3026e510185fcc10911#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Sep 13, 2023

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
@gradio/dropdown patch
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Ensure input value saves on dropdown blur

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@hannahblair hannahblair changed the title save input on dropdown blur Ensure input value saves on dropdown blur Sep 13, 2023
@hannahblair hannahblair marked this pull request as ready for review September 13, 2023 17:06
@abidlabs
Copy link
Member

Thanks @hannahblair -- this change looks good. Could we also make the same change when multiselect=True?

If possible, would be great to add unit tests for this to to prevent any regressions. I'll try to increase the coverage of the unit tests for Dropdown/Multiselect in a separate PR.

@hannahblair
Copy link
Collaborator Author

thanks for the review @abidlabs! ah yes, i've added that change to multiselect. also added a unit test 👍

@abidlabs
Copy link
Member

Thanks for the quick fix @hannahblair! Taking a look

@abidlabs
Copy link
Member

abidlabs commented Sep 13, 2023

I used this code to test:

import gradio as gr

def printy(x):
    print(x)
    return x

with gr.Blocks() as demo:
    gr.Markdown("Inputs")
    d1 = gr.Dropdown(["choice 1", ("choice 2 [with value]", "value 2"), "choice 3"], label="single select", filterable=True,
                    multiselect=False)
    d2 = gr.Dropdown(["choice 1", ("choice 2 [with value]", "value 2"), "choice 3"], label="multi select", filterable=True,
                    multiselect=True, max_choices=2)
    d3 = gr.Dropdown(["choice 1", ("choice 2 [with value]", "value 2"), "choice 3"], label="single select allow_custom_value",
                    multiselect=False, allow_custom_value=True)
    d4 = gr.Dropdown(["choice 1", ("choice 2 [with value]", "value 2"), "choice 3"], label="multi select allow_custom_value",
                    multiselect=True, max_choices=2, allow_custom_value=True)
    
    gr.Markdown("Outputs")
    t = gr.Textbox()
    
    d1.change(printy, d1, t)
    d2.change(printy, d2, t)
    d3.change(printy, d3, t)
    d4.change(printy, d4, t)
    
demo.launch()

Noticed two issues:

  1. If allow_custom_value=False and multiselect=False (dropdown 1), this change is preventing the user from selecting any choices

  2. If allow_custom_value=True and multiselect=True (dropdown 4), the custom value does get saved -- however, it overrides the previously selected choice instead of being added to the list of selected choices. In the 4th dropdown, try selecting a choice first, and then typing in a custom value, and then blurring (versus pressing enter -- the behaviors are different).

@hannahblair
Copy link
Collaborator Author

hannahblair commented Sep 13, 2023

My testing was lousy 😅 Fixed, thank you @abidlabs

@abidlabs
Copy link
Member

Beautiful @hannahblair! Just one nit above, otherwise looks good to merge.

@abidlabs
Copy link
Member

Merging so we can do the release. Thanks @hannahblair!

@abidlabs abidlabs merged commit 21f1db4 into main Sep 13, 2023
13 checks passed
@abidlabs abidlabs deleted the handle-dropdown-blur branch September 13, 2023 19:42
@pngwn pngwn mentioned this pull request Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom value in gr.Dropdown is not reflected without pressing enter
3 participants