From 11c1c2b9b4c09e24c5b32379cce6cb4ce742b889 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Wed, 7 May 2025 15:18:38 -0700 Subject: [PATCH] No more observer resize errors --- frontend/src/BackstoryTextField.tsx | 22 ++++++++++++---------- frontend/src/VectorVisualizer.tsx | 8 -------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/frontend/src/BackstoryTextField.tsx b/frontend/src/BackstoryTextField.tsx index 17752ea..bb7bc44 100644 --- a/frontend/src/BackstoryTextField.tsx +++ b/frontend/src/BackstoryTextField.tsx @@ -1,5 +1,6 @@ import React, { useRef, useEffect, ChangeEvent, KeyboardEvent } from 'react'; import { useTheme } from '@mui/material/styles'; +import './BackstoryTextField.css'; interface BackstoryTextFieldProps { value: string; @@ -29,7 +30,7 @@ const BackstoryTextField: React.FC = ({ shadow.value = value || placeholder || ''; - window.setTimeout(() => { + window.requestAnimationFrame(() => { const computed = getComputedStyle(textarea); const paddingTop = parseFloat(computed.paddingTop || '0'); const paddingBottom = parseFloat(computed.paddingBottom || '0'); @@ -38,9 +39,9 @@ const BackstoryTextField: React.FC = ({ const newHeight = shadow.scrollHeight + totalPadding; textarea.style.height = `${newHeight}px`; - }, 100); + }); } - }, [value, multiline, placeholder]); + }, [value, multiline, textareaRef, shadowRef, placeholder]); const handleChange = (e: ChangeEvent) => { if (onChange) { @@ -49,9 +50,6 @@ const BackstoryTextField: React.FC = ({ }; const handleKeyDown = (e: KeyboardEvent) => { - if (!multiline && e.key === 'Enter') { - e.preventDefault(); - } if (onKeyDown) { onKeyDown(e); } @@ -59,15 +57,14 @@ const BackstoryTextField: React.FC = ({ const sharedStyle = { width: '100%', - padding: '14px', + padding: '16.5px 14px', resize: 'none' as const, overflow: 'hidden' as const, boxSizing: 'border-box' as const, + minHeight: 'calc(1.5rem + 28px)', // lineHeight + padding-top + padding-bottom lineHeight: '1.5', - borderRadius: '0.25rem', + borderRadius: '4px', fontSize: '16px', - opacity: disabled ? "0.38" : "1", - color: disabled ? 'rgba(0, 0, 0, 0.38)' : 'rgb(46, 46, 46)', backgroundColor: 'rgba(0, 0, 0, 0)', fontFamily: theme.typography.fontFamily, }; @@ -75,6 +72,7 @@ const BackstoryTextField: React.FC = ({ if (!multiline) { return ( = ({ return ( <>