From 7535862a409f68285d772f9f712fd3a4d8af21e4 Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 30 Aug 2022 11:22:36 -0400 Subject: [PATCH] Autogrow the textarea --- .../components/ui/textarea/textarea.tsx | 77 +++++++++++++++---- .../features/chats/components/chat-box.tsx | 3 +- 2 files changed, 62 insertions(+), 18 deletions(-) diff --git a/app/soapbox/components/ui/textarea/textarea.tsx b/app/soapbox/components/ui/textarea/textarea.tsx index bdce03a12..7c2f94a4a 100644 --- a/app/soapbox/components/ui/textarea/textarea.tsx +++ b/app/soapbox/components/ui/textarea/textarea.tsx @@ -1,9 +1,15 @@ import classNames from 'clsx'; -import React from 'react'; +import React, { useState } from 'react'; interface ITextarea extends Pick, 'maxLength' | 'onChange' | 'onKeyDown' | 'required' | 'disabled' | 'rows' | 'readOnly'> { /** Put the cursor into the input on mount. */ autoFocus?: boolean, + /** Allows the textarea height to grow while typing */ + autoGrow?: boolean, + /** Used with "autoGrow". Sets a max number of rows. */ + maxRows?: number, + /** Used with "autoGrow". Sets a min number of rows. */ + minRows?: number, /** The initial text in the input. */ defaultValue?: string, /** Internal input name. */ @@ -23,22 +29,59 @@ interface ITextarea extends Pick) => { - return ( -