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

Adds a filterable parameter to gr.Dropdown that controls whether user can type to filter choices #5508

Merged
merged 74 commits into from Sep 13, 2023

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Sep 12, 2023

Closes: #5465

Example code:

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=False,
                    multiselect=False)
    d2 = gr.Dropdown(["choice 1", ("choice 2 [with value]", "value 2"), "choice 3"], label="multi select", filterable=False,
                    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()

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Sep 12, 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/4a50a9e1831f800b999aae4fbfd23a35c930a585/gradio-3.43.2-py3-none-any.whl

Install Gradio Python Client from this PR

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

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Sep 12, 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.

Adds a filterable parameter to gr.Dropdown that controls whether user can type to filter choices

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.

@dawoodkhan82
Copy link
Collaborator

Looks good. Maybe we should return a warning when a user tries to set allow_custom_value=True and filterable=False. Also right now when allow_custom_value=True and filterable=False is set, typing is disabled but I think filterable should be ignored and typing should be enabled.

@abidlabs
Copy link
Member Author

Makes sense @dawoodkhan82, I'll make the changes

@abidlabs
Copy link
Member Author

Made the changes & fixed tests -- merging

@abidlabs abidlabs merged commit 05715f5 into main Sep 13, 2023
16 checks passed
@abidlabs abidlabs deleted the dropdown-filterable branch September 13, 2023 01:36
@pngwn pngwn mentioned this pull request Sep 13, 2023
@pseudotensor
Copy link
Contributor

Thanks!

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.

Dropdown "search" leads to odd pop-ups, making it difficult to use -- allow disable "search" mode
4 participants