Bind widgets to query params - st.pills & st.segmented_control#14006
Bind widgets to query params - st.pills & st.segmented_control#14006mayagbarnes merged 3 commits intodevelopfrom
st.pills & st.segmented_control#14006Conversation
✅ PR preview is ready!
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
There was a problem hiding this comment.
Pull request overview
This PR adds query parameter binding support (bind="query-params") to st.pills and st.segmented_control, enabling two-way synchronization between widget values and URL query strings. This completes the query param binding feature for selection widgets in the Streamlit library.
Changes:
- Extended protobuf schema with
query_param_keyfield for ButtonGroup widgets - Added
bindparameter to bothst.pillsandst.segmented_controlPython APIs with comprehensive docstrings - Implemented frontend query param binding configuration using
string_array_valuewith repeated URL format - Added comprehensive test coverage across Python unit tests, frontend unit tests, and E2E tests
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
proto/streamlit/proto/ButtonGroup.proto |
Added optional query_param_key field (field 15) to enable query parameter binding |
lib/streamlit/elements/widgets/button_group.py |
Added bind parameter to pills, segmented_control, and internal functions; configured register_widget with clearable=True, formatted_options, and max_array_length for proper query param handling |
lib/tests/streamlit/elements/button_group_test.py |
Added Python unit tests for bind functionality covering key requirement, invalid values, format_func, and multi-mode |
frontend/lib/src/components/widgets/ButtonGroup/ButtonGroup.tsx |
Configured queryParamBinding object with string_array_value, clearable=true, and repeated URL format |
frontend/lib/src/components/widgets/ButtonGroup/ButtonGroup.test.tsx |
Added frontend unit tests verifying registration, unregistration, and config for both single and multi-select modes |
e2e_playwright/st_pills_test.py |
Added 14 E2E tests covering seeding, URL updates, invalid values, format_func, deduplication, truncation, and edge cases |
e2e_playwright/st_pills.py |
Added test widgets with various configurations (single, multi, defaults, format_func) for E2E testing |
e2e_playwright/st_segmented_control_test.py |
Added 7 E2E tests covering seeding, URL updates, invalid values, and multi-select behavior |
e2e_playwright/st_segmented_control.py |
Added test widgets for E2E testing of query param binding |
SummaryThis PR adds
Code QualityThe implementation is clean and follows established patterns well:
Test CoverageTest coverage is excellent and comprehensive across all three test levels: Python unit tests (
Frontend unit tests (
E2E tests (
The E2E tests are thorough but numerous (17 for pills, 7 for segmented_control). Per the E2E AGENTS.md guidance to "prefer aggregated scenario tests over many micro-tests," some of these could potentially be consolidated — however, each test covers a distinct behavioral aspect with different URL seeding, so the granularity is reasonable for a feature of this complexity. One gap: The typing tests in Backwards CompatibilityFully backwards compatible:
Security & Risk
AccessibilityNo accessibility concerns. The changes are purely data-flow related (query parameter binding). No new UI elements, ARIA attributes, or interaction patterns are introduced. The existing ButtonGroup accessibility (button roles, disabled states, keyboard interaction) is unaffected. Recommendations
VerdictAPPROVED: Clean, well-tested implementation that correctly adds query parameter binding to This is an automated AI review by |
8ac88e3 to
fe98620
Compare
SummaryThis PR adds Code QualityThe code structure is clean and consistent with existing widget implementations:
Test CoverageCoverage is strong and multi-layered:
The added tests are adequate for the behavior introduced. Backwards CompatibilityNo breaking changes identified:
Security & RiskNo security concerns identified in the diff. Regression risk appears low because:
AccessibilityNo accessibility regressions identified from this change set.
Recommendations
VerdictAPPROVED: The changes are well-implemented, backward compatible, and sufficiently tested for merge. This is an automated AI review by |
Describe your changes
Adds bind="query-params" to
st.pillsandst.segmented_controlfor two-way sync between widget values and URL query parameters.Key changes:
st.multiselect. Single-select:?color=Red. Multi-select: ?tags=Red&tags=Blue.?key=) are accepted as an intentional clear to None/[].st.radioandst.selectbox. This distinction (invalid ≠ cleared) is verified by dedicated tests.?color=Red&color=Blue) are truncated to the first via max_array_length=1.Testing Plan