Skip to content

Use key as main identity for st.text_area & st.text_input#12397

Merged
lukasmasuch merged 10 commits intodevelopfrom
stable-key-identity-for-text-widgets
Sep 8, 2025
Merged

Use key as main identity for st.text_area & st.text_input#12397
lukasmasuch merged 10 commits intodevelopfrom
stable-key-identity-for-text-widgets

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Sep 1, 2025

Describe your changes

If a custom key is passed to any of the st.text_input or st.text_area widgets it will be used as the main identity. This allows for dynamically changing other parameters in between reruns without causing the widgets to be recreated in the frontend.

GitHub Issue Link (if applicable)

Testing Plan

  • Added e2e and unit tests.

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Sep 1, 2025

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

security/snyk check is complete. No issues have been found. (View Details)

license/snyk check is complete. No issues have been found. (View Details)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 1, 2025

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12397/streamlit-1.49.1-py3-none-any.whl
🕹️ Preview app pr-12397.streamlit.app (☁️ Deploy here if not accessible)

@sfc-gh-lmasuch sfc-gh-lmasuch added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Sep 1, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch changed the title Use key as main identity for st.text_area & st.text_input Use key as main identity for st.text_area & st.text_input Sep 1, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review September 1, 2025 22:23
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as draft September 1, 2025 22:23
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 modifies st.text_input and st.text_area widgets to use custom keys as their main identity when provided, allowing dynamic parameter changes without widget recreation in the frontend. This addresses user requests for better widget state persistence when other properties change between reruns.

Key changes:

  • Updated widget identity logic to use key-based identification with max_chars as a special parameter
  • Added comprehensive unit tests to verify stable widget IDs across parameter changes
  • Implemented E2E tests demonstrating dynamic property updates while preserving widget state

Reviewed Changes

Copilot reviewed 7 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/streamlit/elements/widgets/text_widgets.py Changed key_as_main_identity from False to {"max_chars"} for both text widgets
lib/tests/streamlit/elements/text_input_test.py Added unit test verifying stable widget ID when key is provided
lib/tests/streamlit/elements/text_area_test.py Added unit test verifying stable widget ID when key is provided
e2e_playwright/st_text_input.py Added dynamic text input example with property switching
e2e_playwright/st_text_input_test.py Added E2E test for dynamic property updates with state persistence
e2e_playwright/st_text_area.py Added dynamic text area example with property switching
e2e_playwright/st_text_area_test.py Added E2E test for dynamic property updates with state persistence

@sfc-gh-lmasuch sfc-gh-lmasuch added the change:breaking PR contains breaking change that affects backwards compatibility label Sep 1, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review September 1, 2025 23:04
@lukasmasuch lukasmasuch merged commit 93288ea into develop Sep 8, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-text-widgets branch September 8, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:breaking PR contains breaking change that affects backwards compatibility 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.

4 participants