From 94e7da226061b1383d9d0c1c59638a9c621b1b18 Mon Sep 17 00:00:00 2001 From: Jing Hua Date: Tue, 14 Mar 2023 02:35:08 +0800 Subject: [PATCH] style: prompt library textarea --- .../PromptLibraryMenu/PromptLibraryMenu.tsx | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/components/PromptLibraryMenu/PromptLibraryMenu.tsx b/src/components/PromptLibraryMenu/PromptLibraryMenu.tsx index 77fa31f..568c431 100644 --- a/src/components/PromptLibraryMenu/PromptLibraryMenu.tsx +++ b/src/components/PromptLibraryMenu/PromptLibraryMenu.tsx @@ -39,6 +39,7 @@ const PromptLibraryMenuPopUp = ({ const handleInput = (e: React.ChangeEvent) => { e.target.style.height = 'auto'; e.target.style.height = `${e.target.scrollHeight}px`; + e.target.style.maxHeight = `${e.target.scrollHeight}px`; }; const handleSave = () => { @@ -62,13 +63,16 @@ const PromptLibraryMenuPopUp = ({ _setPrompts(updatedPrompts); }; - useEffect(() => { - if (container && container.current) { - container.current.querySelectorAll('textarea').forEach((elem) => { - elem.style.height = `${elem.scrollHeight}px`; - }); - } - }, []); + const handleOnFocus = (e: React.FocusEvent) => { + e.target.style.height = 'auto'; + e.target.style.height = `${e.target.scrollHeight}px`; + e.target.style.maxHeight = `${e.target.scrollHeight}px`; + }; + + const handleOnBlur = (e: React.FocusEvent) => { + e.target.style.height = 'auto'; + e.target.style.maxHeight = '2.5rem'; + }; return (
-
{t('name')}
+
{t('name')}
{t('prompt')}
{_prompts.map((prompt, index) => ( @@ -87,9 +91,11 @@ const PromptLibraryMenuPopUp = ({ key={prompt.id} className='flex items-center border-b border-gray-500/50 mb-1 p-1' > -
+