Skip to content

Allow dynamically changing in min and max in st.date_input#13549

Merged
lukasmasuch merged 8 commits intodevelopfrom
feature/dynamic-min-max-for-date-input
Jan 16, 2026
Merged

Allow dynamically changing in min and max in st.date_input#13549
lukasmasuch merged 8 commits intodevelopfrom
feature/dynamic-min-max-for-date-input

Conversation

@lukasmasuch
Copy link
Copy Markdown
Collaborator

@lukasmasuch lukasmasuch commented Jan 9, 2026

Describe your changes

Allow dynamically changing the min_value, max_value of st.date_input without triggering an identity change / state reset. If the current selected value isn't in the range, it will be reset to the default value.

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 Jan 9, 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 9, 2026

✅ PR preview is ready!

Name Link
📦 Wheel file https://core-previews.s3-us-west-2.amazonaws.com/pr-13549/streamlit-1.53.0-py3-none-any.whl
📦 @streamlit/component-v2-lib Download from artifacts
🕹️ Preview app pr-13549.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 Jan 12, 2026
@lukasmasuch lukasmasuch marked this pull request as ready for review January 12, 2026 20:44
Copilot AI review requested due to automatic review settings January 12, 2026 20:44
@lukasmasuch
Copy link
Copy Markdown
Collaborator Author

@cursor review

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 pull request enables dynamic changing of min_value and max_value parameters in st.date_input by removing them from the whitelisted parameters that affect widget ID computation. When bounds change and the current value becomes invalid, the widget now automatically resets to its default value.

Changes:

  • Removed min_value and max_value from the key_as_main_identity whitelist, keeping only format (which has a known baseweb bug that prevents dynamic changes)
  • Added validation logic to detect when widget values fall outside new bounds and automatically reset to defaults
  • Updated widget ID stability tests to verify that min/max changes don't trigger ID regeneration
  • Added comprehensive unit tests and E2E tests covering dynamic bound changes for both single-date and range-date inputs

Reviewed changes

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

File Description
lib/streamlit/elements/widgets/time_widgets.py Added _validate_and_reset_date_value function to validate and reset values when bounds change; updated _date_input to use only format in key_as_main_identity and apply validation logic
lib/tests/streamlit/elements/date_input_test.py Updated ID stability tests to reflect that min/max are no longer whitelisted; added new tests for dynamic bound changes, value preservation, and session state handling
e2e_playwright/st_date_input.py Updated test app to use different min/max values when toggling to demonstrate dynamic bounds
e2e_playwright/st_date_input_test.py Added E2E test case verifying that out-of-bounds values reset to defaults when bounds change

# Now min_value=June 1, so March 1 is invalid and should reset to default (July 15)
assert at.date_input[0].value == date(2024, 7, 15)
# Anti-regression: ensure it didn't keep the old invalid value
assert at.date_input[0].value != date(2024, 3, 1)
Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby Jan 16, 2026

Choose a reason for hiding this comment

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

Is this useful? Since if this were true, won't execution stop when the first assert fails?

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.

Removed it, agree that it is not super useful

if current_value is None or not has_explicit_bounds:
return current_value, False

value_needs_reset = False
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.

[nit] You could define this above the conditional check here and the return current_value, value_needs_reset in the conditional. It's jut a bit more readable because it reminds you what the two return values are for. But super nit.

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.

Changed 👍

Copy link
Copy Markdown
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby left a comment

Choose a reason for hiding this comment

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

LGTM when the e2e test is fixed (running now, so maybe already fixed).

@lukasmasuch lukasmasuch enabled auto-merge (squash) January 16, 2026 19:42
@lukasmasuch lukasmasuch disabled auto-merge January 16, 2026 19:49
@lukasmasuch lukasmasuch enabled auto-merge (squash) January 16, 2026 19:49
@lukasmasuch lukasmasuch merged commit a4584bc into develop Jan 16, 2026
44 checks passed
@lukasmasuch lukasmasuch deleted the feature/dynamic-min-max-for-date-input branch January 16, 2026 19:58
lukasmasuch added a commit that referenced this pull request Jan 16, 2026
Enable dynamic min_value and max_value changes for datetime_input when a key is provided, following the same pattern as st.date_input (PR #13549).

Changes:
- Updated key_as_main_identity to exclude min/max from element ID stability
- Added _validate_datetime_value() to handle bound validation and value resets
- Added logic to track explicit bounds and reset values when out of bounds
- Added unit tests for dynamic min/max scenarios
- Updated E2E tests to validate dynamic bounds behavior

Co-Authored-By: Claude <[email protected]>
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