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(textarea): auto resizable #1681

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

feat(textarea): auto resizable #1681

wants to merge 16 commits into from

Conversation

rainyEra
Copy link

@rainyEra rainyEra commented Oct 5, 2023

vd.mp4

In my opinion, an auto-resizable textarea brings a great user experience, and I would like to see it included in this UI library. I discarded the changes in New Yorker because of Server Components. What do you think?

@vercel
Copy link

vercel bot commented Oct 5, 2023

@rainyEra is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@shadcn shadcn added enhancement New feature or request component: textarea area: roadmap This looks great. We'll add it to the roadmap, review and merge. labels Oct 15, 2023
@vercel
Copy link

vercel bot commented Oct 15, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 15, 2023 0:38am

Comment on lines 13 to 14
const texteAreaRef = useRef<HTMLTextAreaElement>(null)

Copy link

Choose a reason for hiding this comment

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

Could use React.useImperativeHandle to merge the refs so you don't need to pull in an extra dependency.

    const texteAreaRef = useRef<HTMLTextAreaElement>(null)
    React.useImperativeHandle(ref, () => texteAreaRef.current!);
<textarea
        className={cn(
          "flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
          className
        )}
        ref={texteAreaRef}
        {...props}
      />

https://react.dev/reference/react/useImperativeHandle

Copy link
Author

Choose a reason for hiding this comment

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

I know it, I just prefer other way due to readability. -1 dependency, this is also good.

Choose a reason for hiding this comment

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

how can i make a dynamic textarea with react-hook-form, it handles ref by itself . how can i make it use my ref

@isitrita
Copy link

isitrita commented Nov 6, 2023

@rainyEra do you need help on this?

@rainyEra
Copy link
Author

rainyEra commented Nov 7, 2023

@isitrita sorry, I've been too busy :c

@Obiwarn
Copy link

Obiwarn commented Dec 13, 2023

this is so great! please add this!

@masewo
Copy link

masewo commented Jan 13, 2024

Nice component!
Had to use overflow-y-hidden on my Windows machine to get rid of the scrollbar.
Would be nice to see it with minRows and maxRows options.
Also the ability to manually turn auto resizing on and off would be great (in the case you do not want to have all your textareas grow).
And the perfect solution for me would contain the ability to replace the ugly Windows scrollbars with the beautiful shadcn scrollbars but I think this is kind of impossible.

@rainyEra
Copy link
Author

@shadcn any updates?

@Zakisb
Copy link

Zakisb commented Mar 27, 2024

@shadcn any update?

@rainyEra
Copy link
Author

rainyEra commented Mar 28, 2024

autoResize is now optional, so it won't break other projects. (disabled by default)

@TimurBas
Copy link

TimurBas commented May 14, 2024

autoResize is now optional, so it won't break other projects. (disabled by default)

I don't have the autoRezize prop? I just dowloaded the Textarea component.
image

The PR isn't merged my bad.

@harshpandey002
Copy link

Need this!

@iDevBrandon
Copy link

any update? @shadcn

@unav4ila8le
Copy link

also waiting for this

const updateTextareaHeight = () => {
if (ref && autoResize) {
ref.style.height = "auto"
ref.style.height = ref?.scrollHeight + "px"

Choose a reason for hiding this comment

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

Maybe we need this:

const scrollHeight = `${ref.scrollHeight}px`;
const computedStyleMap = ref.computedStyleMap();
const borderTopWidth = computedStyleMap.get("border-top-width")?.toString() ?? "0";
const borderBottomWidth = computedStyleMap.get("border-bottom-width")?.toString() ?? "0";

ref.style.height = `calc(${scrollHeight} + ${borderTopWidth} + ${borderBottomWidth})`;

patrickchin added a commit to patrickchin/haru2-vercel that referenced this pull request Oct 15, 2024
@jungsikjeong
Copy link

Why hasn't it come together yet?

@karisDev
Copy link

CSS now has field-sizing property, which yet has only 68% support

@Xu-Justin
Copy link

I'm waiting for this. I need this 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: roadmap This looks great. We'll add it to the roadmap, review and merge. component: textarea enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.