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

Fix single select dropdown #9526

Open
wants to merge 4 commits into
base: 5.0-dev
Choose a base branch
from
Open

Conversation

whitphx
Copy link
Member

@whitphx whitphx commented Oct 4, 2024

Description

gr.Dropdown(multiselect=False) sets the default value as [] of type list. It's a confusing behavior.

The fix is in a04ad54 where the default value is changed from [] to undefined.
As a result, the following value initializer that seems to have not been reached before became effective and the first item of choices is now set as the default value.

} else if (choices.length > 0) {
old_selected_index = 0;
selected_index = 0;
[input_text, value] = choices[selected_index];
old_value = value;
old_input_text = input_text;
}

I think

  • setting a list value [] as the default value of a single-select dropdown is obviously a bug.
  • but setting the first value of choices instead of None is an opinionated behavior, while I think it's desirable as the user can eliminate the null-checking from the user-defined fn. If it's a problem I will fix it.

For example,
the tone generator example looks like this, where the non-null dropdown value is set by default:
CleanShot 2024-10-04 at 12 14 04@2x

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 4, 2024

🪼 branch checks and previews

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

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/bcc1c6c62f0c767bfc9ba40c5e72499d84287af2/gradio-4.44.1-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/bcc1c6c62f0c767bfc9ba40c5e72499d84287af2/gradio-client-1.6.0-beta.3.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/bcc1c6c62f0c767bfc9ba40c5e72499d84287af2/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Oct 4, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Fix single select dropdown

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.

@whitphx whitphx marked this pull request as ready for review October 4, 2024 03:47
@whitphx whitphx mentioned this pull request Oct 4, 2024
1 task
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.

2 participants