Skip to content

Use key as main identity for st.segmented_control widget#12711

Merged
lukasmasuch merged 8 commits intodevelopfrom
stable-key-identity-for-segmented-control
Oct 8, 2025
Merged

Use key as main identity for st.segmented_control widget#12711
lukasmasuch merged 8 commits intodevelopfrom
stable-key-identity-for-segmented-control

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

Describe your changes

If a custom key is passed to the st.segmented_control widget 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 unit and e2e 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.

@lukasmasuch lukasmasuch requested a review from Copilot October 7, 2025 13:32
@snyk-io
Copy link
Copy Markdown
Contributor

snyk-io bot commented Oct 7, 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 Oct 7, 2025

✅ PR preview is ready!

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

@lukasmasuch lukasmasuch added security-assessment-completed change:feature PR contains new feature or enhancement implementation impact:users PR changes affect end users labels Oct 7, 2025
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 the st.segmented_control widget to use a custom key as the main identity when provided, allowing dynamic changes to other parameters between reruns without causing the widget to be recreated in the frontend.

Key changes:

  • Updated the button group implementation to use key_as_main_identity for segmented controls
  • Added comprehensive unit tests to verify stable widget IDs with keys
  • Added E2E tests to demonstrate dynamic property updates while preserving state

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/streamlit/elements/widgets/button_group.py Modified segmented control to use key as main identity with whitelisted kwargs
lib/tests/streamlit/elements/button_group_test.py Added unit tests for stable ID behavior and whitelisted kwargs validation
e2e_playwright/st_segmented_control.py Added test app with dynamic segmented control property updates
e2e_playwright/st_segmented_control_test.py Added E2E test to verify dynamic property changes preserve widget state

@lukasmasuch lukasmasuch merged commit 60bed03 into develop Oct 8, 2025
39 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-segmented-control branch October 8, 2025 16:42
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