Fix Dropdown labels for None-valued choices - #13842
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/ad46ca0b230b1522d311d252951f876c4284b361/gradio-6.26.0-py3-none-any.whlInstall Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@ad46ca0b230b1522d311d252951f876c4284b361#subdirectory=client/python"Import Gradio JS Client from this PR via CDN import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/ad46ca0b230b1522d311d252951f876c4284b361/browser.js"; |
🦄 change detectedThis Pull Request includes changes to the following packages.
|
There was a problem hiding this comment.
🟡 Changes recommended
The supported null choice behavior remains excluded by the frontend and Python public type contracts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Fixes single-select Dropdown labels for choices mapped to None.
Changes:
- Resolves display labels before treating
nullas empty. - Adds initial-render and selection regression tests.
- Adds generated patch changeset.
File summaries
| File | Description |
|---|---|
js/dropdown/shared/Dropdown.svelte |
Handles matching null-valued choices. |
js/dropdown/dropdown.test.ts |
Tests rendering and selecting null choices. |
.changeset/late-dancers-invite.md |
Records patch releases. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } else if (current_value === null) { | ||
| input_text = ""; | ||
| selected_index = null; |
|
I'm actually not sure if we should do this, as it might be a breaking change. Currently, we say that if if value is Technically, the usage that was reported is not supported as values are supposed to be strings or numerics only. To get what they want, they just need to map "Default" to "Default" and then inside their function they could map to |
|
That being said, the current behavior is definitely not expected, so perhaps we just document this (we'll want to update the type hints for choices and values, and maybe in the frontend as well) and support this. |
Description
Fixes single-select Dropdowns whose choices include a display label mapped to
None. The component now checks for a matching choice before treating aNonevalue as an empty selection, so the label is shown while the submitted value remainsNone.Closes: #13832
Before / after Spaces
Both Spaces run the same reproduction from the issue:
0edbbc905On load, compare the Choose an option field: the before Space leaves it blank, while the after Space shows Default. Then select Option A followed by Default; the after Space keeps Default visible and the result confirms that its submitted value is still
None.The temporary demo and wheel are hosted in the Spaces and are not committed to this branch.
AI Disclosure
🎯 PRs Should Target Issues
This PR targets #13832. I checked for overlapping open PRs before starting and found none.
Testing and Formatting Your Code
None-valued choice. No Playwright tests were added.CI=1 pnpm exec vitest run --config .config/vitest.config.ts js/dropdown/dropdown.test.ts— 140 passed, 4 todo.bash scripts/format_frontend.shformatted the changes successfully. Its repository-wide type-check reports 16 existing errors in unrelated files..changeset/late-dancers-invite.mdfrom the PR title after the branch was pushed.