Skip to content
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

feat: adds auto resize feature to textarea #10786

Merged
merged 4 commits into from
Jan 29, 2025

Conversation

LimChorngUan
Copy link
Contributor

@LimChorngUan LimChorngUan commented Jan 24, 2025

This PR introduces an auto resize feature for the textarea field.
By default Payload textarea field will dynamically adjust its height based on its content.

Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

I hadn't checked the implementation yet, and I thought it was using the new CSS field-sizing property.

The implementation of this PR has some issues. For example, it doesn't display a scroll-bar. Also, it requires an additional div and some CSS tricks.

I think we should use field-sizing. It's a single line of code and is already supported by 73% of users. Firefox already gave a positive vote to the standard in September so it probably won't take that long. I didn't find anything specific about Safari.

@LimChorngUan LimChorngUan force-pushed the autogrowing-textarea branch 2 times, most recently from 244fd69 to 068a426 Compare January 28, 2025 15:02
@LimChorngUan
Copy link
Contributor Author

@GermanJablo Hey thanks for the feedback! Yea I was using the extra div and css tricks because field-sizing isn't supported 100% yet but good to know it's gonna become a standard soon! I have changed it and so nice to see this PR just shrink to 1 line change :D

For the scrollbar, unless it hits the height constraint there will be no scrollbar displayed, it's the default field-sizing: content behaviour.
I also leave out setting the max-height here in Payload since I thought every customers will have different requirement and they can always set themselves by providing one through the custom classname. Is that okay?

Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

Yes, much better!

We also agree on not setting a pre-set max-height. In fact, we had the same discussion about the codeblock: #8209

The only detail I would fix in this PR is that if the user manually shrinks the textArea and it takes up less space than the content, the scrollbar should be visible (I don't see it right now).

@LimChorngUan
Copy link
Contributor Author

The scrollbar is currently not visible on chrome also on the main branch, not sure why this style has been added? https://github.com/payloadcms/payload/blob/main/packages/ui/src/fields/Textarea/index.scss#L58-L60

I have removed for now and added overflow-y: scroll but could you confirm with your team if we should change that behaviour?

@LimChorngUan
Copy link
Contributor Author

Screen.Recording.2025-01-28.at.21.18.08.mov

@GermanJablo GermanJablo enabled auto-merge (squash) January 29, 2025 14:28
Copy link
Contributor

@GermanJablo GermanJablo left a comment

Choose a reason for hiding this comment

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

  • I changed overflow-y from scroll to auto, so that the scroll-bar is only visible if there is overflow.
  • reverted PR feat: let textarea grow based on value #1398. Back then field-sizing wasn't a thing and fortunately certain hacks aren't needed now.

For the record, I made sure that textareas are displayed correctly in dark and light mode, as well as error states. Also, the height behavior now follows the decision made in #8209.

Thanks a lot, @LimChorngUan !

@LimChorngUan
Copy link
Contributor Author

Thanks a lot of the feedback and changes you made too!

@GermanJablo GermanJablo merged commit 7d429f8 into payloadcms:main Jan 29, 2025
67 checks passed
Copy link
Contributor

github-actions bot commented Feb 5, 2025

🚀 This is included in version v3.21.0

@openbayou
Copy link

How do you get it to resize?

@LimChorngUan
Copy link
Contributor Author

LimChorngUan commented Feb 14, 2025

Hey @openbayou, it should be automatic and no configuration needed since we used field-sizing: content https://developer.mozilla.org/en-US/docs/Web/CSS/field-sizing. Note that firefox currently doesn't support it yet, but will become a standard eventually: mozilla/standards-positions#849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants