-
Notifications
You must be signed in to change notification settings - Fork 4k
Allow dynamically changing in min, max and step in st.number_input
#13512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow dynamically changing in min, max and step in st.number_input
#13512
Conversation
✅ PR preview is ready!
|
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📉 Frontend coverage change detectedThe frontend unit test (vitest) coverage has decreased by 0.0000%
✅ Coverage change is within normal range. |
There was a problem hiding this 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 allows st.number_input to dynamically change min_value, max_value, and step parameters without triggering a widget identity change or state reset. When the current value becomes invalid due to bound changes, it automatically resets to the default value, providing behavior consistent with other Streamlit widgets like st.selectbox.
Key changes:
- Widget ID stability now applies to all parameters when a key is provided, not just a whitelisted subset
- Out-of-range values are automatically reset to the default instead of raising exceptions
- Session state is properly updated when value resets to avoid inconsistencies
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
lib/streamlit/elements/widgets/number_input.py |
Changed key_as_main_identity from a whitelist set to True for full parameter stability, and replaced exception-throwing with automatic value reset when bounds change |
lib/tests/streamlit/elements/number_input_test.py |
Removed unused StreamlitValueBelowMinError import, updated test to expect reset behavior instead of exceptions, removed whitelisted parameter tests, and added comprehensive tests for dynamic bound changes |
e2e_playwright/st_number_input.py |
Updated test app to actually change min/max/step values dynamically to demonstrate the new capability |
e2e_playwright/st_number_input_test.py |
Enhanced test to verify both value preservation when still valid and value reset when invalid after bound changes |
e2e_playwright/__snapshots__/linux/st_number_input_test/st_number_input-dynamic_updated[webkit].png |
Updated screenshot reflecting the new dynamic bounds (step changes from 1 to 5) |
e2e_playwright/__snapshots__/linux/st_number_input_test/st_number_input-dynamic_updated[chromium].png |
Updated screenshot reflecting the new dynamic bounds (step changes from 1 to 5) |
…in-max-step-for-number-input
|
@cursor review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Bugbot reviewed your changes and found no bugs!
Describe your changes
Allow dynamically changing the
min_value,max_valueandstepofst.number_inputwithout triggering an identity change / state reset. If the current selected options isn't in the list of available option, it will be reset to the default value.GitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.