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

Fixes to the .key_up() method to make it usable for a dynamic dropdown autocomplete #7425

Merged
merged 7 commits into from Feb 16, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Feb 15, 2024

This PR makes two changes:

  1. In the Dropdown component, we were resetting the value when the choices were updated. It is somewhat debatable whether we should do this or not. For example, in Dropdown doesn't retain value if choice name is changed #6853, users asked for this behavior. However, it makes it impossible to use for the use case in which the Dropdown component's choices are being updated based on the value of the Dropdown itself.

The way I've implemented it here is that iff when allow_custom_value=True, the Dropdown's values are not reset, which I think is the desired behavior for users in either case. I've also added a test for this.

  1. Since .key_up() is an event that is expected to be fired continuously, I've set the default trigger_mode for the .key_up() event to be always_last, just like for .change().

Test the new behavior with this demo:

import gradio as gr
import time

def f(x, k: gr.KeyUpData):
    time.sleep(1)
    return gr.update(choices=[f"{k.input_value} {i}" for i in range(int(5))])    


with gr.Blocks() as demo:
    t = gr.Dropdown(interactive=True, allow_custom_value=True)
    t.key_up(f, t, t, show_progress="hidden", trigger_mode="always_last")
    
demo.launch()

cc @apolinario (see internal thread)

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 15, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

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

Install Gradio Python Client from this PR

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

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Feb 15, 2024

🦄 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.

Fixes to the .key_up() method to make it usable for a dynamic dropdown autocomplete

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.

@abidlabs abidlabs added the v: patch A change that requires a patch release label Feb 15, 2024
@pngwn
Copy link
Member

pngwn commented Feb 15, 2024

Isn't this a breaking change?

@abidlabs
Copy link
Member Author

abidlabs commented Feb 15, 2024

Both of the changes are technically breaking changes but the original changes were both made in 4.19.0 (the first one was changed in 4.19.0 and the KeyUp event was introduced in 4.19.0) so I think its ok but I should mark it as such

@pngwn
Copy link
Member

pngwn commented Feb 15, 2024

I wouldnt list them as breaking changes if we aren't doing a major bump :p that's just confusing. I'd just put it through as a fix.

@abidlabs
Copy link
Member Author

The python test is failing due to a typecheck issue on files that I haven't touched, something strange is happening on CI. Will investigate but that should be independent of this PR

@hannahblair
Copy link
Collaborator

Nice @abidlabs, works great!

@abidlabs
Copy link
Member Author

Thanks @hannahblair for reviewing! Merging in changes from main to fix the typechecks. And then will merge this in.

@abidlabs abidlabs merged commit 3e4e680 into main Feb 16, 2024
8 checks passed
@abidlabs abidlabs deleted the key-up-fixes branch February 16, 2024 18:21
@pngwn pngwn mentioned this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: patch A change that requires a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants