Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sfc-gh-lwilby
Copy link
Collaborator

@sfc-gh-lwilby sfc-gh-lwilby commented Oct 29, 2025

Describe your changes

Fixes a bug in st.text_area where very small height values would render larger than expected due to negative height calculations producing invalid CSS.

Root Cause:
When calculating inner height, the formula pixelHeight - labelAndPadding could produce negative values (e.g., height=10 with 30px label padding = -20px). Invalid negative CSS height values were ignored by browsers, causing the minHeight (68px) to take over, which made height=10 render larger than height=30.

Fix:
Added Math.max(0, innerHeight) to clamp calculated heights to 0 minimum, ensuring all height values produce valid CSS.

Note: the minimum height for st.text_area is such that two lines of text fit in the input, so heights that would result in less space in the input will render as this minimum.

Screenshot 2025-10-29 at 7 16 59 PM Screenshot 2025-10-29 at 7 17 28 PM Screenshot 2025-10-29 at 7 17 49 PM

GitHub Issue Link

Fixes #12867

Testing Plan

  • Unit Tests (TypeScript) - 8 parameterized test cases for negative height clamping
    • Tests heights below, at, and above boundary for both visible and collapsed labels
    • Verifies 0px clamping for negative calculations
    • Confirms positive heights work correctly
  • E2E Tests - Added snapshot test for height=10 case
  • Manual testing completed with comprehensive test app covering:
    • Original bug demonstration (height=10 vs height=30)
    • Boundary cases from team testing (29, 30, 31)
    • Collapsed label boundary cases (1, 2, 3)
    • Various heights (50, 100, 150, 200)

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

- Fix: Clamp calculated height to 0 minimum to prevent invalid CSS
- Add comprehensive unit tests for negative height clamping
- Add E2E snapshot test for height=10 case
- Covers both visible and collapsed label scenarios
@sfc-gh-lwilby sfc-gh-lwilby added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Oct 29, 2025
@snyk-io
Copy link
Contributor

snyk-io bot commented Oct 29, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 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
Contributor

github-actions bot commented Oct 29, 2025

✅ PR preview is ready!

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

@sfc-gh-lwilby sfc-gh-lwilby marked this pull request as ready for review October 29, 2025 21:00
@sfc-gh-lwilby sfc-gh-lwilby changed the title Fix st.text_area negative height calculation (gh-12867) [fix] st.text_area negative height calculation Oct 29, 2025
@sfc-gh-lwilby sfc-gh-lwilby merged commit 9d3a016 into develop Oct 30, 2025
38 checks passed
@sfc-gh-lwilby sfc-gh-lwilby deleted the fix/text-area-negative-height branch October 30, 2025 13:28
sfc-gh-nbellante added a commit that referenced this pull request Oct 31, 2025
…ments_test

Skip on Chromium due to 1px snapshot width mismatch in CI. See failing workflow: https://github.com/streamlit/streamlit/actions/runs/18964912763/job/54180100557\n\nRecent snapshot touched by 9d3a016 (#12891); feature introduced in 5409b98 (#12848). We'll stabilize and re-enable later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

st.text_area height=10 is set to a larger height than height=30

3 participants