Skip to content

Use key as main identity for st.time_input & st.date_input#12464

Merged
lukasmasuch merged 13 commits intodevelopfrom
stable-key-identity-for-time-widgets
Sep 10, 2025
Merged

Use key as main identity for st.time_input & st.date_input#12464
lukasmasuch merged 13 commits intodevelopfrom
stable-key-identity-for-time-widgets

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Sep 8, 2025

Describe your changes

If a custom key is passed to any of the st.time_input and st.date_input 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 unit & 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 Sep 8, 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 8, 2025

✅ PR preview is ready!

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

@lukasmasuch lukasmasuch requested a review from Copilot September 8, 2025 15:56
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 implements stable widget IDs for st.time_input and st.date_input when a custom key is provided, allowing dynamic parameter updates without recreating widgets in the frontend.

  • Enables use of key as main identity for time and date input widgets
  • Adds whitelisting for parameters that affect widget state (step for time_input, min_value/max_value for date_input)
  • Ensures widget state preservation across reruns when non-whitelisted parameters change

Reviewed Changes

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

Show a summary per file
File Description
lib/streamlit/elements/widgets/time_widgets.py Updates time_input and date_input to use key as main identity with specific parameter whitelisting
lib/streamlit/elements/widgets/number_input.py Adds clarifying comment about parameter whitelisting for number_input
lib/tests/streamlit/elements/time_input_test.py Adds unit tests for stable ID behavior and whitelisted parameter changes
lib/tests/streamlit/elements/date_input_test.py Adds unit tests for stable ID behavior in both single and range date modes
e2e_playwright/st_time_input_test.py Adds e2e test for dynamic time input property updates
e2e_playwright/st_time_input.py Implements test app with dynamic time input toggling
e2e_playwright/st_date_input_test.py Adds e2e test for dynamic date input property updates
e2e_playwright/st_date_input.py Implements test app with dynamic date input toggling

@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as draft September 8, 2025 16:09
@sfc-gh-lmasuch sfc-gh-lmasuch added impact:users PR changes affect end users security-assessment-completed change:feature PR contains new feature or enhancement implementation labels Sep 9, 2025
@sfc-gh-lmasuch sfc-gh-lmasuch marked this pull request as ready for review September 9, 2025 12:22
@lukasmasuch lukasmasuch merged commit c5c2718 into develop Sep 10, 2025
37 checks passed
@lukasmasuch lukasmasuch deleted the stable-key-identity-for-time-widgets branch September 10, 2025 07:18
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.

st.date_input value is not changing while using session_state

4 participants