Textarea: autodetect RTL

This commit is contained in:
Alex Gleason 2023-10-11 13:51:36 -05:00
parent 5bd1eab607
commit 3c2fef5a80
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -2,6 +2,9 @@ import clsx from 'clsx';
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { useLocale } from 'soapbox/hooks';
import { getTextDirection } from 'soapbox/utils/rtl';
import Stack from '../stack/stack';
import Text from '../text/text';
@ -52,6 +55,7 @@ const Textarea = React.forwardRef(({
}: ITextarea, ref: React.ForwardedRef<HTMLTextAreaElement>) => {
const length = value?.length || 0;
const [rows, setRows] = useState<number>(autoGrow ? 1 : 4);
const locale = useLocale();
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
if (autoGrow) {
@ -94,6 +98,7 @@ const Textarea = React.forwardRef(({
'text-red-600 border-red-600': hasError,
'resize-none': !isResizeable,
})}
dir={value?.length ? getTextDirection(value, { fallback: locale.direction }) : undefined}
/>
{maxLength && (