Skip to content

fix: update textarea to fit content height and set a max height #17946

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

Merged
merged 3 commits into from
May 21, 2025

Conversation

jaaydenh
Copy link
Contributor

No description provided.

@jaaydenh jaaydenh self-assigned this May 20, 2025
@jaaydenh jaaydenh requested a review from aslilac May 20, 2025 16:59
@jaaydenh jaaydenh changed the title fix: textarea show fit height of content and set a max height fix: update textarea to fit content height and set a max height May 20, 2025
id={id}
className="max-w-2xl"
className="overflow-y-auto max-h-[500px]"
value={localValue}
onChange={(e) => {
const target = e.currentTarget;
target.style.height = "auto";
Copy link
Member

Choose a reason for hiding this comment

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

this is a static style and should be turned into a tailwind class as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I test this, If I don't set height to auto in the onchange, the textarea height does not get updated correctly when the users adds and removes lines from the textarea

@jaaydenh jaaydenh requested a review from aslilac May 20, 2025 19:28
const resizeTextarea = useEffectEvent(() => {
if (textareaRef.current) {
const textarea = textareaRef.current;
textarea.style.height = "auto";
Copy link
Member

Choose a reason for hiding this comment

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

does this actually do anything? you overwrite it immediately

Copy link
Contributor Author

@jaaydenh jaaydenh May 20, 2025

Choose a reason for hiding this comment

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

you are right it was necessary in the onChange below but not needed here.

@jaaydenh jaaydenh merged commit 3a6d5f5 into main May 21, 2025
33 of 34 checks passed
@jaaydenh jaaydenh deleted the jaaydenh/textarea-height branch May 21, 2025 14:56
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants