Bind widgets to query params - st.checkbox & st.toggle#13900
Bind widgets to query params - st.checkbox & st.toggle#13900mayagbarnes merged 4 commits intodevelopfrom
st.checkbox & st.toggle#13900Conversation
✅ 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. |
📈 Frontend coverage change detectedThe frontend unit test (vitest) coverage has increased by 0.0500%
✅ Coverage change is within normal range. |
There was a problem hiding this comment.
Pull request overview
Adds URL query parameter binding support for st.checkbox and st.toggle, enabling two-way sync between widget state and the browser URL via the existing query-param binding infrastructure.
Changes:
- Added
bindparameter support in Python forst.checkbox/st.toggle, wiring it into widget registration and protobuf payloads. - Extended the Checkbox protobuf + frontend Checkbox widget to register query-param bindings when
queryParamKeyis present. - Added/updated Python, frontend, and Playwright E2E tests to cover seeding, URL updates, default-clearing, and invalid URL handling.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| proto/streamlit/proto/Checkbox.proto | Adds query_param_key field to allow backend → frontend signaling of query-param binding. |
| lib/streamlit/elements/widgets/checkbox.py | Introduces bind API for checkbox/toggle and populates query_param_key; passes binding metadata into widget registration. |
| lib/streamlit/runtime/state/session_state.py | Adjusts URL seeding logic to clear params when URL value resolves to the widget default. |
| lib/tests/streamlit/runtime/state/session_state_test.py | Adds regression test ensuring default-equivalent URL values are cleared. |
| lib/tests/streamlit/elements/checkbox_test.py | Adds unit tests for bind="query-params" behavior and invalid bind value handling for checkbox/toggle. |
| frontend/lib/src/components/widgets/Checkbox/Checkbox.tsx | Registers query-param binding config via useBasicWidgetState when queryParamKey is present; normalizes default/current proto values to booleans. |
| frontend/lib/src/components/widgets/Checkbox/Checkbox.test.tsx | Adds frontend unit tests verifying (un)registration of query-param bindings. |
| e2e_playwright/st_toggle.py | Adds bound toggles used by E2E coverage. |
| e2e_playwright/st_toggle_test.py | Adds E2E tests for query-param seeding, URL updates, default-clearing, and invalid URL values for toggle. |
| e2e_playwright/st_checkbox.py | Adds bound checkboxes used by E2E coverage. |
| e2e_playwright/st_checkbox_test.py | Adds E2E tests for query-param seeding, URL updates, default-clearing, and invalid URL values for checkbox. |
SummaryThis PR adds Key changes:
Code QualityThe code is clean, well-structured, and follows established patterns in the codebase:
Minor observations:
Test CoverageTest coverage is thorough and well-structured: E2E tests (checkbox + toggle):
Python unit tests:
Frontend unit tests:
Typing tests:
The element count constants ( Backwards CompatibilityThis PR is fully backwards compatible:
Security & RiskNo security concerns identified:
AccessibilityNo accessibility concerns. The checkbox and toggle widgets themselves are unchanged visually and functionally — only the URL binding behavior is new. The existing RecommendationsNo blocking issues found. A few minor suggestions:
VerdictAPPROVED: Clean, well-tested implementation that follows established patterns for binding widgets to URL query params. The session_state simplification is a correct behavioral improvement, and the PR is fully backwards compatible. This is an automated AI review by |
42a23f4 to
2611cb1
Compare
Describe your changes
Adds the bind parameter to
st.checkbox&st.toggleto enable two-way sync between widget values and URL query parameters.Also includes clean up / improvements from the
st.color_pickerimplementation:shouldClearUrlParamlogic.getDefaultStateFromProto/getCurrStateFromProtofallback — checkbox now falls back tofalseinstead ofnullwhen proto fields are unset, matching the boolean type contract.queryParamBindingconstruction —color_pickeraligned to use the same extracted-const pattern as checkbox for consistency.Testing Plan