Skip to content

Use key as main identity for button widgets#12332

Merged
lukasmasuch merged 22 commits intodevelopfrom
feature/use-key-as-identity-for-buttons
Aug 29, 2025
Merged

Use key as main identity for button widgets#12332
lukasmasuch merged 22 commits intodevelopfrom
feature/use-key-as-identity-for-buttons

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Aug 26, 2025

Describe your changes

If a custom key is passed to any of the button widgets - st.button, st.download_button, st.form_submit_button - 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.

@snyk-io
Copy link
Copy Markdown
Contributor

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

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-12332/streamlit-1.49.0-py3-none-any.whl
🕹️ Preview app pr-12332.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 Aug 26, 2025
@lukasmasuch lukasmasuch marked this pull request as ready for review August 26, 2025 19:06
element_id = compute_and_register_element_id(
"button",
user_key=key,
key_as_main_identity=True,
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.

Only the buttons are configured as true here.

)


def test_dynamic_button(app: Page, assert_snapshot: ImageCompareFunction):
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.

note: Seems like there is a snapshot mismatch for this test in CI.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

seems to be some sub-pixel screenshot flakiness with firefox :( pushed an attempt to fix it

expect(submit_button).to_be_visible()


def test_dynamic_submit_button(app: Page, assert_snapshot: ImageCompareFunction):
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.

note: Seems like there is a snapshot mismatch for this test in CI.

Copy link
Copy Markdown
Collaborator

@sfc-gh-bnisco sfc-gh-bnisco left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@lukasmasuch lukasmasuch merged commit 81f4d5f into develop Aug 29, 2025
38 of 39 checks passed
@lukasmasuch lukasmasuch deleted the feature/use-key-as-identity-for-buttons branch August 29, 2025 08:58
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.

Allow dynamic label on button with fixed key

3 participants