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

Skip to content

Conversation

@sfc-gh-pchiu
Copy link
Contributor

@sfc-gh-pchiu sfc-gh-pchiu commented Mar 27, 2025

Describe your changes

See GH issue linked below for context.

In this fix we preserve the scroll height of the input when placeholder expands it to multiple line, and add new e2e tests to validate 3 scenarios.

However, the caveat is that this fix does not work on Firefox. This is because when the placeholder text exceeds the predefined height of the textarea, baseweb increases it scroll height on Chrome and webkit, but not on FIrefox. As a result, when we calculate scrollHeight in getScrollHeight it returns the height set by its styling.

Screen.Recording.2025-03-27.at.11.18.13.AM.mov

I'm currently leaning towards shipping this fix, as I think 1) having this discrepancy has low risk, 2) the existing behavior happens only for edge cases (when there's a reason for long placeholder or short input width,) and 3) any other workaround for this baseweb inconsistency feels hacky and introduces complexity that does not outweigh the gain.

I would appreciate any feedback on how we should go about it.

GitHub Issue Link (if applicable)

#10611

Testing Plan

  • 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
Contributor

snyk-io bot commented Mar 27, 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
Contributor

github-actions bot commented Mar 27, 2025

✅ PR preview is ready!

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

@sfc-gh-pchiu sfc-gh-pchiu 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 Mar 27, 2025
@sfc-gh-pchiu sfc-gh-pchiu force-pushed the fix/chat-input-placeholder-height branch from 691346f to df82094 Compare March 27, 2025 18:28
@sfc-gh-pchiu sfc-gh-pchiu changed the title fix height for placeholder [RFC] fix chat input height for long placeholder Mar 27, 2025
@sfc-gh-pchiu sfc-gh-pchiu changed the title [RFC] fix chat input height for long placeholder [RFC] fix chat input height for multi-line placeholder Mar 27, 2025
@sfc-gh-pchiu sfc-gh-pchiu marked this pull request as ready for review March 27, 2025 20:39
@lukasmasuch lukasmasuch requested a review from Copilot March 27, 2025 21:02
Copy link
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 addresses an issue with multi-line placeholders in the chat input by adjusting the scroll height calculation and adding new e2e tests for validating the updated behavior.

  • Refactored the scrollHeight measurement in ChatInput.tsx to better handle multi-line placeholders.
  • Added a useLayoutEffect hook that triggers a recalculation when the placeholder changes.
  • Introduced new e2e tests in st_chat_input_test.py and updated chat input initialization in st_chat_input.py to validate the fix.

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated no comments.

File Description
frontend/lib/src/components/widgets/ChatInput/ChatInput.tsx Adjusted scrollHeight calculation by removing temporary clearing of the textarea's placeholder and added a useLayoutEffect hook for recalculation when placeholder changes.
e2e_playwright/st_chat_input_test.py Added new tests to capture screenshots for the chat input's behavior with long placeholders.
e2e_playwright/st_chat_input.py Updated chat input instantiation with an extended placeholder to trigger multi-line behavior.
Comments suppressed due to low confidence (2)

frontend/lib/src/components/widgets/ChatInput/ChatInput.tsx:279

  • Ensure that removing the temporary clearing of textarea.placeholder does not lead to inaccurate scrollHeight measurements on browsers other than Chrome/WebKit. Consider adding a code comment referencing the baseweb behavior discrepancy for future maintainers.
scrollHeight = textarea.scrollHeight

e2e_playwright/st_chat_input_test.py:390

  • [nitpick] Using nth(5) to select the chat input element may be brittle if the DOM structure changes. Consider using a more specific selector or adding a comment explaining why this index is used.
chat_input = app.get_by_test_id("stChatInput").nth(5)

Copy link
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 given the tradeoffs talked about in Slack

@sfc-gh-pchiu sfc-gh-pchiu force-pushed the fix/chat-input-placeholder-height branch from 21f0e39 to 1752a21 Compare March 28, 2025 19:32
@sfc-gh-pchiu sfc-gh-pchiu enabled auto-merge (squash) March 28, 2025 19:45
@sfc-gh-pchiu sfc-gh-pchiu merged commit 977d275 into develop Mar 28, 2025
33 checks passed
@sfc-gh-pchiu sfc-gh-pchiu deleted the fix/chat-input-placeholder-height branch March 28, 2025 20:06
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.

3 participants