Fix rows prop in Textarea, use Textarea in SiteErrorBoundary

This commit is contained in:
Alex Gleason 2023-10-21 16:11:52 -05:00
parent c33ff771da
commit 882f7c38c5
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 7 additions and 6 deletions

View file

@ -3,7 +3,7 @@ import { ErrorBoundary } from 'react-error-boundary';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { NODE_ENV } from 'soapbox/build-config'; import { NODE_ENV } from 'soapbox/build-config';
import { HStack, Text, Stack } from 'soapbox/components/ui'; import { HStack, Text, Stack, Textarea } from 'soapbox/components/ui';
import { useSoapboxConfig } from 'soapbox/hooks'; import { useSoapboxConfig } from 'soapbox/hooks';
import { captureSentryException } from 'soapbox/sentry'; import { captureSentryException } from 'soapbox/sentry';
import KVStore from 'soapbox/storage/kv-store'; import KVStore from 'soapbox/storage/kv-store';
@ -121,12 +121,12 @@ const SiteErrorBoundary: React.FC<ISiteErrorBoundary> = ({ children }) => {
) : ( ) : (
<> <>
{errorText && ( {errorText && (
<textarea <Textarea
ref={textarea} ref={textarea}
className='block h-48 w-full rounded-md border-gray-300 bg-gray-100 p-4 font-mono text-gray-900 shadow-sm focus:border-primary-500 focus:ring-2 focus:ring-primary-500 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100 sm:text-sm'
value={errorText} value={errorText}
onClick={handleCopy} onClick={handleCopy}
dir='ltr' isCodeEditor
rows={12}
readOnly readOnly
/> />
)} )}

View file

@ -8,7 +8,7 @@ import { getTextDirection } from 'soapbox/utils/rtl';
import Stack from '../stack/stack'; import Stack from '../stack/stack';
import Text from '../text/text'; import Text from '../text/text';
interface ITextarea extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'id' | 'maxLength' | 'onChange' | 'onKeyDown' | 'onPaste' | 'required' | 'disabled' | 'rows' | 'readOnly'> { interface ITextarea extends Pick<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'id' | 'maxLength' | 'onChange' | 'onClick' | 'onKeyDown' | 'onPaste' | 'required' | 'disabled' | 'rows' | 'readOnly'> {
/** Put the cursor into the input on mount. */ /** Put the cursor into the input on mount. */
autoFocus?: boolean; autoFocus?: boolean;
/** Allows the textarea height to grow while typing */ /** Allows the textarea height to grow while typing */
@ -48,13 +48,14 @@ const Textarea = React.forwardRef(({
autoGrow = false, autoGrow = false,
maxRows = 10, maxRows = 10,
minRows = 1, minRows = 1,
rows: initialRows = 4,
theme = 'default', theme = 'default',
maxLength, maxLength,
value, value,
...props ...props
}: ITextarea, ref: React.ForwardedRef<HTMLTextAreaElement>) => { }: ITextarea, ref: React.ForwardedRef<HTMLTextAreaElement>) => {
const length = value?.length || 0; const length = value?.length || 0;
const [rows, setRows] = useState<number>(autoGrow ? 1 : 4); const [rows, setRows] = useState<number>(autoGrow ? minRows : initialRows);
const locale = useLocale(); const locale = useLocale();
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {