-
Notifications
You must be signed in to change notification settings - Fork 23
fix: fix text area auto-expand when controlled #912
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
Conversation
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 PR fixes the text area auto-expand functionality for controlled components by splitting the logic into two useEffect calls within a new useAutoExpand hook.
- Introduces a new useAutoExpand hook to handle controlled and uncontrolled auto-expand behavior.
- Removes the previous unified auto-expand useEffect in favor of the new split implementation.
Files not reviewed (1)
- src/text-area/text-area.stories.mdx: Language not supported
{...props} | ||
label="What do you want to accomplish?" | ||
message="This one will not auto-expand." | ||
autoExpand={false} |
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.
💭 Was it intentional to remove the "What do you want to accomplish?" textarea that had autoExpand={false}
? I'm ok without it (as anyway there are plenty of other stories with textareas with autoExpand={false}
, so not really needed.
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.
That was my thinking too.
event.preventDefault() | ||
setValue('') // Clear the input programmatically | ||
} | ||
}} |
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.
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.
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.
❌ Oh I guess it's because we're not passing {...props}
anymore to the textarea
in this story. Assuming it wasn't intentional, I think we should put it back so that devs can play with the story in the Canvas like before, right? (Otherwise the controls would not work)
Before (prod) | After (this PR) |
---|---|
CleanShot.2025-04-30.at.11.34.50.mp4 |
CleanShot.2025-04-30.at.11.35.27.mp4 |
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.
My mistake! Must have removed the {...props}
inadvertently. Will fix it.
const isControlled = value !== undefined | ||
|
||
React.useEffect( | ||
function setupAutoExpandWhenUncontrolled() { |
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.
💭 I see that in setupAutoExpandWhenControlled
you do !isControlled -> return
.
Would it make sense to do isControl -> return
in this case? 🤔
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.
Makes sense to me overall! I left one blocking comment (need to pass {...props}
to the controlled textarea in storybook).
Short description
Fixes #911
The main issue is that our current auto-expand implementation is more suitable for when the component is uncontrolled. When the component is controlled, it is better to use the
value
changes as the signal to run the effect.This PR now changes the auto-expand to set up two different
useEffect
calls:oninput
event to update the auto-expand size)value
as dependency in the effect, to update the auto-expand size)PR Checklist