Skip to content

Bind widgets to query params - Part 4#13722

Closed
mayagbarnes wants to merge 7 commits intoquery-param-bind-3from
query-param-bind-4
Closed

Bind widgets to query params - Part 4#13722
mayagbarnes wants to merge 7 commits intoquery-param-bind-3from
query-param-bind-4

Conversation

@mayagbarnes
Copy link
Copy Markdown
Collaborator

@mayagbarnes mayagbarnes commented Jan 27, 2026

Describe your changes

Bind Widgets to Query Params - Part 4
This PR adds the bind parameter to st.text_input, st.text_area, and st.number_input to enable two-way sync between widget values and URL query parameters.

  • URL seeding - Widgets initialize from URL on page load
  • URL sync - User input updates URL in real-time (on blur/enter)
  • Default cleanup - URL param removed when widget returns to default value
  • Constraint handling - max_chars truncates seeded values; min/max clamps number inputs
  • Error handling - StreamlitInvalidBindValueError for invalid bind values

Testing Plan

  • Python/JS Unit Tests: ✅ Added
  • E2E Tests: ✅ Added
  • Manual Testing: ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13722/streamlit-1.53.1-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13722.streamlit.app (☁️ Deploy here if not accessible)

@mayagbarnes mayagbarnes changed the title Add st.text_input & tests Bind widgets to query params - Part 4 Jan 27, 2026
Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Jan 27, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@mayagbarnes mayagbarnes added change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users security-assessment-completed labels Jan 27, 2026 — with Graphite App
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

📈 Significant bundle size change detected

Metric This Branch develop Change (%)
Total (gzip) 8.14 MiB 8.14 MiB +0.02%
Entry (gzip) 722.15 KiB 718.14 KiB +0.56%

Please verify that this change is expected.

📊 View detailed bundle comparison

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

📈 Frontend coverage change detected

The frontend unit test (vitest) coverage has increased by 0.0700%

  • Current PR: 86.3300% (13662 lines, 1867 missed)
  • Latest develop: 86.2600% (13545 lines, 1861 missed)

🎉 Great job on improving test coverage!

📊 View detailed coverage comparison

@mayagbarnes mayagbarnes marked this pull request as ready for review January 27, 2026 20:38
@mayagbarnes mayagbarnes requested a review from a team as a code owner January 27, 2026 20:38
@mayagbarnes mayagbarnes requested a review from Copilot January 27, 2026 20:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the bind parameter to st.text_input, st.text_area, and st.number_input widgets, enabling two-way synchronization between widget values and URL query parameters. This is Part 4 of the "Bind widgets to query params" feature series.

Changes:

  • Adds bind="query-params" parameter support to three text/number input widgets
  • Implements URL seeding (widgets initialize from URL on page load)
  • Implements URL sync (user input updates URL in real-time)
  • Handles constraint enforcement (max_chars truncation, min/max clamping for numbers)
  • Includes comprehensive error handling for invalid bind values

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
proto/streamlit/proto/TextInput.proto Adds optional query_param_key field to TextInput proto message
proto/streamlit/proto/TextArea.proto Adds optional query_param_key field to TextArea proto message
proto/streamlit/proto/NumberInput.proto Adds optional query_param_key field to NumberInput proto message
lib/streamlit/elements/widgets/text_widgets.py Implements bind parameter for text_input and text_area, adds max_chars handling in Serde classes
lib/streamlit/elements/widgets/number_input.py Implements bind parameter for number_input, adds min/max clamping in NumberInputSerde
lib/tests/streamlit/elements/text_input_test.py Adds comprehensive unit tests for text_input bind functionality
lib/tests/streamlit/elements/text_area_test.py Adds comprehensive unit tests for text_area bind functionality
lib/tests/streamlit/elements/number_input_test.py Adds comprehensive unit tests for number_input bind functionality including clamping tests
frontend/lib/src/components/widgets/TextInput/TextInput.tsx Registers query param binding when queryParamKey is set
frontend/lib/src/components/widgets/TextInput/TextInput.test.tsx Adds frontend unit tests for query param binding
frontend/lib/src/components/widgets/TextArea/TextArea.tsx Registers query param binding and refactors getStateFromWidgetMgr for consistency
frontend/lib/src/components/widgets/TextArea/TextArea.test.tsx Adds frontend unit tests for query param binding
frontend/lib/src/components/widgets/NumberInput/NumberInput.tsx Registers query param binding when queryParamKey is set
frontend/lib/src/components/widgets/NumberInput/NumberInput.test.tsx Adds frontend unit tests for query param binding
e2e_playwright/st_text_input.py Adds test app code for query param bound text inputs
e2e_playwright/st_text_input_test.py Adds E2E tests for URL seeding, updates, and edge cases
e2e_playwright/st_text_area.py Adds test app code for query param bound text areas
e2e_playwright/st_text_area_test.py Adds E2E tests for URL seeding, updates, and edge cases
e2e_playwright/st_number_input.py Adds test app code for query param bound number inputs
e2e_playwright/st_number_input_test.py Adds E2E tests for URL seeding, clamping, and edge cases

if self.data_type == NumberInputProto.INT:
val = int(val)
# Clamp to min/max range (e.g., for values seeded from URL)
val = max(self.min_value, min(self.max_value, val))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This seems like it's going to have broader effects than just for values seeded from URL. Is this desired behavior even if this value was set not from the URL query string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants