-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
base: main
Are you sure you want to change the base?
Conversation
@rainyEra is attempting to deploy a commit to the shadcn-pro Team on Vercel. A member of the Team first needs to authorize it. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const texteAreaRef = useRef<HTMLTextAreaElement>(null) | ||
|
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.
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}
/>
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 know it, I just prefer other way due to readability. -1 dependency, this is also good.
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.
how can i make a dynamic textarea with react-hook-form, it handles ref by itself . how can i make it use my ref
@rainyEra do you need help on this? |
@isitrita sorry, I've been too busy :c |
this is so great! please add this! |
Nice component! |
@shadcn any updates? |
@shadcn any update? |
autoResize is now optional, so it won't break other projects. (disabled by default) |
Need this! |
any update? @shadcn |
also waiting for this |
const updateTextareaHeight = () => { | ||
if (ref && autoResize) { | ||
ref.style.height = "auto" | ||
ref.style.height = ref?.scrollHeight + "px" |
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.
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})`;
Why hasn't it come together yet? |
CSS now has field-sizing property, which yet has only 68% support |
I'm waiting for this. I need this 🙏 |
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?